Skip to content

Commit

Permalink
Fix memcpy/memset deprecation warning (#221)
Browse files Browse the repository at this point in the history
* Fix memcpy/memset deprecation warning

* Formatting
  • Loading branch information
topikettunen authored Nov 13, 2024
1 parent 2d80a93 commit 174079a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
15 changes: 8 additions & 7 deletions internal/Data/Attoparsec/ByteString/Buffer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@ module Data.Attoparsec.ByteString.Buffer
) where

import Control.Exception (assert)
import Data.ByteString.Internal (ByteString(..), memcpy, nullForeignPtr)
import Data.ByteString.Internal (ByteString(..), nullForeignPtr)
import Data.Attoparsec.Internal.Fhthagn (inlinePerformIO)
import Data.Attoparsec.Internal.Compat
import Data.List (foldl1')
import Data.Monoid as Mon (Monoid(..))
import Data.Semigroup (Semigroup(..))
import Data.Word (Word8)
import Foreign.ForeignPtr (ForeignPtr, withForeignPtr)
import Foreign.Marshal.Utils (copyBytes)
import Foreign.Ptr (castPtr, plusPtr)
import Foreign.Storable (peek, peekByteOff, poke, sizeOf)
import GHC.ForeignPtr (mallocPlainForeignPtrBytes)
Expand Down Expand Up @@ -118,9 +119,9 @@ append (Buf fp0 off0 len0 cap0 gen0) !fp1 !off1 !len1 =
then do
let newgen = gen + 1
poke (castPtr ptr0) newgen
memcpy (ptr0 `plusPtr` (off0+len0))
(ptr1 `plusPtr` off1)
(fromIntegral len1)
copyBytes (ptr0 `plusPtr` (off0+len0))
(ptr1 `plusPtr` off1)
(fromIntegral len1)
return (Buf fp0 off0 newlen cap0 newgen)
else do
let newcap = newlen * 2
Expand All @@ -129,9 +130,9 @@ append (Buf fp0 off0 len0 cap0 gen0) !fp1 !off1 !len1 =
let ptr = ptr_ `plusPtr` genSize
newgen = 1
poke (castPtr ptr_) newgen
memcpy ptr (ptr0 `plusPtr` off0) (fromIntegral len0)
memcpy (ptr `plusPtr` len0) (ptr1 `plusPtr` off1)
(fromIntegral len1)
copyBytes ptr (ptr0 `plusPtr` off0) (fromIntegral len0)
copyBytes (ptr `plusPtr` len0) (ptr1 `plusPtr` off1)
(fromIntegral len1)
return (Buf fp genSize newlen newcap newgen)

length :: Buffer -> Int
Expand Down
3 changes: 2 additions & 1 deletion internal/Data/Attoparsec/ByteString/FastSet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module Data.Attoparsec.ByteString.FastSet
) where

import Data.Bits ((.&.), (.|.), unsafeShiftL)
import Foreign.Marshal.Utils (fillBytes)
import Foreign.Storable (peekByteOff, pokeByteOff)
import GHC.Exts (Int(I#), iShiftRA#)
import GHC.Word (Word8)
Expand Down Expand Up @@ -94,7 +95,7 @@ memberChar c = memberWord8 (I.c2w c)

mkTable :: B.ByteString -> B.ByteString
mkTable s = I.unsafeCreate 32 $ \t -> do
_ <- I.memset t 0 32
fillBytes t 0 32
U.unsafeUseAsCStringLen s $ \(p, l) ->
let loop n | n == l = return ()
| otherwise = do
Expand Down

0 comments on commit 174079a

Please sign in to comment.