Skip to content

Fix memcpy/memset deprecation warning #221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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