[Haskell-cafe] FunPtr stability - suggested clarification to FFI Addendum

Claude Heiland-Allen claudiusmaximus at goto10.org
Thu Jun 14 15:49:58 EDT 2007


I think the FFI Addendum should make explicit that FunPtr values are 
stable (in the sense of StablePtr).

I'm writing a Haskell plugin for an application written in C, and the 
control flow is:

     C->Haskell->C ; C->Haskell->C ; ...

and I was confused by this statement in section 4.1 of the Addendum 
(under the subheading "Dynamic wrapper"):

The stub factory mkCallback turns any Haskell computation of type IO () 
into a C function pointer that can be passed to C routines, which can 
call back into the Haskell context by invoking the referenced function.

The usage of "call back" makes it clear that this control flow is ok:


but I wasn't sure whether the C code could store the pointer and call it 
later.  Apparently it is safe, but it isn't made explicit in the 
Addendum.  As SamB said in #haskell:

The fact that there is something called "freeHaskellFunPtr" seems to 
indicate that, yes, those things are stable.  It would be totally 
bonkers to have a "free" function if the associated memory was not 
stable (and, therefor, garbage collected).

Thanks for your attention,


More information about the Haskell-Cafe mailing list