[racket] FFI/3m and Boehm GC compatibility

From: Tim Brown (tim.brown at cityc.co.uk)
Date: Mon Jul 16 12:33:23 EDT 2012

Matthew Flatt wrote:
> Looking again, I think I didn't understand the question.

Thanks for taking the time to look again. Yes, this second time, you do
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
> help.

That's right -- racketcgc is by far the friendliest environment for this.

> 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.

As I suspected :-(
Which leaves me the options of either:
   * doing this using an FFI call and writing wrappers in racket to manage
     pointer visibility
   * extending my foreign library to do this (I have done this in the past
     with a GC_malloc_uncollectable'd pointer to my GC_malloc'd pointer --
     which keeps life simpler)

In any case, I will need to invisibleise the pointer when it is no
longer in use by racket (i.e. "legitimately" collectable). What would be
the best way/hook to detect the pointers' end-of-life?

Regards,

Tim

-- 
Tim Brown <tim.brown at cityc.co.uk>  | City Computing Limited            |
T: +44 20 8770 2110                | City House, Sutton Park Road      |
F: +44 20 8770 2130                | Sutton, Surrey, SM1 2AE, GB       |
-----------------------------------------------------------------------|
BEAUTY:  What's in your eye when you have a bee in your hand           |
-----------------------------------------------------------------------'
City Computing Limited registered in London No. 1767817.
Registered Office: City House, Sutton Park Road, Sutton, Surrey, SM1 2AE
VAT number 372 8290 34.

Posted on the users mailing list.