ats-storable 0.1.0.6 → 0.2.0.0
raw patch · 2 files changed
+28/−1 lines, 2 filesdep +bytestringdep +textPVP ok
version bump matches the API change (PVP)
Dependencies added: bytestring, text
API changes (from Hackage documentation)
+ Foreign.Storable.ATS: class AsCString a
+ Foreign.Storable.ATS: instance Foreign.Storable.ATS.AsCString Data.ByteString.Internal.ByteString
+ Foreign.Storable.ATS: instance Foreign.Storable.ATS.AsCString Data.ByteString.Lazy.Internal.ByteString
+ Foreign.Storable.ATS: instance Foreign.Storable.ATS.AsCString Data.Text.Internal.Lazy.Text
+ Foreign.Storable.ATS: instance Foreign.Storable.ATS.AsCString Data.Text.Internal.Text
+ Foreign.Storable.ATS: instance Foreign.Storable.ATS.AsCString GHC.Base.String
+ Foreign.Storable.ATS: toCString :: AsCString a => a -> IO CString
Files
- ats-storable.cabal +3/−1
- src/Foreign/Storable/ATS.hs +25/−0
ats-storable.cabal view
@@ -1,5 +1,5 @@ name: ats-storable-version: 0.1.0.6+version: 0.2.0.0 synopsis: Marshal ATS types into Haskell description: Facilities for sharing types between ATS and Haskell homepage: https://github.com//ats-generic#readme@@ -25,6 +25,8 @@ exposed-modules: Foreign.Storable.ATS build-depends: base >= 4.9 && < 5 , composition-prelude+ , text+ , bytestring default-language: Haskell2010 if flag(development) ghc-options: -Werror
src/Foreign/Storable/ATS.hs view
@@ -8,15 +8,39 @@ module Foreign.Storable.ATS ( ATSStorable (..)+ , AsCString (..) ) where import Control.Composition+import qualified Data.ByteString as BS+import qualified Data.ByteString.Lazy as BSL+import qualified Data.Text as T+import qualified Data.Text.Lazy as TL import Data.Word+import Foreign.C.String import Foreign.Marshal.Alloc import Foreign.Ptr import qualified Foreign.Storable as C import GHC.Generics +class AsCString a where+ toCString :: a -> IO CString++instance AsCString String where+ toCString = newCString++instance AsCString T.Text where+ toCString = newCString . T.unpack++instance AsCString TL.Text where+ toCString = newCString . TL.unpack++instance AsCString BS.ByteString where+ toCString = flip BS.useAsCString pure++instance AsCString BSL.ByteString where+ toCString = flip BS.useAsCString pure . BSL.toStrict+ class Storable' f where sizeOf' :: f a -> Int@@ -61,6 +85,7 @@ peek :: Ptr a -> IO a peek = C.peek +-- FIXME this doesn't use reference types properly instance (Storable' a, Storable' b) => Storable' (a :+: b) where sizeOf' _ = 4 + max (sizeOf' (undefined :: a x)) (sizeOf' (undefined :: b x)) alignment' _ = gcd 4 $ gcd (alignment' (undefined :: a x)) (alignment' (undefined :: b x))