Problem with FFI?

John Meacham john@repetae.net
Sat, 25 May 2002 18:37:00 -0700


I may be missing something obvious here, but from the current FFI spec
it appears that it is impossible to create libraries in haskell which
are meant to be called from c code without running into undefined
behavior. The problem is in the definition of 
hs_init() and hs_exit()
.
now, it is acceptable to have hs_init and hs_exit called in the
initialization and finalization of your library, but the problem arrises
when you link against more than one library which is implemented in
haskell, suddenly whichever library is initialized secondly segfaults! (or
whatever undefined behaviour means.).
programs could suddenly stop working when a library is changed from a c
implementation to a haskell one, which seems to be a bad thing.

proposed fix:
allow nested calls to hs_init, hs_exit, a counter is incremented when
hs_init is called more than once, and decremented on hs_exit. only the
last call to hs_exit will actually do whatever needs to be done.

note that this cannot be implemented by the programmer himself since
there might be several third party libraries also implemented in haskell
which an app wishes to link against.

this is sort of a showstopper for people (like me!) who wish to just use
haskell as an implementation language for a library which is meant to be
called from C.

but then again, perhaps i am missing something obvious.
	John

-- 
---------------------------------------------------------------------------
John Meacham - California Institute of Technology, Alum. - john@foo.net
---------------------------------------------------------------------------