"static_wrapper" imports in the FFI
Tyson Whitehead
twhitehead at gmail.com
Mon Mar 15 18:56:12 EDT 2010
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20100315/b335611f/attachment.bin
More information about the Glasgow-haskell-users
mailing list