Commit 6f0243ae authored by Tamar Christina's avatar Tamar Christina Committed by Marge Bot

winio: fix array splat

parent c832f7e2
...@@ -142,13 +142,17 @@ unsafeLoad (Array ref) load = do ...@@ -142,13 +142,17 @@ unsafeLoad (Array ref) load = do
-- | Reads n elements from the pointer and copies them -- | Reads n elements from the pointer and copies them
-- into the array. -- into the array.
unsafeCopyFromBuffer :: Array a -> Ptr a -> Int -> IO () unsafeCopyFromBuffer :: Storable a => Array a -> Ptr a -> Int -> IO ()
unsafeCopyFromBuffer (Array ref) sptr n = unsafeCopyFromBuffer (Array ref) sptr n =
readIORef ref >>= \(AC es _ cap) -> readIORef ref >>= \(AC es _ cap) ->
CHECK_BOUNDS("unsafeCopyFromBuffer", cap, n-1) CHECK_BOUNDS("unsafeCopyFromBuffer", cap, n)
withForeignPtr es $ \pdest -> do 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) 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 :: Storable a => Array a -> Int -> IO ()
ensureCapacity (Array ref) c = do ensureCapacity (Array ref) c = do
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment