[Git][ghc/ghc][master] winio: fix array splat

Marge Bot gitlab at gitlab.haskell.org
Fri Oct 9 12:50:17 UTC 2020



 Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
6f0243ae by Tamar Christina at 2020-10-09T08:50:13-04:00
winio: fix array splat

- - - - -


1 changed file:

- libraries/base/GHC/Event/Array.hs


Changes:

=====================================
libraries/base/GHC/Event/Array.hs
=====================================
@@ -142,13 +142,17 @@ unsafeLoad (Array ref) load = do
 
 -- | Reads n elements from the pointer and copies them
 -- into the array.
-unsafeCopyFromBuffer :: Array a -> Ptr a -> Int -> IO ()
+unsafeCopyFromBuffer :: Storable a => Array a -> Ptr a -> Int -> IO ()
 unsafeCopyFromBuffer (Array ref) sptr n =
     readIORef ref >>= \(AC es _ cap) ->
-    CHECK_BOUNDS("unsafeCopyFromBuffer", cap, n-1)
+    CHECK_BOUNDS("unsafeCopyFromBuffer", cap, n)
     withForeignPtr es $ \pdest -> do
-      _ <- memcpy pdest sptr (fromIntegral n)
+      let size = sizeOfPtr sptr undefined
+      _ <- memcpy pdest sptr (fromIntegral $ n * size)
       writeIORef ref (AC es n cap)
+  where
+    sizeOfPtr :: Storable a => Ptr a -> a -> Int
+    sizeOfPtr _ a = sizeOf a
 
 ensureCapacity :: Storable a => Array a -> Int -> IO ()
 ensureCapacity (Array ref) c = do



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6f0243ae5b359124936a8ff3dd0a287df3d7aca2

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6f0243ae5b359124936a8ff3dd0a287df3d7aca2
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20201009/c9b1c9ed/attachment-0001.html>


More information about the ghc-commits mailing list