packages feed

derive-storable 0.2.0.0 → 0.3.0.0

raw patch · 6 files changed

+24/−160 lines, 6 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Foreign.Storable.Generic: instance Foreign.Storable.Generic.Internal.GStorable a => Foreign.Storable.Storable a
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable (GHC.Ptr.FunPtr a)
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable (GHC.Ptr.Ptr a)
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable (GHC.Stable.StablePtr a)
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable Foreign.C.Types.CChar
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable Foreign.C.Types.CClock
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable Foreign.C.Types.CDouble
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable Foreign.C.Types.CFloat
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable Foreign.C.Types.CInt
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable Foreign.C.Types.CIntMax
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable Foreign.C.Types.CLLong
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable Foreign.C.Types.CLong
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable Foreign.C.Types.CPtrdiff
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable Foreign.C.Types.CSChar
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable Foreign.C.Types.CSUSeconds
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable Foreign.C.Types.CShort
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable Foreign.C.Types.CSigAtomic
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable Foreign.C.Types.CTime
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable Foreign.C.Types.CUChar
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable Foreign.C.Types.CUInt
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable Foreign.C.Types.CUIntMax
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable Foreign.C.Types.CULLong
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable Foreign.C.Types.CULong
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable Foreign.C.Types.CUSeconds
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable Foreign.C.Types.CUShort
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable Foreign.Ptr.IntPtr
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable Foreign.Ptr.WordPtr
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable GHC.Fingerprint.Type.Fingerprint
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable GHC.Int.Int16
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable GHC.Int.Int32
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable GHC.Int.Int64
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable GHC.Int.Int8
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable GHC.Types.Bool
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable GHC.Types.Char
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable GHC.Types.Double
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable GHC.Types.Float
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable GHC.Types.Int
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable GHC.Types.Word
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable GHC.Word.Word16
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable GHC.Word.Word32
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable GHC.Word.Word64
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable GHC.Word.Word8
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable System.Posix.Types.CCc
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable System.Posix.Types.CDev
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable System.Posix.Types.CGid
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable System.Posix.Types.CIno
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable System.Posix.Types.CMode
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable System.Posix.Types.CNlink
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable System.Posix.Types.COff
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable System.Posix.Types.CPid
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable System.Posix.Types.CRLim
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable System.Posix.Types.CSpeed
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable System.Posix.Types.CSsize
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable System.Posix.Types.CTcflag
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable System.Posix.Types.CUid
- Foreign.Storable.Generic.Instances: instance Foreign.Storable.Generic.Internal.GStorable System.Posix.Types.Fd
- Foreign.Storable.Generic.Internal: instance (Foreign.Storable.Generic.Internal.ConstraintsAll a, Foreign.Storable.Generic.Tools.TypeFuns.IsSumType (GHC.Generics.Rep a) Data.Type.Equality.~ 'GHC.Types.False) => Foreign.Storable.Generic.Internal.GStorableChoice' 'GHC.Types.False a
- Foreign.Storable.Generic.Internal: instance (GHC.Generics.Generic a, GHC.TypeNats.KnownNat (Foreign.Storable.Generic.Tools.TypeFuns.SumArity (GHC.Generics.Rep a)), Foreign.Storable.Generic.Internal.GStorableSum' (GHC.Generics.Rep a), Foreign.Storable.Generic.Tools.TypeFuns.IsSumType (GHC.Generics.Rep a) Data.Type.Equality.~ 'GHC.Types.True) => Foreign.Storable.Generic.Internal.GStorableChoice' 'GHC.Types.True a
- Foreign.Storable.Generic.Internal: instance Foreign.Storable.Generic.Internal.GStorable a => Foreign.Storable.Generic.Internal.GStorable' (GHC.Generics.K1 i a)
+ Foreign.Storable.Generic.Internal: alignment :: Storable a => a -> Int
+ Foreign.Storable.Generic.Internal: class Storable a
+ Foreign.Storable.Generic.Internal: instance (Foreign.Storable.Generic.Internal.ConstraintsAll a, Foreign.Storable.Generic.Tools.TypeFuns.IsSumType (GHC.Generics.Rep a) GHC.Types.~ 'GHC.Types.False) => Foreign.Storable.Generic.Internal.GStorableChoice' 'GHC.Types.False a
+ Foreign.Storable.Generic.Internal: instance (GHC.Generics.Generic a, GHC.TypeNats.KnownNat (Foreign.Storable.Generic.Tools.TypeFuns.SumArity (GHC.Generics.Rep a)), Foreign.Storable.Generic.Internal.GStorableSum' (GHC.Generics.Rep a), Foreign.Storable.Generic.Tools.TypeFuns.IsSumType (GHC.Generics.Rep a) GHC.Types.~ 'GHC.Types.True) => Foreign.Storable.Generic.Internal.GStorableChoice' 'GHC.Types.True a
+ Foreign.Storable.Generic.Internal: instance Foreign.Storable.Generic.Internal.GStorable a => Foreign.Storable.Storable a
+ Foreign.Storable.Generic.Internal: instance Foreign.Storable.Storable a => Foreign.Storable.Generic.Internal.GStorable' (GHC.Generics.K1 i a)
+ Foreign.Storable.Generic.Internal: peek :: Storable a => Ptr a -> IO a
+ Foreign.Storable.Generic.Internal: peekByteOff :: Storable a => Ptr b -> Int -> IO a
+ Foreign.Storable.Generic.Internal: peekElemOff :: Storable a => Ptr a -> Int -> IO a
+ Foreign.Storable.Generic.Internal: poke :: Storable a => Ptr a -> a -> IO ()
+ Foreign.Storable.Generic.Internal: pokeByteOff :: Storable a => Ptr b -> Int -> a -> IO ()
+ Foreign.Storable.Generic.Internal: pokeElemOff :: Storable a => Ptr a -> Int -> a -> IO ()
+ Foreign.Storable.Generic.Internal: sizeOf :: Storable a => a -> Int

Files

ChangeLog.md view
@@ -1,5 +1,9 @@ # Revision history for derive-storable +## 0.3.0.0  -- 2020-03-01++* Removed instances module. A breaking change therefore bump to 0.3.+ ## 0.2.0.0  -- 2020-03-01  * Added support for sum types enabled through additional option.
derive-storable.cabal view
@@ -1,6 +1,6 @@ name:                derive-storable -version:             0.2.0.0+version:             0.3.0.0 synopsis:            Derive Storable instances with GHC.Generics.             description:         Derive Storable instances with GHC.Generics. The derived Storable instances have the same alignment as C structs.@@ -29,7 +29,6 @@ library   exposed-modules:     Foreign.Storable.Generic                       , Foreign.Storable.Generic.Internal-                     , Foreign.Storable.Generic.Instances                             , Foreign.Storable.Generic.Tools                      , Foreign.Storable.Generic.Tools.TypeFuns   build-depends:       base >=4.8 && < 5@@ -54,7 +53,6 @@   c-sources:           test/Basic/cbits/TestCases.c    main-is:             MemoryCSpec.hs   other-modules:       Foreign.Storable.Generic-                     , Foreign.Storable.Generic.Instances                      , Foreign.Storable.Generic.Internal                      , Foreign.Storable.Generic.Tools                      , Foreign.Storable.Generic.Tools.TypeFuns
src/Foreign/Storable/Generic.hs view
@@ -22,21 +22,4 @@   import Foreign.Storable (Storable(..))- import Foreign.Storable.Generic.Internal (GStorable (..))-import Foreign.Storable.Generic.Instances---------Association to Storable class---------instance {-# OVERLAPS #-} (GStorable a) => (Storable a) where-    {-# INLINE sizeOf #-}-    sizeOf      = gsizeOf-    {-# INLINE alignment #-}-    alignment   = galignment-    {-# INLINE peekByteOff #-}-    peekByteOff = gpeekByteOff-    {-# INLINE pokeByteOff #-}-    pokeByteOff = gpokeByteOff--
− src/Foreign/Storable/Generic/Instances.hs
@@ -1,133 +0,0 @@-{-|-Module      : Foreign.Storable.Generic.Instances-Copyright   : (c) Mateusz Kłoczko, 2016-License     : MIT-Maintainer  : mateusz.p.kloczko@gmail.com-Stability   : experimental-Portability : portable----}---{-# LANGUAGE CPP #-}-#include "HsBaseConfig.h"-module Foreign.Storable.Generic.Instances () where--import Data.Int-import Data.Word-import Foreign.C.Types-import Foreign.Ptr-import Foreign.StablePtr-import Foreign.Storable-import Foreign.Storable.Generic.Internal-import GHC.Fingerprint.Type-import System.Posix.Types-import Data.Ratio (Ratio)--#define MakeGStorable(Type)     \-instance GStorable Type where   \-    {-#INLINE gsizeOf #-}       \-;   gsizeOf      = sizeOf       \-;   {-#INLINE galignment #-}    \-;   galignment   = alignment    \-;   {-#INLINE gpeekByteOff #-}  \-;   gpeekByteOff = peekByteOff  \-;   {-#INLINE gpokeByteOff #-}  \-;   gpokeByteOff = pokeByteOff  \---- Haskell primitives-MakeGStorable(Bool)-MakeGStorable(Char)-MakeGStorable(Double)-MakeGStorable(Float)--MakeGStorable(Int)-MakeGStorable(Int8)-MakeGStorable(Int16)-MakeGStorable(Int32)-MakeGStorable(Int64)--MakeGStorable(Word)-MakeGStorable(Word8)-MakeGStorable(Word16)-MakeGStorable(Word32)-MakeGStorable(Word64)--MakeGStorable(Fingerprint)---- C primitives-MakeGStorable(CUIntMax)-MakeGStorable(CIntMax)-MakeGStorable(CSUSeconds)-MakeGStorable(CUSeconds)-MakeGStorable(CTime)-MakeGStorable(CClock)-MakeGStorable(CSigAtomic)-MakeGStorable(CPtrdiff)-MakeGStorable(CDouble)-MakeGStorable(CFloat)-MakeGStorable(CULLong)-MakeGStorable(CLLong)-MakeGStorable(CULong)-MakeGStorable(CLong)-MakeGStorable(CUInt)-MakeGStorable(CInt)-MakeGStorable(CUShort)-MakeGStorable(CShort)-MakeGStorable(CUChar)-MakeGStorable(CSChar)-MakeGStorable(CChar)---- Ptr-MakeGStorable(IntPtr)-MakeGStorable(WordPtr)--MakeGStorable((StablePtr a))-MakeGStorable((Ptr a)) -MakeGStorable((FunPtr a))---- Posix-MakeGStorable(Fd)-#if defined(HTYPE_RLIM_T)-MakeGStorable(CRLim)-#endif-#if defined(HTYPE_TCFLAG_T)-MakeGStorable(CTcflag)-#endif-#if defined(HTYPE_SPEED_T)-MakeGStorable(CSpeed)-#endif-#if defined(HTYPE_CC_T)-MakeGStorable(CCc)-#endif-#if defined(HTYPE_UID_T)-MakeGStorable(CUid)-#endif-#if defined(HTYPE_NLINK_T)-MakeGStorable(CNlink)-#endif-#if defined(HTYPE_GID_T)-MakeGStorable(CGid)-#endif-#if defined(HTYPE_SSIZE_T)-MakeGStorable(CSsize)-#endif-#if defined(HTYPE_PID_T)-MakeGStorable(CPid)-#endif-#if defined(HTYPE_OFF_T)-MakeGStorable(COff)-#endif-#if defined(HTYPE_MODE_T)-MakeGStorable(CMode)-#endif-#if defined(HTYPE_INO_T)-MakeGStorable(CIno)-#endif-#if defined(HTYPE_DEV_T)-MakeGStorable(CDev)-#endif- --
src/Foreign/Storable/Generic/Internal.hs view
@@ -25,6 +25,7 @@ module Foreign.Storable.Generic.Internal (      GStorable'(..),      GStorable (..),+     Storable (..), #ifdef GSTORABLE_SUMTYPES      GStorableSum'(..),      GStorableChoice'(..),@@ -130,22 +131,21 @@     -- Concatenate the lists.     glistAlignment' _ = glistAlignment' (undefined :: f a) ++ glistAlignment' (undefined :: g a) -instance (GStorable a) => GStorable' (K1 i a) where+instance (Storable a) => GStorable' (K1 i a) where     {-# INLINE gpeekByteOff' #-}-    gpeekByteOff' offsets ix ptr offset = K1 <$> gpeekByteOff ptr (off1 + offset)+    gpeekByteOff' offsets ix ptr offset = K1 <$> peekByteOff ptr (off1 + offset)         where off1 = inline (offsets !! ix)     {-# INLINE gpokeByteOff' #-}-    gpokeByteOff' offsets ix ptr offset (K1 x) = gpokeByteOff ptr (off1 + offset) x+    gpokeByteOff' offsets ix ptr offset (K1 x) = pokeByteOff ptr (off1 + offset) x         where off1 = inline (offsets !! ix)        -- When the constructor is used, return the size of      -- the constructed type in a list.-    glistSizeOf' _ = [gsizeOf (undefined :: a)]+    glistSizeOf' _ = [sizeOf (undefined :: a)]     -- When the constructor is used, return the alignment of      -- the constructed type in a list.-    glistAlignment' _ = [galignment (undefined :: a)]  -+    glistAlignment' _ = [alignment (undefined :: a)]    #ifndef GSTORABLE_SUMTYPES type SumTypesDisabled = Text "By default sum types are not supported by GStorable instances." :$$: Text "You can pass a 'sumtypes' flag through 'cabal new-configure' to enable them." :$$: Text "In case of trouble, one can use '-DGSTORABLE_SUMTYPES' ghc flag instead." @@ -429,3 +429,16 @@     gpeekByteOffSum' _ _ _ = undefined     gpokeByteOffSum' _ _ _ = undefined #endif++------Association to Storable class-------++instance {-# OVERLAPS #-} (GStorable a) => (Storable a) where+    {-# INLINE sizeOf #-}+    sizeOf      = gsizeOf+    {-# INLINE alignment #-}+    alignment   = galignment+    {-# INLINE peekByteOff #-}+    peekByteOff = gpeekByteOff+    {-# INLINE pokeByteOff #-}+    pokeByteOff = gpokeByteOff+
test/Basic/TestCases.hs view
@@ -24,7 +24,6 @@  import Foreign.Storable.Generic.Tools import Foreign.Storable.Generic.Internal-import Foreign.Storable.Generic.Instances import Data.Int import Control.Monad (sequence, liftM) import System.Exit