packages feed

inline-c 0.9.1.0 → 0.9.1.1

raw patch · 11 files changed

+42/−13 lines, 11 filesPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

API changes (from Hackage documentation)

+ Language.C.Types: TemplatePointer :: TypeSpecifier -> TypeSpecifier
+ Language.C.Types.Parse: TemplatePointer :: TypeSpecifier -> TypeSpecifier

Files

README.md view
@@ -317,5 +317,6 @@ ```  [ghc-manual-quasiquotation]:-https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/template-haskell.html#th-quasiquotation-[ghc-manual-template-haskell]: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/template-haskell.html+https://downloads.haskell.org/ghc/latest/docs/html/users_guide/glasgow_exts.html#template-haskell-quasi-quotation+[ghc-manual-template-haskell]:+https://downloads.haskell.org/ghc/latest/docs/html/users_guide/glasgow_exts.html#template-haskell
changelog.md view
@@ -1,4 +1,5 @@-- 0.9.0.1: Add `Language.C.Inline.substitute` and `Language.C.Inline.getHaskellType`.+- 0.9.1.1: Use `unsafeDupablePerformIO` rather than `unsafePerformIO`. See issue #115 and PR #117.+- 0.9.1.0: Add `Language.C.Inline.substitute` and `Language.C.Inline.getHaskellType`. - 0.9.0.0: Add support for C++ namespace and template. - 0.8.0.1: Compatibility with GHC 8.8 - 0.8: Add code locations.
inline-c.cabal view
@@ -1,5 +1,5 @@ name:                inline-c-version:             0.9.1.0+version:             0.9.1.1 synopsis:            Write Haskell source files including C code inline. No FFI required. description:         See <https://github.com/fpco/inline-c/blob/master/README.md>. license:             MIT@@ -8,7 +8,7 @@ maintainer:          f@mazzo.li copyright:           (c) 2015-2016 FP Complete Corporation, (c) 2017-2019 Francesco Mazzoli category:            FFI-tested-with:         GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.5+tested-with:         GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.5, GHC == 8.8.4, GHC == 8.10.2 build-type:          Simple cabal-version:       >=1.10 Extra-Source-Files:  README.md, changelog.md
src/Language/C/Inline.hs view
@@ -241,10 +241,15 @@  -- | Variant of 'exp', for use with expressions known to have no side effects. ----- BEWARE: use this function with caution, only when you know what you are+-- __BEWARE__: Use this function with caution, only when you know what you are -- doing. If an expression does in fact have side-effects, then indiscriminate -- use of 'pure' may endanger referential transparency, and in principle even--- type safety.+-- type safety. Also note that the function might be called multiple times,+-- given that 'System.IO.Unsafe.unsafeDupablePerformIO' is used to call the+-- provided C code.  Please refer to the documentation for+-- 'System.IO.Unsafe.unsafePerformIO' for more details.+-- [unsafeDupablePerformIO is used to ensure good performance using the+-- threaded runtime](https://github.com/fpco/inline-c/issues/115). pure :: TH.QuasiQuoter pure = genericQuote Pure $ inlineExp TH.Safe 
src/Language/C/Inline/Context.hs view
@@ -299,6 +299,10 @@       C.TypeSpecifier _specs (C.TemplateConst num) -> do         let n = (TH.LitT (TH.NumTyLit (read num)))         lift [t| $(return n) |]+      C.TypeSpecifier _specs (C.TemplatePointer cSpec) -> do+        case Map.lookup cSpec cTypes of+          Nothing -> mzero+          Just ty -> lift [t| Ptr $(ty) |]       C.TypeSpecifier _specs cSpec ->         case Map.lookup cSpec cTypes of           Nothing -> mzero
src/Language/C/Inline/Internal.hs view
@@ -70,7 +70,7 @@ import qualified Language.Haskell.TH as TH import qualified Language.Haskell.TH.Quote as TH import qualified Language.Haskell.TH.Syntax as TH-import           System.IO.Unsafe (unsafePerformIO)+import           System.IO.Unsafe (unsafePerformIO, unsafeDupablePerformIO) import qualified Text.Parsec as Parsec import qualified Text.Parsec.Pos as Parsec import qualified Text.Parser.Char as Parser@@ -659,7 +659,8 @@     ioCall <- buildFunCall ctx (build here hsFunType cType cParams' cExp) (map snd hsParams) []     -- If the user requested a pure function, make it so.     case purity of-      Pure -> [| unsafePerformIO $(return ioCall) |]+      -- Using unsafeDupablePerformIO to increase performance of pure calls, see <https://github.com/fpco/inline-c/issues/115>+      Pure -> [| unsafeDupablePerformIO $(return ioCall) |]       IO -> return ioCall   where     buildFunCall :: Context -> TH.ExpQ -> [TH.Exp] -> [TH.Name] -> TH.ExpQ
src/Language/C/Inline/Interruptible.hs view
@@ -1,7 +1,7 @@ {-# LANGUAGE CPP #-}  -- | @interruptible@ variants of the "Language.C.Inline" quasi-quoters, to call--- interruptible C code. See <https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/ffi.html#ffi-interruptible>+-- interruptible C code. See <https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/ffi-chap.html#interruptible-foreign-calls> -- for more information. -- -- This module is intended to be imported qualified:
src/Language/C/Inline/Unsafe.hs view
@@ -37,10 +37,16 @@  -- | Variant of 'exp', for use with expressions known to have no side effects. ----- BEWARE: use this function with caution, only when you know what you are+-- __BEWARE__: Use this function with caution, only when you know what you are -- doing. If an expression does in fact have side-effects, then indiscriminate -- use of 'pure' may endanger referential transparency, and in principle even--- type safety.+-- type safety. Also note that the function may run more than once and that it+-- may run in parallel with itself, given that+-- 'System.IO.Unsafe.unsafeDupablePerformIO' is used to call the provided C+-- code [to ensure good performance using the threaded+-- runtime](https://github.com/fpco/inline-c/issues/115).  Please refer to the+-- documentation for 'System.IO.Unsafe.unsafeDupablePerformIO' for more+-- details. pure :: TH.QuasiQuoter pure = genericQuote Pure $ inlineExp TH.Unsafe 
src/Language/C/Types.hs view
@@ -105,6 +105,7 @@   | Enum P.CIdentifier   | Template P.CIdentifier [TypeSpecifier]   | TemplateConst String+  | TemplatePointer TypeSpecifier   deriving (Typeable, Show, Eq, Ord)  data Specifiers = Specifiers@@ -216,6 +217,10 @@         P.TemplateConst s -> do           checkNoSpecs           return $ TemplateConst s+        P.TemplatePointer s -> do+          checkNoSpecs+          s' <- type2type s+          return $ TemplatePointer s'         P.TypeName s -> do           checkNoSpecs           return $ TypeName s@@ -406,6 +411,7 @@         Enum s -> [P.Enum s]         Template s types -> [P.Template s (concat (map pTySpecs types))]         TemplateConst s -> [P.TemplateConst s]+        TemplatePointer type' -> [P.TemplatePointer (head (pTySpecs type'))]   in map P.StorageClassSpecifier storages ++      map P.TypeQualifier tyQuals ++      map P.FunctionSpecifier funSpecs ++@@ -511,6 +517,7 @@     Enum s -> "enum" <+> PP.pretty s     Template s args -> PP.pretty s <+> "<"  <+>  mconcat (intersperse "," (map PP.pretty args))  <+> ">"     TemplateConst s -> PP.pretty s+    TemplatePointer s -> PP.pretty s <+> "*"  instance PP.Pretty UntangleErr where   pretty err = case err of
src/Language/C/Types/Parse.hs view
@@ -300,6 +300,7 @@   | TypeName CIdentifier   | Template CIdentifier [TypeSpecifier]   | TemplateConst String+  | TemplatePointer TypeSpecifier   deriving (Typeable, Eq, Show)  type_specifier :: CParser i m => m TypeSpecifier@@ -379,7 +380,7 @@     cidentParserWithNamespace =       try (concat <$> sequence [cidentParser, (string "::"), cidentParserWithNamespace]) <|>       cidentParser-    templateArgType = try type_specifier <|> (TemplateConst <$> (many $ oneOf ['0'..'9']))+    templateArgType = try ((TemplatePointer <$> (type_specifier)) <* (string "*")) <|> try type_specifier <|> (TemplateConst <$> (many $ oneOf ['0'..'9']))     templateArgParser' = do       t <- templateArgType       _ <- string ","@@ -564,6 +565,7 @@    TypeName x -> pretty x    Template x args -> pretty x <+> "<" <+> mconcat (intersperse "," (map pretty args))  <+> ">"    TemplateConst x -> pretty x+   TemplatePointer x -> pretty x <+> "*"  instance Pretty TypeQualifier where   pretty tyQual = case tyQual of
test/Language/C/Inline/ParseSpec.hs view
@@ -41,6 +41,8 @@       cExp `shouldMatchBody` " (int) ceil(x[a-z0-9_]+ \\+ ((double) y[a-z0-9_]+)) "     Hspec.it "accepts anti quotes" $ do       void $ goodParse [r| int { $(int x) } |]+    Hspec.it "accepts anti quotes with pointer" $ do+      void $ goodParse [r| int* { $(int* x) } |]     Hspec.it "rejects if bad braces (1)" $ do       badParse [r| int x |]     Hspec.it "rejects if bad braces (2)" $ do