hoppy-runtime 0.5.1 → 0.6.0
raw patch · 4 files changed
+46/−34 lines, 4 filesdep ~Cabaldep ~containerssetup-changedPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: Cabal, containers
API changes (from Hackage documentation)
- Foreign.Hoppy.Runtime: CBool :: CUChar -> CBool
- Foreign.Hoppy.Runtime: CUChar :: Word8 -> CUChar
- Foreign.Hoppy.Runtime: instance Foreign.Hoppy.Runtime.Assignable (GHC.Ptr.Ptr Foreign.Hoppy.Runtime.CBool) GHC.Types.Bool
- Foreign.Hoppy.Runtime: instance Foreign.Hoppy.Runtime.CppDefault Foreign.Hoppy.Runtime.CBool
- Foreign.Hoppy.Runtime: instance Foreign.Hoppy.Runtime.Decodable (GHC.Ptr.Ptr (GHC.Ptr.Ptr Foreign.Hoppy.Runtime.CBool)) (GHC.Ptr.Ptr Foreign.Hoppy.Runtime.CBool)
- Foreign.Hoppy.Runtime: instance Foreign.Hoppy.Runtime.Decodable (GHC.Ptr.Ptr Foreign.Hoppy.Runtime.CBool) GHC.Types.Bool
- Foreign.Hoppy.Runtime: instance Foreign.Storable.Storable Foreign.Hoppy.Runtime.CBool
- Foreign.Hoppy.Runtime: instance GHC.Classes.Eq Foreign.Hoppy.Runtime.CBool
- Foreign.Hoppy.Runtime: instance GHC.Classes.Ord Foreign.Hoppy.Runtime.CBool
- Foreign.Hoppy.Runtime: instance GHC.Enum.Bounded Foreign.Hoppy.Runtime.CBool
- Foreign.Hoppy.Runtime: instance GHC.Enum.Enum Foreign.Hoppy.Runtime.CBool
- Foreign.Hoppy.Runtime: instance GHC.Exception.Exception Foreign.Hoppy.Runtime.SomeCppException
- Foreign.Hoppy.Runtime: instance GHC.Num.Num Foreign.Hoppy.Runtime.CBool
- Foreign.Hoppy.Runtime: instance GHC.Real.Integral Foreign.Hoppy.Runtime.CBool
- Foreign.Hoppy.Runtime: instance GHC.Real.Real Foreign.Hoppy.Runtime.CBool
- Foreign.Hoppy.Runtime: instance GHC.Show.Show Foreign.Hoppy.Runtime.CBool
- Foreign.Hoppy.Runtime: newtype CBool
- Foreign.Hoppy.Runtime: newtype CUChar
+ Foreign.Hoppy.Runtime: class CppEnum n e | e -> n
+ Foreign.Hoppy.Runtime: fromCppEnum :: CppEnum n e => e -> n
+ Foreign.Hoppy.Runtime: instance Foreign.Hoppy.Runtime.Assignable (GHC.Ptr.Ptr Foreign.C.Types.CBool) GHC.Types.Bool
+ Foreign.Hoppy.Runtime: instance Foreign.Hoppy.Runtime.CppDefault Foreign.C.Types.CBool
+ Foreign.Hoppy.Runtime: instance Foreign.Hoppy.Runtime.Decodable (GHC.Ptr.Ptr (GHC.Ptr.Ptr Foreign.C.Types.CBool)) (GHC.Ptr.Ptr Foreign.C.Types.CBool)
+ Foreign.Hoppy.Runtime: instance Foreign.Hoppy.Runtime.Decodable (GHC.Ptr.Ptr Foreign.C.Types.CBool) GHC.Types.Bool
+ Foreign.Hoppy.Runtime: instance GHC.Exception.Type.Exception Foreign.Hoppy.Runtime.SomeCppException
+ Foreign.Hoppy.Runtime: toCppEnum :: (CppEnum n e, HasCallStack) => n -> e
+ Foreign.Hoppy.Setup: [interfaceName] :: ProjectConfig -> Maybe String
- Foreign.Hoppy.Runtime: CCallback :: (Ptr ()) -> CCallback fnHsCType
+ Foreign.Hoppy.Runtime: CCallback :: Ptr () -> CCallback fnHsCType
- Foreign.Hoppy.Runtime: ExceptionClassInfo :: ExceptionId -> String -> Map ExceptionId (Ptr () -> Ptr ()) -> Ptr () -> IO () -> Ptr () -> IO (Ptr ()) -> Ptr () -> IO (ForeignPtr ()) -> ExceptionClassInfo
+ Foreign.Hoppy.Runtime: ExceptionClassInfo :: ExceptionId -> String -> Map ExceptionId (Ptr () -> Ptr ()) -> (Ptr () -> IO ()) -> (Ptr () -> IO (Ptr ())) -> (Ptr () -> IO (ForeignPtr ())) -> ExceptionClassInfo
- Foreign.Hoppy.Runtime: ExceptionDb :: (Map ExceptionId ExceptionClassInfo) -> ExceptionDb
+ Foreign.Hoppy.Runtime: ExceptionDb :: Map ExceptionId ExceptionClassInfo -> ExceptionDb
- Foreign.Hoppy.Runtime: SomeCppException :: ExceptionClassInfo -> (Maybe (ForeignPtr ())) -> (Ptr ()) -> SomeCppException
+ Foreign.Hoppy.Runtime: SomeCppException :: ExceptionClassInfo -> Maybe (ForeignPtr ()) -> Ptr () -> SomeCppException
- Foreign.Hoppy.Setup: ProjectConfig :: FilePath -> String -> FilePath -> FilePath -> ProjectConfig
+ Foreign.Hoppy.Setup: ProjectConfig :: FilePath -> String -> FilePath -> FilePath -> Maybe String -> ProjectConfig
Files
- Setup.hs +1/−1
- hoppy-runtime.cabal +5/−4
- src/Foreign/Hoppy/Runtime.hs +20/−23
- src/Foreign/Hoppy/Setup.hs +20/−6
Setup.hs view
@@ -1,6 +1,6 @@ -- This file is part of Hoppy. ----- Copyright 2015-2018 Bryan Gardiner <bog@khumba.net>+-- Copyright 2015-2019 Bryan Gardiner <bog@khumba.net> -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License.
hoppy-runtime.cabal view
@@ -1,12 +1,12 @@ name: hoppy-runtime-version: 0.5.1+version: 0.6.0 synopsis: C++ FFI generator - Runtime support homepage: http://khumba.net/projects/hoppy license: Apache-2.0 license-file: LICENSE author: Bryan Gardiner <bog@khumba.net> maintainer: Bryan Gardiner <bog@khumba.net>-copyright: Copyright 2015-2018 Bryan Gardiner+copyright: Copyright 2015-2019 Bryan Gardiner category: Foreign build-type: Simple cabal-version: >=1.10@@ -26,12 +26,13 @@ , FlexibleInstances , FunctionalDependencies , GeneralizedNewtypeDeriving+ , LambdaCase , MultiParamTypeClasses , ScopedTypeVariables build-depends: base >=4.7 && <5- , Cabal >=1.20 && <2.3- , containers >=0.5 && <0.6+ , Cabal >=1.20 && <2.5+ , containers >=0.5 && <0.7 , directory >=1.2 && <1.4 , filepath >=1.3 && <1.5 hs-source-dirs: src
src/Foreign/Hoppy/Runtime.hs view
@@ -1,6 +1,6 @@ -- This file is part of Hoppy. ----- Copyright 2015-2018 Bryan Gardiner <bog@khumba.net>+-- Copyright 2015-2019 Bryan Gardiner <bog@khumba.net> -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License.@@ -17,11 +17,9 @@ -- | Runtime support for generated Haskell bindings. module Foreign.Hoppy.Runtime ( -- * Primitive types- CBool (..),- -- CBool is a newtype for CUChar, so GHC 7.10 (at least) requires reexporting- -- the CUChar data constructor for CBool to be marshalled in foreign imports.- CUChar (CUChar), coerceIntegral,+ -- * Enumerations+ CppEnum (..), -- * Objects CppPtr (..), Deletable (..),@@ -73,6 +71,7 @@ touchForeignPtr, ) import Foreign.C (+ CBool, CChar, CDouble, CFloat,@@ -82,12 +81,13 @@ CPtrdiff, CShort, CSize,- CUChar (CUChar),+ CUChar, CUInt, CULLong, CULong, CUShort, )+import GHC.Stack (HasCallStack) import System.IO.Unsafe (unsafePerformIO) import System.Posix.Types (CSsize) import Unsafe.Coerce (unsafeCoerce)@@ -96,22 +96,6 @@ :: (FunPtr (IO ()) -> IO ()) -> IO (FunPtr (FunPtr (IO ()) -> IO ())) --- | A numeric type representing a C++ boolean.-newtype CBool = CBool CUChar- deriving (Eq, Integral, Num, Ord, Real, Show, Storable)--instance Bounded CBool where- minBound = 0- maxBound = 1--instance Enum CBool where- fromEnum (CBool n) = fromIntegral n-- toEnum n =- if n == 0 || n == 1- then CBool $ fromIntegral n- else error $ concat ["CBool.toEnum: Invalid value ", show n, "."]- -- | Converts between integral types by going from @a@ to @b@, and also -- round-tripping the @b@ value back to an @a@ value. If the two @a@ values -- don't match, then an error is signalled.@@ -124,6 +108,19 @@ else error $ "Conversion from " ++ show (typeOf a) ++ " to " ++ show (typeOf b) ++ " does not preserve the value " ++ show a ++ "." +-- | An instance @e@ of this class represents a value belonging to a C+++-- enumeration with numeric type @n@.+class CppEnum n e | e -> n where+ -- | Converts a number into an enum value.+ --+ -- If the Hoppy binding didn't request that the enum support arbitrary unknown+ -- values, then given an entry not explicitly supported by the enum, this+ -- throws an exception.+ toCppEnum :: HasCallStack => n -> e++ -- | Extracts the number that an enum value represents.+ fromCppEnum :: e -> n+ -- | An instance of this class represents a handle (a pointer) to a C++ object. -- All C++ classes bound by Hoppy have instances of @CppPtr@. The lifetime of -- such an object can optionally be managed by the Haskell garbage collector.@@ -463,7 +460,7 @@ -- Indicate no exception unless we catch something. poke excIdPtr 0 - catch doCall $ \caughtEx -> case caughtEx of+ catch doCall $ \case SomeCppException classInfo caughtFPtr caughtPtr -> do let ExceptionId excId = exceptionClassId classInfo poke excIdPtr excId
src/Foreign/Hoppy/Setup.hs view
@@ -1,6 +1,6 @@ -- This file is part of Hoppy. ----- Copyright 2015-2018 Bryan Gardiner <bog@khumba.net>+-- Copyright 2015-2019 Bryan Gardiner <bog@khumba.net> -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License.@@ -156,11 +156,20 @@ , hsSourcesDir :: FilePath -- ^ The directory into which to generate Haskell sources, under the Haskell -- gateway package root.+ , interfaceName :: Maybe String+ -- ^ If the generator contains multiple interfaces, then this can be used to+ -- select one. If present, it is passed as an argument to @--interface@+ -- when invoking the generator. If absent, the default interface is used. } getGeneratorProgram :: ProjectConfig -> Program getGeneratorProgram project = simpleProgram $ generatorExecutableName project +getInterfaceArg :: ProjectConfig -> [String]+getInterfaceArg project = case interfaceName project of+ Just name -> ["--interface", name]+ Nothing -> []+ -- | A @main@ implementation to be used in the @Setup.hs@ of a C++ gateway -- package. --@@ -234,7 +243,8 @@ let programDb = withPrograms localBuildInfo sourcesDir = cppSourcesDir project createDirectoryIfMissing True sourcesDir- runDbProgram verbosity generatorProgram programDb ["--gen-cpp", sourcesDir]+ runDbProgram verbosity generatorProgram programDb $+ getInterfaceArg project ++ ["--gen-cpp", sourcesDir] -- When there is a configure script, then run it. maybeConfigureProgram <- findConfigure@@ -305,8 +315,8 @@ die #endif "No Makefile found."- makeProgram <- findSystemProgram verbosity "make"- runProgram verbosity makeProgram ["clean"]+ make <- findSystemProgram verbosity "make"+ runProgram verbosity make ["clean"] findSystemProgram :: Verbosity -> FilePath -> IO ConfiguredProgram findSystemProgram verbosity basename = do@@ -421,7 +431,8 @@ let programDb = withPrograms localBuildInfo sourcesDir = hsSourcesDir project createDirectoryIfMissing True sourcesDir- runDbProgram verbosity generatorProgram programDb ["--gen-hs", sourcesDir]+ runDbProgram verbosity generatorProgram programDb $+ getInterfaceArg project ++ ["--gen-hs", sourcesDir] addLibDir :: IO HookedBuildInfo addLibDir = do@@ -438,7 +449,10 @@ Cpp -> ("--list-cpp-files", cppSourcesDir) Haskell -> ("--list-hs-files", hsSourcesDir) generatorProgram <- findSystemProgram verbosity $ generatorExecutableName project- generatedFiles <- fmap lines $ getProgramOutput verbosity generatorProgram [listArg]+ generatedFiles <-+ lines <$> getProgramOutput verbosity+ generatorProgram+ (getInterfaceArg project ++ [listArg]) forM_ generatedFiles $ \file -> do let path = sourcesDir project </> file exists <- doesFileExist path