
On March 15, 2010 12:48:02 Iavor Diatchki wrote:
I have implemented a small extension to the FFI which allows for "static_wrapper" imports. These are a variation on "wrapper" imports that do not use run-time code generation. This is important in security sensitive contexts because it avoids executable data. While "static_wrapper" imports are less general then "wrapper" imports, they can be used to install Haskell handlers in many C libraries where callbacks have an extra "user-data" parameter (e.g., GTK signal handlers).
Hi Iavor, Would not the following also do what you want foreign export ccall "haskellCIntCInt" \ cbind :: CInt -> StablePtr (CInt -> IO CInt) -> IO CInt cbind :: a -> StablePtr (a-> IO b) -> IO b cbind x f = deRefStablePtr f >>= (\f_ -> f_ x) On the C side you would then have something like register_callback(haskellCIntInt,<wrapped haskell closure>) where <wrapped haskell closure> would be a stable pointer of type StablePtr (CInt -> IO CInt) generated on the haskell side via newStablePtr <haskell closure> and passed to the C code. Cheers! -Tyson