memory 0.14.17 → 0.14.18
raw patch · 5 files changed
+35/−10 lines, 5 files
Files
- CHANGELOG.md +9/−0
- Data/ByteArray/Methods.hs +10/−4
- Data/Memory/PtrMethods.hs +9/−0
- memory.cabal +1/−1
- tests/Tests.hs +6/−5
CHANGELOG.md view
@@ -1,3 +1,12 @@+## 0.14.18++* Branch/Release Snafu++## 0.14.17++* Require basement >= 0.0.7, Fix compilation with GHC 8,6+* Cleanup CPP, dropping support for much older version+ ## 0.14.16 * Fix compilation with a newer basement (>= 0.0.7) and an older GHC (< 8.0)
Data/ByteArray/Methods.hs view
@@ -26,6 +26,7 @@ , take , drop , span+ , reverse , convert , copyRet , copyAndFreeze@@ -48,7 +49,7 @@ import Foreign.Storable import Foreign.Ptr -import Prelude hiding (length, take, drop, span, concat, replicate, splitAt, null, pred, last, any, all)+import Prelude hiding (length, take, drop, span, reverse, concat, replicate, splitAt, null, pred, last, any, all) import qualified Prelude #if defined(WITH_BYTESTRING_SUPPORT) && defined(WITH_BASEMENT_SUPPORT)@@ -195,6 +196,11 @@ | otherwise = i len = length bs +-- | Reverse a bytearray+reverse :: ByteArray bs => bs -> bs+reverse bs = unsafeCreate n $ \d -> withByteArray bs $ \s -> memReverse d s n+ where n = length bs+ -- | Concatenate bytearray into a larger bytearray concat :: (ByteArrayAccess bin, ByteArray bout) => [bin] -> bout concat l = unsafeCreate retLen (loopCopy l)@@ -203,7 +209,7 @@ loopCopy [] _ = return () loopCopy (x:xs) dst = do- withByteArray x $ \src -> memCopy dst src chunkLen+ copyByteArrayToPtr x dst loopCopy xs (dst `plusPtr` chunkLen) where !chunkLen = length x@@ -216,14 +222,14 @@ copy :: (ByteArrayAccess bs1, ByteArray bs2) => bs1 -> (Ptr p -> IO ()) -> IO bs2 copy bs f = alloc (length bs) $ \d -> do- withByteArray bs $ \s -> memCopy d s (length bs)+ copyByteArrayToPtr bs d f (castPtr d) -- | Similar to 'copy' but also provide a way to return a value from the initializer copyRet :: (ByteArrayAccess bs1, ByteArray bs2) => bs1 -> (Ptr p -> IO a) -> IO (a, bs2) copyRet bs f = allocRet (length bs) $ \d -> do- withByteArray bs $ \s -> memCopy d s (length bs)+ copyByteArrayToPtr bs d f (castPtr d) -- | Similiar to 'copy' but expect the resulting bytearray in a pure context
Data/Memory/PtrMethods.hs view
@@ -17,6 +17,7 @@ , memXorWith , memCopy , memSet+ , memReverse , memEqual , memConstEqual , memCompare@@ -71,6 +72,14 @@ memSet :: Ptr Word8 -> Word8 -> Int -> IO () memSet start v n = c_memset start v (fromIntegral n) >>= \_ -> return () {-# INLINE memSet #-}++-- | Reverse a set number of bytes from @src@ to @dst@. Memory+-- locations should not overlap.+memReverse :: Ptr Word8 -> Ptr Word8 -> Int -> IO ()+memReverse d s n+ | n > 0 = do peekByteOff s (n - 1) >>= poke d+ memReverse (d `plusPtr` 1) s (n - 1)+ | otherwise = return () -- | Check if two piece of memory are equals memEqual :: Ptr Word8 -> Ptr Word8 -> Int -> IO Bool
memory.cabal view
@@ -1,5 +1,5 @@ Name: memory-version: 0.14.17+version: 0.14.18 Synopsis: memory and related abstraction stuff Description: Chunk of memory, polymorphic byte array management and manipulation
tests/Tests.hs view
@@ -246,11 +246,12 @@ let chunks = fmap (witnessID . B.pack . unWords8) l expected = concatMap unWords8 l in B.pack expected == witnessID (B.concat chunks)- , Property "cons b bs == reverse (snoc (reverse bs) b)" $ \(Words8 l) b ->- let b1 = witnessID (B.pack l)- b2 = witnessID (B.pack (reverse l))- expected = B.pack (reverse (B.unpack (B.snoc b2 b)))- in B.cons b b1 == expected+ , Property "reverse" $ \(Words8 l) ->+ let b = witnessID (B.pack l)+ in reverse l == B.unpack (B.reverse b)+ , Property "cons b (reverse bs) == reverse (snoc bs b)" $ \(Words8 l) b ->+ let a = witnessID (B.pack l)+ in B.cons b (B.reverse a) == B.reverse (B.snoc a b) , Property "all == Prelude.all" $ \(Words8 l) b -> let b1 = witnessID (B.pack l) p = (/= b)