[racket] FFI/3m and Boehm GC compatibility

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Jul 16 12:20:54 EDT 2012

At Mon, 16 Jul 2012 15:48:42 +0100, Tim Brown wrote:
> I posted this on IRC earlier today with no response:
>    "With ffi, i have a function which returns a pointer which has been
>     malloc'd using a GC_malloc (linked with my foreign library).
>    "I need this pointer to remain visible within racket (i.e. on the stack
>     or anywhere else that the CGC would find it). This is fine for
>     racketcgc (since GC_malloc is shared between my library and racket)
>     but how do i keep a pointer visible with racket3m?
>    "[if possible, without "remembering" it explicitly in my library]"
> Does anyone have any idea how to hint to the FFI that I want this reference
> kept visible?

Looking again, I think I didn't understand the question.

I think you're saying that you always call the Boehm GC's GC_malloc();
that happens to be the same as Racket's GC_malloc() with CGC, but it's
not the same in 3m. In the latter case, memory allocated with
GC_malloc() is not managed by Racket's GC, and so `_gcpointer' doesn't

If that's right, then this doesn't seem like a FFI question so much as
a Boehm GC question: how do you tell the Boehm GC that a pointer is
still live, even if it's otherwise invisible? I think the answer is
that you have to allocate immobile memory to hold the pointer, and then
use GC_add_roots() to register the pointer-holding memory.

Posted on the users mailing list.