memory 0.15.0 → 0.16.0
raw patch · 10 files changed
+26/−112 lines, 10 filesdep ~basedep ~ghc-prim
Dependency ranges changed: base, ghc-prim
Files
- Data/ByteArray/Bytes.hs +3/−0
- Data/ByteArray/Encoding.hs +7/−0
- Data/ByteArray/ScrubbedBytes.hs +11/−3
- Data/ByteArray/Sized.hs +1/−1
- Data/Memory/Encoding/Base64.hs +0/−1
- Data/Memory/Internal/CompatPrim.hs +0/−20
- Data/Memory/Internal/Imports.hs +1/−1
- Data/Memory/Internal/Scrubber.hs +0/−80
- Data/Memory/PtrMethods.hs +2/−4
- memory.cabal +1/−2
Data/ByteArray/Bytes.hs view
@@ -16,6 +16,9 @@ ( Bytes ) where +#if MIN_VERSION_base(4,15,0)+import GHC.Exts (unsafeCoerce#)+#endif import GHC.Types import GHC.Prim import GHC.Ptr
Data/ByteArray/Encoding.hs view
@@ -33,6 +33,13 @@ -- encoding is often used in other specifications without -- <http://tools.ietf.org/html/rfc4648#section-3.2 padding> characters. --+-- <https://www.ietf.org/rfc/rfc2045.txt RFC 2045>+-- defines a separate Base64 encoding, which is not supported. This format+-- requires a newline at least every 76 encoded characters, which works around+-- limitations of older email programs that could not handle long lines.+-- Be aware that other languages, such as Ruby, encode the RFC 2045 version+-- by default. To decode their ouput, remove all newlines before decoding.+-- -- ==== Examples -- -- A quick example to show the differences:
Data/ByteArray/ScrubbedBytes.hs view
@@ -17,6 +17,9 @@ import GHC.Types import GHC.Prim import GHC.Ptr+#if MIN_VERSION_base(4,15,0)+import GHC.Exts (unsafeCoerce#)+#endif #if MIN_VERSION_base(4,9,0) import Data.Semigroup import Data.Foldable (toList)@@ -25,11 +28,10 @@ #endif import Data.String (IsString(..)) import Data.Typeable-import Data.Memory.PtrMethods (memCopy, memConstEqual)+import Data.Memory.PtrMethods import Data.Memory.Internal.CompatPrim import Data.Memory.Internal.Compat (unsafeDoIO) import Data.Memory.Internal.Imports-import Data.Memory.Internal.Scrubber (getScrubber) import Data.ByteArray.Types import Foreign.Storable #ifdef MIN_VERSION_basement@@ -90,11 +92,17 @@ | otherwise = IO $ \s -> case newAlignedPinnedByteArray# sz 8# s of (# s1, mbarr #) ->- let !scrubber = (getScrubber sz) (byteArrayContents# (unsafeCoerce# mbarr))+ let !scrubber = getScrubber (byteArrayContents# (unsafeCoerce# mbarr)) !mba = ScrubbedBytes mbarr in case mkWeak# mbarr () (finalize scrubber mba) s1 of (# s2, _ #) -> (# s2, mba #) where+ getScrubber :: Addr# -> State# RealWorld -> State# RealWorld+ getScrubber addr s =+ let IO scrubBytes = memSet (Ptr addr) 0 (I# sz)+ in case scrubBytes s of+ (# s', _ #) -> s'+ #if __GLASGOW_HASKELL__ >= 800 finalize :: (State# RealWorld -> State# RealWorld) -> ScrubbedBytes -> State# RealWorld -> (# State# RealWorld, () #) finalize scrubber mba@(ScrubbedBytes _) = \s1 ->
Data/ByteArray/Sized.hs view
@@ -99,7 +99,7 @@ -- | Wrapper around any collection type with the size as type parameter -- newtype SizedByteArray (n :: Nat) ba = SizedByteArray { unSizedByteArray :: ba }- deriving (Eq, Show, Typeable, Ord, NormalForm, Semigroup, Monoid)+ deriving (Eq, Show, Typeable, Ord, NormalForm) -- | create a 'SizedByteArray' from the given 'ByteArrayAccess' if the -- size is the same as the target size.
Data/Memory/Encoding/Base64.hs view
@@ -26,7 +26,6 @@ , fromBase64OpenBSD ) where -import Control.Monad import Data.Memory.Internal.Compat import Data.Memory.Internal.CompatPrim import Data.Memory.Internal.Imports
Data/Memory/Internal/CompatPrim.hs view
@@ -14,13 +14,11 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE BangPatterns #-} {-# LANGUAGE MagicHash #-}-{-# LANGUAGE UnboxedTuples #-} module Data.Memory.Internal.CompatPrim ( be32Prim , le32Prim , byteswap32Prim , booleanPrim- , eitherDivideBy8# ) where import GHC.Prim@@ -70,21 +68,3 @@ booleanPrim b = b #endif {-# INLINE booleanPrim #-}---- | Apply or or another function if 8 divides the number of bytes-eitherDivideBy8# :: Int# -- ^ number of bytes- -> (Int# -> a) -- ^ if it divided by 8, the argument is the number of 8 bytes words- -> (Int# -> a) -- ^ if it doesn't, just the number of bytes- -> a-#if __GLASGOW_HASKELL__ > 704-eitherDivideBy8# v f8 f1 =- let !(# q, r #) = quotRemInt# v 8#- in if booleanPrim (r ==# 0#)- then f8 q- else f1 v-#else-eitherDivideBy8# v f8 f1 =- if booleanPrim ((remInt# v 8#) ==# 0#)- then f8 (quotInt# v 8#)- else f1 v-#endif
Data/Memory/Internal/Imports.hs view
@@ -12,6 +12,6 @@ import Data.Word as X import Control.Applicative as X-import Control.Monad as X (forM, forM_, void)+import Control.Monad as X (forM, forM_, void, when) import Control.Arrow as X (first, second) import Data.Memory.Internal.DeepSeq as X
− Data/Memory/Internal/Scrubber.hs
@@ -1,80 +0,0 @@--- |--- Module : Data.Memory.Internal.Scrubber--- License : BSD-style--- Maintainer : Vincent Hanquez <vincent@snarc.org>--- Stability : stable--- Portability : Compat----{-# LANGUAGE CPP #-}-{-# LANGUAGE BangPatterns #-}-{-# LANGUAGE MagicHash #-}-{-# LANGUAGE UnboxedTuples #-}-#include "MachDeps.h"-module Data.Memory.Internal.Scrubber- ( getScrubber- ) where--import GHC.Prim-import Data.Memory.Internal.CompatPrim (booleanPrim)--getScrubber :: Int# -> (Addr# -> State# RealWorld -> State# RealWorld)-getScrubber sz - | booleanPrim (sz ==# 4#) = scrub4- | booleanPrim (sz ==# 8#) = scrub8- | booleanPrim (sz ==# 16#) = scrub16- | booleanPrim (sz ==# 32#) = scrub32- | otherwise = scrubBytes sz- where- scrub4 a = \s -> writeWord32OffAddr# a 0# 0## s- {-# INLINE scrub4 #-}-#if WORD_SIZE_IN_BITS == 64- scrub8 a = \s -> writeWord64OffAddr# a 0# 0## s- {-# INLINE scrub8 #-}- scrub16 a = \s1 ->- let !s2 = writeWord64OffAddr# a 0# 0## s1- !s3 = writeWord64OffAddr# a 1# 0## s2- in s3- {-# INLINE scrub16 #-}- scrub32 a = \s1 ->- let !s2 = writeWord64OffAddr# a 0# 0## s1- !s3 = writeWord64OffAddr# a 1# 0## s2- !s4 = writeWord64OffAddr# a 2# 0## s3- !s5 = writeWord64OffAddr# a 3# 0## s4- in s5- {-# INLINE scrub32 #-}-#else- scrub8 a = \s1 ->- let !s2 = writeWord32OffAddr# a 0# 0## s1- !s3 = writeWord32OffAddr# a 1# 0## s2- in s3- {-# INLINE scrub8 #-}- scrub16 a = \s1 ->- let !s2 = writeWord32OffAddr# a 0# 0## s1- !s3 = writeWord32OffAddr# a 1# 0## s2- !s4 = writeWord32OffAddr# a 2# 0## s3- !s5 = writeWord32OffAddr# a 3# 0## s4- in s5- {-# INLINE scrub16 #-}- scrub32 a = \s1 ->- let !s2 = writeWord32OffAddr# a 0# 0## s1- !s3 = writeWord32OffAddr# a 1# 0## s2- !s4 = writeWord32OffAddr# a 2# 0## s3- !s5 = writeWord32OffAddr# a 3# 0## s4- !s6 = writeWord32OffAddr# a 4# 0## s5- !s7 = writeWord32OffAddr# a 5# 0## s6- !s8 = writeWord32OffAddr# a 6# 0## s7- !s9 = writeWord32OffAddr# a 7# 0## s8- in s9- {-# INLINE scrub32 #-}-#endif--scrubBytes :: Int# -> Addr# -> State# RealWorld -> State# RealWorld-scrubBytes sz8 addr = \s -> loop sz8 addr s- where loop :: Int# -> Addr# -> State# RealWorld -> State# RealWorld- loop n a s- | booleanPrim (n ==# 0#) = s- | otherwise =- case writeWord8OffAddr# a 0# 0## s of- s' -> loop (n -# 1#) (plusAddr# a 1#) s'- {-# INLINE loop #-}-{-# INLINE scrubBytes #-}
Data/Memory/PtrMethods.hs view
@@ -53,13 +53,11 @@ | destination == source = loopInplace source bytes | otherwise = loop destination source bytes where- loop _ _ 0 = return ()- loop !d !s !n = do+ loop !d !s n = when (n > 0) $ do peek s >>= poke d . xor v loop (d `plusPtr` 1) (s `plusPtr` 1) (n-1) - loopInplace _ 0 = return ()- loopInplace !s !n = do+ loopInplace !s n = when (n > 0) $ do peek s >>= poke s . xor v loopInplace (s `plusPtr` 1) (n-1)
memory.cabal view
@@ -1,5 +1,5 @@ Name: memory-version: 0.15.0+version: 0.16.0 Synopsis: memory and related abstraction stuff Description: Chunk of memory, polymorphic byte array management and manipulation@@ -70,7 +70,6 @@ Data.Memory.Internal.CompatPrim64 Data.Memory.Internal.DeepSeq Data.Memory.Internal.Imports- Data.Memory.Internal.Scrubber Data.Memory.Hash.SipHash Data.Memory.Hash.FNV Data.ByteArray.Pack.Internal