[Gc] GC_DEBUG breaks finalisation.

Boehm, Hans hans.boehm at hp.com
Thu Feb 15 11:35:55 PST 2007


Please use GC_REGISTER_FINALIZER instead of GC_register_finalizer.  I
think that should fix your problem.

Hans 

> -----Original Message-----
> From: gc-bounces at napali.hpl.hp.com 
> [mailto:gc-bounces at napali.hpl.hp.com] On Behalf Of S M Ryan
> Sent: Thursday, February 15, 2007 1:52 AM
> To: gc at napali.hpl.hp.com
> Subject: [Gc] GC_DEBUG breaks finalisation.
> 
> 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 \n",&a,a);
> 	GC_register_finalizer(a,delete,0,&ofn,&ocd);
> 	int *b = GC_MALLOC(sizeof(int)); fprintf(stderr,"create 
> b %p = %p \n",&b,b);
> 	GC_register_finalizer(b,delete,0,&ofn,&ocd);
> 	fprintf(stderr,"before GC_gcollect\n");
> 	GC_gcollect();
> 	fprintf(stderr,"after GC_gcollect\n");
> }
> 
> int main(int N,char **P) {
> 	GC_init();
> 	work();
> 	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
> 
> 
> _______________________________________________
> Gc mailing list
> Gc at linux.hpl.hp.com
> http://www.hpl.hp.com/hosted/linux/mail-archives/gc/
> 



More information about the Gc mailing list