From 58bff93ad0e3817ae7cdbbd18f1f0eb6c006fe87 Mon Sep 17 00:00:00 2001 From: Adithya Kumar Date: Fri, 29 Nov 2024 17:26:51 +0530 Subject: [PATCH] Support streamly-core-0.3.0 --- src/Streamly/External/ByteString.hs | 9 ++++++++- src/Streamly/External/ByteString/Lazy.hs | 8 +++++++- streamly-bytestring.cabal | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Streamly/External/ByteString.hs b/src/Streamly/External/ByteString.hs index 71e4bc7..c81396b 100644 --- a/src/Streamly/External/ByteString.hs +++ b/src/Streamly/External/ByteString.hs @@ -101,6 +101,13 @@ pinnedCreate = Array.pinnedWrite ensurePinned = pure pinnedCreateOf = Array.writeN pinnedCreate = Array.write +array_createN = Array.writeN +#endif + +#if MIN_VERSION_streamly_core(0,3,0) +#define CREATE_N Array.createOf +#else +#define CREATE_N Array.writeN #endif {-# INLINE mutableByteArrayContents# #-} @@ -129,7 +136,7 @@ toArray (CONSTRUCTOR((ForeignPtr addr# (PlainPtr marr#)), off0, len)) = toArray (CONSTRUCTOR(fptr, off, len)) = unsafeInlineIO $ withForeignPtr (fptr WHEN_0_10_12(`plusForeignPtr` off)) - $ Unfold.fold (Array.writeN len) generator + $ Unfold.fold (CREATE_N len) generator where diff --git a/src/Streamly/External/ByteString/Lazy.hs b/src/Streamly/External/ByteString/Lazy.hs index 2b6680e..3fcbffa 100644 --- a/src/Streamly/External/ByteString/Lazy.hs +++ b/src/Streamly/External/ByteString/Lazy.hs @@ -37,6 +37,12 @@ import qualified Streamly.Data.Stream as Stream import Prelude hiding (read) +#if MIN_VERSION_streamly_core(0,3,0) +#define UNFOLD_EACH Unfold.unfoldEach +#else +#define UNFOLD_EACH Unfold.many +#endif + -- | Unfold a lazy ByteString to a stream of 'Array' 'Words'. {-# INLINE chunkReader #-} chunkReader :: Monad m => Unfold m ByteString (Array Word8) @@ -49,7 +55,7 @@ chunkReader = Unfold step seed -- | Unfold a lazy ByteString to a stream of Word8 {-# INLINE reader #-} reader :: Monad m => Unfold m ByteString Word8 -reader = Unfold.many Array.reader readChunks +reader = UNFOLD_EACH Array.reader readChunks -- TODO: "toChunks" should be called "read" instead -- | Convert a lazy 'ByteString' to a serial stream of 'Array' 'Word8'. diff --git a/streamly-bytestring.cabal b/streamly-bytestring.cabal index c7fde2f..111b880 100644 --- a/streamly-bytestring.cabal +++ b/streamly-bytestring.cabal @@ -48,7 +48,7 @@ library || == 0.11.4.* || == 0.11.5.* || == 0.12.0.* - , streamly-core >= 0.1.0 && < 0.2.3 + , streamly-core >= 0.1.0 && < 0.3.1 default-language: Haskell2010 test-suite sb-test