GHCI/FFI/GMP/Me madness

Remi Turk buran at xs4all.nl
Mon Aug 9 11:57:14 EDT 2004


On Sun, Aug 08, 2004 at 07:34:04AM -0700, Sigbjorn Finne wrote:
> Hi,
> 
> please be aware that the RTS uses GMP as well, and upon
> initialisation it sets GMP's 'memory functions' to allocate memory
> from the RTS' heap. So, in the code below, the global variable
> 'p' will end up having components pointing into the heap.
> Which is fine, until a GC occurs and the pointed-to
> GMP allocated value is eventually stomped on by the storage
> manager for some other purpose.
> 
> I'm _guessing_ that's the reason for the behaviour you're seeing.

Hm, I _was_ aware of mp_set_memory_functions being used by the RTS.
I've seen it often enough in ltrace's ;)
It does indeed sound rather plausible (and making big allocations
and such does indeed cause it to happen earlier).

At which point my next question is: what now? I don't feel really
confident about my GHC-hacking skills (huh? skills? where? ;) so
does that mean I'm out of luck?
*looks* Am I correct that I'd have to copy any GMP-allocated
memory to my own memory before returning from C and vice-versa?
I hope not :(

Happy hacking,
Remi "3212th unfinished project" Turk

-- 
Nobody can be exactly like me. Even I have trouble doing it.


More information about the Glasgow-haskell-users mailing list