How to access hs_free_fun_ptr from a Visual Studio DLL
Simon Marlow
simonmarhaskell at gmail.com
Mon Mar 27 05:49:10 EST 2006
Sven Panne wrote:
> Am Samstag, 25. März 2006 20:00 schrieb Brian Hulley:
>
>>I've found a workaround to the problem below: instead of trying to use
>>hs_free_fun_ptr, I instead pass a FunPtr to the Haskell function
>>freeHaskellFunPtr into my DLL, and use this to free everything, finally
>>using it to free itself (!) which I assume should be safe. [...]
>
>
> It has been quite some time since I've worked on GHC's Adjustor.c and Hugs'
> FFI, but IIRC it is in general *not* safe to do this. On some platforms code
> is being generated dynamically for these kind of callbacks, which has already
> been freed by the time the callback returns. This might appear to work,
> depending on your processor architecture and dynamic memory management
> behaviour, but it's better not to rely on this. Perhaps the FFI spec should
> be clearer here.
I'm pretty sure this *does* work with GHC, at least on some platforms
(definitely x86 and x86_64, I'm not sure about the others). We're
careful not to require any dynamically-allocated code to run when the
callback returns.
I agree the FFI spec should be clearer here.
Cheers,
Simon
More information about the Glasgow-haskell-users
mailing list