Skip to content

Commit 174079a

Browse files
authored
Fix memcpy/memset deprecation warning (#221)
* Fix memcpy/memset deprecation warning * Formatting
1 parent 2d80a93 commit 174079a

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

internal/Data/Attoparsec/ByteString/Buffer.hs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,15 @@ module Data.Attoparsec.ByteString.Buffer
5454
) where
5555

5656
import Control.Exception (assert)
57-
import Data.ByteString.Internal (ByteString(..), memcpy, nullForeignPtr)
57+
import Data.ByteString.Internal (ByteString(..), nullForeignPtr)
5858
import Data.Attoparsec.Internal.Fhthagn (inlinePerformIO)
5959
import Data.Attoparsec.Internal.Compat
6060
import Data.List (foldl1')
6161
import Data.Monoid as Mon (Monoid(..))
6262
import Data.Semigroup (Semigroup(..))
6363
import Data.Word (Word8)
6464
import Foreign.ForeignPtr (ForeignPtr, withForeignPtr)
65+
import Foreign.Marshal.Utils (copyBytes)
6566
import Foreign.Ptr (castPtr, plusPtr)
6667
import Foreign.Storable (peek, peekByteOff, poke, sizeOf)
6768
import GHC.ForeignPtr (mallocPlainForeignPtrBytes)
@@ -118,9 +119,9 @@ append (Buf fp0 off0 len0 cap0 gen0) !fp1 !off1 !len1 =
118119
then do
119120
let newgen = gen + 1
120121
poke (castPtr ptr0) newgen
121-
memcpy (ptr0 `plusPtr` (off0+len0))
122-
(ptr1 `plusPtr` off1)
123-
(fromIntegral len1)
122+
copyBytes (ptr0 `plusPtr` (off0+len0))
123+
(ptr1 `plusPtr` off1)
124+
(fromIntegral len1)
124125
return (Buf fp0 off0 newlen cap0 newgen)
125126
else do
126127
let newcap = newlen * 2
@@ -129,9 +130,9 @@ append (Buf fp0 off0 len0 cap0 gen0) !fp1 !off1 !len1 =
129130
let ptr = ptr_ `plusPtr` genSize
130131
newgen = 1
131132
poke (castPtr ptr_) newgen
132-
memcpy ptr (ptr0 `plusPtr` off0) (fromIntegral len0)
133-
memcpy (ptr `plusPtr` len0) (ptr1 `plusPtr` off1)
134-
(fromIntegral len1)
133+
copyBytes ptr (ptr0 `plusPtr` off0) (fromIntegral len0)
134+
copyBytes (ptr `plusPtr` len0) (ptr1 `plusPtr` off1)
135+
(fromIntegral len1)
135136
return (Buf fp genSize newlen newcap newgen)
136137

137138
length :: Buffer -> Int

internal/Data/Attoparsec/ByteString/FastSet.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module Data.Attoparsec.ByteString.FastSet
3333
) where
3434

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

9596
mkTable :: B.ByteString -> B.ByteString
9697
mkTable s = I.unsafeCreate 32 $ \t -> do
97-
_ <- I.memset t 0 32
98+
fillBytes t 0 32
9899
U.unsafeUseAsCStringLen s $ \(p, l) ->
99100
let loop n | n == l = return ()
100101
| otherwise = do

0 commit comments

Comments
 (0)