FFI digest, Vol 1 #218 - 3 msgs

George Russell ger at tzi.de
Tue Oct 1 05:05:30 EDT 2002


Manuel M T Chakravarty wrote:
> 
> George Russell <ger at tzi.de> wrote,
> 
> > Simon Marlow wrote
> > > PS. I'm sorry to keep banging on about this.  Ultimately it doesn't
> > > really matter to me that much, since I only really use mallocForeignPtr.
> > > I guess I was just intrigued to see if the problem was really as
> > > difficult as we'd thought.
> > [snip]
> > I'm glad you are banging on about it.  But since it looks unlikely that there is going
> > to be agreement on the matter, I suggest the following compromise.  We remove the
> > restriction that finalizers may not call Haskell functions in the main body of the standard,
> > but add a note that says that implementations may opt to impose such a restriction,
> > provided they document it in some standard way.
> 
> That's as good as not defining it at all.  
I agree that it's extremely unsatisfactory, but it seems the best option (to me) of defining
it is not going to be accepted.  So at least it would be better if GHC's documentation said
"We implement the FFI" while Hugs and NHC's said "We implement the FFI with the caveat that
finalizers may not call back into Haskell, as specified in section [blah]".  Since I regard this
caveat as an extremely important one (for example, it severely limits the use of the FFI to
link to languages like Java, which also have their own GC) it needs to be stated very clearly
in the documentation of those implementations which have it, rather than being left as an
embarassing hole which the user will only discover after a long and painful analysis of the
core-dumps.

> And given that
> the type signatures of the two versions are different, it
> isn't even a matter of imposing a runtime restriction.
No, that's not true.  I'm happy with the existing signature (addForeignFinalizer specifying
a pointer to an external function) since that will often be just what you want.  I'm just
unhappy with the restriction that the roof may fall in if by any means whatever a Haskell
function is called from the outside world during the duration of that foreign function.



More information about the FFI mailing list