Re: [Gc] [PATCH] Allow registration of disappearing links on non-heapobjects
ivmai at mail.ru
Sat Jan 31 11:24:30 PST 2009
ludo at gnu.org (Ludovic CourtХs) wrote:
> In 7.1, registering disappearing links on non-heap objects leads to a
> segmentation fault as illustrated with this program:
> GC_GENERAL_REGISTER_DISAPPEARING_LINK (&link, (void *) &foo);
> GC_gcollect (); /* <-- triggers the segfault */
> The attached patch fixes the problem. However, I'm not sure whether
> that behavior was actually on purpose; if it was, it should be
> documented rather than patched. (I haven't checked whether this area
> has changed in CVS.)
This is not a bug, it's the known behavior - see the comment for GC_general_register_disappearing_link() in gc.h: "Obj MUST be a pointer to the first word of an object we ALLOCATED".
I fact, I ran into this problem too - see https://www.hpl.hp.com/hosted/linux/mail-archives/gc/2008-October/002400.html.
This had 2 consequences:
- for GC: addition of GC_ASSERT clause to GC_general_register_disappearing_link();
- for me: I added GC_base(obj) != NULL check before calling GC_general_register_disappearing_link() where obj could be a non-heap one.
So, Your patch is not needed now (and it's not quite correct) - simply get the latest CVS snapshot (or my tarball from the previous post) and compile GC with GC_ASSERTIONS (and You'd get assertion in the right place ;).
PS. GC_register_finalizer_...() allows non-heap objects (it simply ignores such ones) and it's documented in "gc.h".
More information about the Gc