From 174079a6e6ed5d4f164f642c12dfa75672b70c51 Mon Sep 17 00:00:00 2001 From: Topi Kettunen Date: Thu, 14 Nov 2024 00:26:29 +0100 Subject: [PATCH] Fix memcpy/memset deprecation warning (#221) * Fix memcpy/memset deprecation warning * Formatting --- internal/Data/Attoparsec/ByteString/Buffer.hs | 15 ++++++++------- internal/Data/Attoparsec/ByteString/FastSet.hs | 3 ++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/internal/Data/Attoparsec/ByteString/Buffer.hs b/internal/Data/Attoparsec/ByteString/Buffer.hs index 4f827a8..7a72fdd 100644 --- a/internal/Data/Attoparsec/ByteString/Buffer.hs +++ b/internal/Data/Attoparsec/ByteString/Buffer.hs @@ -54,7 +54,7 @@ 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') @@ -62,6 +62,7 @@ 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) @@ -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 @@ -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 diff --git a/internal/Data/Attoparsec/ByteString/FastSet.hs b/internal/Data/Attoparsec/ByteString/FastSet.hs index 5d02553..b342d2d 100644 --- a/internal/Data/Attoparsec/ByteString/FastSet.hs +++ b/internal/Data/Attoparsec/ByteString/FastSet.hs @@ -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) @@ -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