[plt-scheme] Re: scheme_weak_reference and MZ_PRECISE_GC
On Tue, 9 Sep 2008 09:17:55 -0600 Matthew Flatt wrote:
> At Tue, 09 Sep 2008 16:40:53 +0200, David Hansen wrote:
>
>> OK, I could scheme_dont_gc_ptr() the weak box and scheme_gc_ptr_ok() the
>> box in a finalizer of the value the box holds.
>
> If I guess correctly about the situation, that wouldn't work, because
> the weak box might move even if it isn't collected. But you could put
> the weak box in an immobile box (allocated with
> scheme_malloc_immobile_box), and so on.
OK, thanks. But still pretty complicated.
>> I want to keep track of Scheme_Object*s of a custom tagged type.
>
> Do you just need a a weak hash table, where the sets of keys in the
> table can act as a list of all the non-GCed objects?
I want a mapping
<some C pointer from another lib> -> <Scheme_Object* that wraps around
the C pointer + some possible other data>.
So when an in C written proc returns a Scheme object it will use the
possibly already existing one instead of creating a new wrapper. The
reason I don't use the existing c pointer type is to have some
flexibility in what "some possible data" can be. An now it's of course
about understanding the issue as well ;-)
I think I just start understanding how this stuff work: When I
scheme_register_extension_global() the values of this mapping, will 3m
update the pointers? What would be the difference to a weak reference?
I suspect they will never get collected (not what I want).
>> Can I
>> do that from the fixup callback I pass to GC_register_traversers()?
>
> If you know when a GC starts and when it ends, then you could record
> all the pointers that are passed to the fixup function. That seems
> relatively complicated, though, and I don't think there's currently a
> way to know when a GC starts and ends.
>
>> If so, how? The documentation is a bit dense there. In case the object
>> moved, how do I get the old and new Scheme_Object*?
>
> GC_fixup_self() can do that. It's mentioned in section 3.1.1, but I
> should add an entry in the list of procedures.
Will this give me the new Scheme_Object*? That will most probably be
enough, the C pointer from the other lib is accessible from the
Scheme_Object so I can update the mapping.
David