From 61c507e7da02d604691523b353b025766a65c325 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sat, 6 Jan 2024 11:32:26 +0000 Subject: [PATCH] core: replace deprecated memcpy (#3652) --- src/Simplex/Chat/Mobile/Shared.hs | 4 ++-- tests/MobileTests.hs | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Simplex/Chat/Mobile/Shared.hs b/src/Simplex/Chat/Mobile/Shared.hs index 5f13f58c7..fcde581ea 100644 --- a/src/Simplex/Chat/Mobile/Shared.hs +++ b/src/Simplex/Chat/Mobile/Shared.hs @@ -3,7 +3,7 @@ module Simplex.Chat.Mobile.Shared where import qualified Data.ByteString as B -import Data.ByteString.Internal (ByteString (..), memcpy) +import Data.ByteString.Internal (ByteString (..)) import qualified Data.ByteString.Lazy as LB import qualified Data.ByteString.Lazy.Internal as LB import Foreign @@ -21,7 +21,7 @@ getByteString ptr len = do putByteString :: Ptr Word8 -> ByteString -> IO () putByteString ptr (PS fp offset len) = - withForeignPtr fp $ \p -> memcpy ptr (p `plusPtr` offset) len + withForeignPtr fp $ \p -> copyBytes ptr (p `plusPtr` offset) len {-# INLINE putByteString #-} putLazyByteString :: Ptr Word8 -> LB.ByteString -> IO () diff --git a/tests/MobileTests.hs b/tests/MobileTests.hs index a6231fa27..27e1d6f8b 100644 --- a/tests/MobileTests.hs +++ b/tests/MobileTests.hs @@ -16,11 +16,12 @@ import qualified Data.Aeson.TH as JQ import Data.ByteString (ByteString) import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as BS -import Data.ByteString.Internal (create, memcpy) +import Data.ByteString.Internal (create) import qualified Data.ByteString.Lazy.Char8 as LB import Data.Word (Word8, Word32) import Foreign.C import Foreign.Marshal.Alloc (mallocBytes) +import Foreign.Marshal.Utils (copyBytes) import Foreign.Ptr import Foreign.StablePtr import Foreign.Storable (peek) @@ -291,7 +292,7 @@ testFileCApi fileName tmp = do peek ptr' `shouldReturn` (0 :: Word8) sz :: Word32 <- peek (ptr' `plusPtr` 1) let sz' = fromIntegral sz - contents <- create sz' $ \toPtr -> memcpy toPtr (ptr' `plusPtr` 5) sz' + contents <- create sz' $ \toPtr -> copyBytes toPtr (ptr' `plusPtr` 5) sz' contents `shouldBe` src sz' `shouldBe` fromIntegral len