primitive-addr 0.1.0.0 → 0.1.0.1
raw patch · 3 files changed
+31/−13 lines, 3 filesdep ~base
Dependency ranges changed: base
Files
- CHANGELOG.md +5/−1
- primitive-addr.cabal +2/−2
- src/Data/Primitive/Addr.hs +24/−10
CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for primitive-addr -## 0.1.0.0 -- YYYY-mm-dd+## 0.1.0.1 -- 2019-06-18++* Allow building with GHCs as old as 7.4.2.++## 0.1.0.0 -- 2019-05-17 * First version. Released on an unsuspecting world.
primitive-addr.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: primitive-addr-version: 0.1.0.0+version: 0.1.0.1 synopsis: Addresses to unmanaged memory homepage: https://github.com/andrewthad/primitive-addr bug-reports: https://github.com/andrewthad/primitive-addr/issues@@ -15,7 +15,7 @@ library exposed-modules: Data.Primitive.Addr build-depends:- base >=4.11.1.0 && <5+ base >=4.5.1.0 && <5 , primitive >=0.7 && <0.8 hs-source-dirs: src default-language: Haskell2010
src/Data/Primitive/Addr.hs view
@@ -1,3 +1,4 @@+{-# language CPP #-} {-# language MagicHash #-} {-# language UnboxedTuples #-} @@ -16,7 +17,9 @@ , writeOffAddr -- * Block operations , copyAddr+#if __GLASGOW_HASKELL__ >= 708 , copyAddrToByteArray+#endif , moveAddr , setAddr -- * Conversion@@ -32,6 +35,14 @@ import GHC.Ptr import Foreign.Marshal.Utils +#if __GLASGOW_HASKELL__ < 708+toBool# :: Bool -> Bool+toBool# = id+#else+toBool# :: Int# -> Bool+toBool# = isTrue#+#endif+ -- | A machine address data Addr = Addr Addr# @@ -40,14 +51,14 @@ showString "0x" . showHex (fromIntegral (I# (addr2Int# a)) :: Word) instance Eq Addr where- Addr a# == Addr b# = isTrue# (eqAddr# a# b#)- Addr a# /= Addr b# = isTrue# (neAddr# a# b#)+ Addr a# == Addr b# = toBool# (eqAddr# a# b#)+ Addr a# /= Addr b# = toBool# (neAddr# a# b#) instance Ord Addr where- Addr a# > Addr b# = isTrue# (gtAddr# a# b#)- Addr a# >= Addr b# = isTrue# (geAddr# a# b#)- Addr a# < Addr b# = isTrue# (ltAddr# a# b#)- Addr a# <= Addr b# = isTrue# (leAddr# a# b#)+ Addr a# > Addr b# = toBool# (gtAddr# a# b#)+ Addr a# >= Addr b# = toBool# (geAddr# a# b#)+ Addr a# < Addr b# = toBool# (ltAddr# a# b#)+ Addr a# <= Addr b# = toBool# (leAddr# a# b#) -- | The null address nullAddr :: Addr@@ -99,6 +110,7 @@ copyAddr (Addr dst#) (Addr src#) n = unsafePrimToPrim $ copyBytes (Ptr dst#) (Ptr src#) n +#if __GLASGOW_HASKELL__ >= 708 -- | Copy the given number of bytes from the 'Addr' to the 'MutableByteArray'. -- The areas may not overlap. This function is only available when compiling -- with GHC 7.8 or newer.@@ -111,13 +123,15 @@ {-# INLINE copyAddrToByteArray #-} copyAddrToByteArray (MutableByteArray marr) (I# off) (Addr addr) (I# len) = primitive_ $ copyAddrToByteArray# addr marr off len+#endif -- | Copy the given number of bytes from the second 'Addr' to the first. The -- areas may overlap.-moveAddr :: PrimMonad m => Addr -- ^ destination address- -> Addr -- ^ source address- -> Int -- ^ number of bytes- -> m ()+moveAddr :: PrimMonad m+ => Addr -- ^ destination address+ -> Addr -- ^ source address+ -> Int -- ^ number of bytes+ -> m () {-# INLINE moveAddr #-} moveAddr (Addr dst#) (Addr src#) n = unsafePrimToPrim $ moveBytes (Ptr dst#) (Ptr src#) n