[Gc] GC_DEBUG breaks finalisation.

S M Ryan wyrmwif at rawbw.com
Thu Feb 15 01:52:08 PST 2007

In finalize.c
void GC_finalize()
         real_ptr = (ptr_t)REVEAL_POINTER(curr_fo -> fo_hidden_base);

is the wrong real pointer if GC_DEBUG is defined.

Replacing GC_is_marked(real_ptr) with GC_is_marked(GC_base(real_ptr))
and GC_set_mark_bit(real_ptr) with GC_set_mark_bit(GC_base(real_ptr))

appears to work.

Test case:

#include "gc.h"
#include <stdio.h>

static void delete(void *obj, void *client_data) {
	fprintf(stderr,"delete val = %p\n", obj);

static void work(void) {
	GC_finalization_proc ofn; void *ocd;
	int *a = GC_MALLOC(sizeof(int)); fprintf(stderr,"create a %p = %p 
	int *b = GC_MALLOC(sizeof(int)); fprintf(stderr,"create b %p = %p 
	fprintf(stderr,"before GC_gcollect\n");
	fprintf(stderr,"after GC_gcollect\n");

int main(int N,char **P) {
	return 0;

/ cc -Igc6.8/include main.c gc6.8/.libs/libgc.a; a.out
create a 0xbffff7d0 = 0x6dff8
create b 0xbffff7d4 = 0x6dfe8
before GC_gcollect
after GC_gcollect
/ cc -Igc6.8/include main.c gc6.8/.libs/libgc.a -DGC_DEBUG; a.out
create a 0xbffff7d0 = 0x6dfe8
create b 0xbffff7d4 = 0x6dfd0
before GC_gcollect
delete val = 0x6dfe8
delete val = 0x6dfd0
after GC_gcollect

More information about the Gc mailing list