[Gc] Re: gc_typed.h allocation incompatible with GC_clear_roots()?

Henning Makholm Henning at octoshape.com
Wed Feb 6 10:42:58 PST 2008


I wrote:

> In particular, there does not seem to be any general way for a
> client program that uses GC_clear_roots() to re-add GC-internal
> roots such as GC_ext_descriptors (indeed, if there are more than
> this one, the linker might choose to scatter them all across the
> data section).

On further investigation I have discovered GC_push_gc_structures(),
which is clearly the place to handle this.

The attached patch against gc-7.1alpha2-revised.tar.gz ought to
fix (but I have not tested it; beware of typos).

--
Henning Makholm
OctoShape ApS
-------------- next part --------------
diff -ur gc-7.1alpha2old/include/private/gc_priv.h gc-7.1alpha2/include/private/gc_priv.h
--- gc-7.1alpha2old/include/private/gc_priv.h	2008-01-08 20:16:17.000000000 +0100
+++ gc-7.1alpha2/include/private/gc_priv.h	2008-02-06 19:36:42.917662400 +0100
@@ -1400,6 +1400,9 @@
 #	ifdef THREADS
 	  extern void GC_push_thread_structures (void);
 #	endif
+	extern void (*GC_push_typed_structures) (void);
+			/* A pointer such that we can avoid linking in	*/
+			/* the typed allocation support if unused.	*/
 extern void (*GC_start_call_back) (void);
   			/* Called at start of full collections.		*/
   			/* Not called if 0.  Called with allocation 	*/
diff -ur gc-7.1alpha2old/mark_rts.c gc-7.1alpha2/mark_rts.c
--- gc-7.1alpha2old/mark_rts.c	2007-06-09 03:26:48.000000000 +0200
+++ gc-7.1alpha2/mark_rts.c	2008-02-06 19:31:33.368806300 +0100
@@ -511,6 +511,8 @@
 #   endif /* !THREADS */
 }
 
+void (*GC_push_typed_structures) (void) = NULL;
+
 /*
  * Push GC internal roots.  Only called if there is some reason to believe
  * these would not otherwise get registered.
@@ -521,6 +523,8 @@
 #   if defined(THREADS)
       GC_push_thread_structures();
 #   endif
+    if( GC_push_typed_structures )
+      GC_push_typed_structures();
 }
 
 #ifdef THREAD_LOCAL_ALLOC
diff -ur gc-7.1alpha2old/typd_mlc.c gc-7.1alpha2/typd_mlc.c
--- gc-7.1alpha2old/typd_mlc.c	2007-06-06 22:37:13.000000000 +0200
+++ gc-7.1alpha2/typd_mlc.c	2008-02-06 19:35:34.932852300 +0100
@@ -97,6 +97,11 @@
 int GC_typed_mark_proc_index;	/* Indices of my mark		*/
 int GC_array_mark_proc_index;	/* procedures.			*/
 
+static void GC_push_typed_structures_proc (void)
+{
+  GC_push_all((ptr_t)&GC_ext_descriptors, (ptr_t)&GC_ext_descriptors + sizeof(word));
+}
+
 /* Add a multiword bitmap to GC_ext_descriptors arrays.  Return	*/
 /* starting index.						*/
 /* Returns -1 on failure.					*/
@@ -118,6 +123,7 @@
     	
     	UNLOCK();
     	if (ed_size == 0) {
+    	    GC_push_typed_structures = GC_push_typed_structures_proc;
     	    new_size = ED_INITIAL_SIZE;
     	} else {
     	    new_size = 2 * ed_size;


More information about the Gc mailing list