From 884a34d3dbea2a8ab977d85a430fa6b3a64aae64 Mon Sep 17 00:00:00 2001 From: James Crayne Date: Tue, 8 Oct 2019 01:19:09 +0000 Subject: support primitive-0.7.0.0 and remove generated bounds from build-depends --- src/Data/Primitive/ByteArray/Util.hs | 17 +++++++++++++++-- src/Data/Primitive/Struct.hs | 4 ++++ 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Data/Primitive/ByteArray/Util.hs b/src/Data/Primitive/ByteArray/Util.hs index 83a2e7d..4134e5f 100644 --- a/src/Data/Primitive/ByteArray/Util.hs +++ b/src/Data/Primitive/ByteArray/Util.hs @@ -15,11 +15,16 @@ import GHC.TypeLits import Control.Monad.Primitive import qualified Data.ByteString as B import qualified Data.ByteString.Unsafe as B +#if !MIN_VERSION_primitive(0,7,0) import Data.Primitive.Addr +#else +import Data.Primitive.Ptr +#endif import Data.Primitive.Types import Data.Primitive.ByteArray import Data.Word import Foreign.Ptr +import Foreign.C.Types newtype Offset (n :: Nat) = Offset Int @@ -55,17 +60,25 @@ readAtByte :: forall a m n. readAtByte buf (Offset offset) = readByteArray buf (div offset $ (sizeOf (undefined :: a))) {-# INLINE readAtByte #-} -writeStringAt :: PrimMonad m => MutableByteArray s -> Int -> B.ByteString -> m (Ptr a) +writeStringAt :: (PrimMonad m) => MutableByteArray s -> Int -> B.ByteString -> m (Ptr a) writeStringAt src o bsname = do (p,cnt) <- unsafeIOToPrim $ B.unsafeUseAsCStringLen bsname return +#if !MIN_VERSION_primitive(0,7,0) let nptr = ptr (mutableByteArrayContents src) `plusPtr` o copyAddr (adr nptr) (adr p) cnt writeOffAddr (adr nptr) cnt (0 :: Word8) - return nptr +#else + let nptr = (mutableByteArrayContents src) `plusPtr` o + copyPtr (nptr) (p) cnt + writeOffPtr (castPtr nptr) cnt (0 :: Foreign.C.Types.CChar ) +#endif + return (castPtr nptr) +#if !MIN_VERSION_primitive(0,7,0) ptr :: Addr -> Ptr a ptr (Addr a) = Ptr a adr :: Ptr a -> Addr adr (Ptr a) = Addr a +#endif diff --git a/src/Data/Primitive/Struct.hs b/src/Data/Primitive/Struct.hs index 705e65d..92bd387 100644 --- a/src/Data/Primitive/Struct.hs +++ b/src/Data/Primitive/Struct.hs @@ -110,7 +110,11 @@ instance IsStruct IO Ptr where withPointer :: Struct IO base tag -> (Ptr tag -> IO x) -> IO x withPointer (Struct (Offset off) ary) f = do +#if !MIN_VERSION_primitive(0,7,0) x <- f (ptr (mutableByteArrayContents ary) `plusPtr` off) +#else + x <- f ((mutableByteArrayContents ary) `plusPtr` off) +#endif seq ary $ return x data ForeignStruct tag = ForeignStruct -- cgit v1.2.3