Introduce scm_i_marking to detect when GC mark bits are touched
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Sat, 16 Aug 2008 14:57:27 +0000 (11:57 -0300)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sat, 16 Aug 2008 16:21:42 +0000 (13:21 -0300)
outside of marking stage.

libguile/gc-mark.c
libguile/gc.h
libguile/private-gc.h

index 77f3ec2..9fcf205 100644 (file)
@@ -73,6 +73,7 @@ scm_mark_all (void)
   long j;
   int loops;
 
+  scm_i_marking = 1;
   scm_i_init_weak_vectors_for_gc ();
   scm_i_init_guardians_for_gc ();
   
@@ -139,8 +140,6 @@ scm_mark_all (void)
       break;
     }
 
-  /* fprintf (stderr, "%d loops\n", loops); */
-
   /* Remove all unmarked entries from the weak vectors.
    */
   scm_i_remove_weaks_from_weak_vectors ();
@@ -148,6 +147,7 @@ scm_mark_all (void)
   /* Bring hashtables upto date.
    */
   scm_i_scan_weak_hashtables ();
+  scm_i_marking = 0;
 }
 
 /* {Mark/Sweep}
@@ -169,6 +169,12 @@ scm_gc_mark (SCM ptr)
   scm_gc_mark_dependencies (ptr);
 }
 
+void
+ensure_marking (void)
+{
+  assert (scm_i_marking);
+}
+
 /*
 
 Mark the dependencies of an object.
index 05412bc..939f800 100644 (file)
@@ -155,6 +155,8 @@ typedef unsigned long scm_t_c_bvec_long;
 
 /* testing and changing GC marks */
 #define SCM_GC_MARK_P(x)   SCM_GC_CELL_GET_BIT (x)
+
+void ensure_marking(void);
 #define SCM_SET_GC_MARK(x) SCM_GC_CELL_SET_BIT (x)
 #define SCM_CLEAR_GC_MARK(x) SCM_GC_CELL_CLEAR_BIT (x)
 
index 7180f2b..26e980c 100644 (file)
@@ -191,6 +191,11 @@ int scm_i_gc_grow_heap_p (scm_t_cell_type_statistics * freelist);
 /*
   gc-mark
  */
+
+/* this can be used to ensure that set/clear gc marks only happen when
+   allowed. */
+int scm_i_marking;
+
 void scm_mark_all (void);
 
 /*