inline-c 0.7.0.0 → 0.7.0.1
raw patch · 3 files changed
+30/−3 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- changelog.md +1/−0
- inline-c.cabal +1/−1
- src/Language/C/Inline.hs +28/−2
changelog.md view
@@ -1,3 +1,4 @@+- 0.7.0.1: Add more docs for `funPtr` - 0.7.0.0: Add `funPtr` quasi-quoter - 0.6.0.6: Support GHC 8.4 - 0.6.0.5: Update readme
inline-c.cabal view
@@ -1,5 +1,5 @@ name: inline-c-version: 0.7.0.0+version: 0.7.0.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
src/Language/C/Inline.hs view
@@ -36,7 +36,6 @@ , exp , pure , block- , funPtr , include , verbatim @@ -46,6 +45,8 @@ , WithPtrs(..) -- * 'FunPtr' utils+ , funPtr+ -- ** 'FunPtr' conversion -- -- Functions to quickly convert from/to 'FunPtr's. They're provided here -- since they can be useful to work with Haskell functions in C, and@@ -250,10 +251,35 @@ -- | Easily get a 'FunPtr': -- -- @--- let fp: FunPtr (Ptr CInt -> IO ()) = [C.funPtr| void poke42(int *ptr) { *ptr = 42; } |]+-- let fp :: FunPtr (Ptr CInt -> IO ()) = [C.funPtr| void poke42(int *ptr) { *ptr = 42; } |] -- @ -- -- Especially useful to generate finalizers that require C code.+--+-- Most importantly, this allows you to write `Foreign.ForeignPtr.newForeignPtr` invocations conveniently:+--+-- @+-- do+-- let c_finalizer_funPtr =+-- [C.funPtr| void myfree(char * ptr) { free(ptr); } |]+-- fp <- newForeignPtr c_finalizer_funPtr objPtr+-- @+--+-- Using where possible `Foreign.ForeignPtr.newForeignPtr` is superior to+-- resorting to its delayed-by-a-thread alternative `Foreign.Concurrent.newForeignPtr`+-- from "Foreign.Concurrent" which takes an @IO ()@ Haskell finaliser action:+-- With the non-concurrent `newForeignPtr` you can guarantee that the finaliser+-- will actually be run+--+-- * when a GC is executed under memory pressure, because it can point directly+-- to a C function that doesn't have to run any Haskell code (which is+-- problematic when you're out of memory)+-- * when the program terminates (`Foreign.Concurrent.newForeignPtr`'s finaliser+-- will likely NOT be called if your main thread exits, making your program+-- e.g. not Valgrind-clean if your finaliser is @free@ or C++'s @delete@).+--+-- `funPtr` makes the normal `newForeignPtr` as convenient as its concurrent+-- counterpart. funPtr :: TH.QuasiQuoter funPtr = funPtrQuote TH.Unsafe -- doesn't make much sense for this to be "safe", but it'd be good to verify what this means