Skip to content

Commit

Permalink
Bytezap: fix deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
raehik committed Aug 18, 2023
1 parent e2664c4 commit 3a417bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/Bytezap/Bytes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Data.ByteString.Internal qualified as B
import GHC.IO
import Data.Word
import Foreign.ForeignPtr
import Foreign.Marshal.Utils qualified

byteString :: B.ByteString -> Write
byteString (B.BS fptr len) = Write len (pokeForeignPtr fptr len)
Expand All @@ -25,7 +26,8 @@ pokeForeignPtr fptr len@(I# len#) = poke $ \addr# st# ->

memcpyForeignPtr :: Ptr Word8 -> ForeignPtr Word8 -> Int -> IO ()
memcpyForeignPtr ptrTo fptrFrom len =
B.unsafeWithForeignPtr fptrFrom $ \ptrFrom -> B.memcpy ptrTo ptrFrom len
B.unsafeWithForeignPtr fptrFrom $ \ptrFrom ->
Foreign.Marshal.Utils.copyBytes ptrTo ptrFrom len
{-# INLINE memcpyForeignPtr #-}

pokeByteArray# :: ByteArray# -> Int# -> Int# -> Poke
Expand All @@ -37,5 +39,5 @@ pokeByteArray# arr# off# len# = poke $ \addr# st# ->
-- TODO this seems to work but like, really? wow lol
pokeByteReplicate :: Int -> Word8 -> Poke
pokeByteReplicate n@(I# n#) w8 = poke $ \addr# st# ->
case unIO (B.memset (Ptr addr#) w8 (fromIntegral n)) st# of
case unIO (Foreign.Marshal.Utils.fillBytes (Ptr addr#) w8 (fromIntegral n)) st# of
(# st'#, _ #) -> (# st'#, addr# `plusAddr#` n# #)
4 changes: 3 additions & 1 deletion src/Bytezap/Poke/Bytes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Data.ByteString.Internal qualified as B
import GHC.IO
import Data.Word
import Foreign.ForeignPtr
import Foreign.Marshal.Utils qualified

byteString :: B.ByteString -> Poke
byteString (B.BS fptr len) = pokeForeignPtr fptr len
Expand All @@ -23,7 +24,8 @@ pokeForeignPtr fptr len@(I# len#) = poke $ \addr# st# ->

memcpyForeignPtr :: Ptr Word8 -> ForeignPtr Word8 -> Int -> IO ()
memcpyForeignPtr ptrTo fptrFrom len =
B.unsafeWithForeignPtr fptrFrom $ \ptrFrom -> B.memcpy ptrTo ptrFrom len
B.unsafeWithForeignPtr fptrFrom $ \ptrFrom ->
Foreign.Marshal.Utils.copyBytes ptrTo ptrFrom len
{-# INLINE memcpyForeignPtr #-}

pokeByteArray# :: ByteArray# -> Int# -> Int# -> Poke
Expand Down

0 comments on commit 3a417bf

Please sign in to comment.