Sven.Panne at informatik.uni-muenchen.de
Sun Jun 16 14:06:59 EDT 2002
Just for clarification: Is it OK to call freeHaskellFunPtr in the
Haskell function pointed to itself, i.e. a kind of "self destruction"?
foreign import ccall "wrapper" makeCB :: IO () -> IO (FunPtr (IO ()))
funPtr <- mfix (\self -> makeCB (do freeHaskellFunPtr self; ...))
<register funPtr somewhere in C land>
The FFI spec doesn't say anything about this, but it would be very
handy if this was allowed, e.g. for one-shot callbacks. After a short
look into GHC's and Hugs' RTS I think it is OK for both systems: The
thunk/adjustor has always a jump at its end, so free-ing the machine
code at the jump destination does no harm.
More information about the FFI