Add configure test for garbage collector friendliness for GLib. If
authorSebastian Wilhelmi <wilhelmi@ira.uka.de>
Mon, 17 Apr 2000 13:23:27 +0000 (13:23 +0000)
committerSebastian Wilhelmi <wilhelmi@src.gnome.org>
Mon, 17 Apr 2000 13:23:27 +0000 (13:23 +0000)
2000-04-17  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>

* configure.in, acconfig.h: Add configure test for garbage
collector friendliness for GLib. If enabled, ENABLE_GC_FRIENDLY
will be defined.

* garray.c, ghash.c, glist.c, gmain.c, gmem.c, gnode.c, gqueue.c,
gslist.c, gtree.c: If ENABLE_GC_FRIENDLY is defined, NULLify all
memory released by the user, but cached by GLib. This lets a
garbage collector have a more correct view of the actually used
memory.

28 files changed:
ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
acconfig.h
configure.in
garray.c
ghash.c
glib/garray.c
glib/ghash.c
glib/glist.c
glib/gmain.c
glib/gmem.c
glib/gnode.c
glib/gqueue.c
glib/gslist.c
glib/gtree.c
glist.c
gmain.c
gmem.c
gnode.c
gqueue.c
gslist.c
gtree.c

index 0b64b6e..b646c1f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2000-04-17  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
+       * configure.in, acconfig.h: Add configure test for garbage
+       collector friendliness for GLib. If enabled, ENABLE_GC_FRIENDLY
+       will be defined.
+
+       * garray.c, ghash.c, glist.c, gmain.c, gmem.c, gnode.c, gqueue.c,
+       gslist.c, gtree.c: If ENABLE_GC_FRIENDLY is defined, NULLify all
+       memory released by the user, but cached by GLib. This lets a
+       garbage collector have a more correct view of the actually used
+       memory.
+       
        * garray.c, glib.h: Added g_(array|ptr_array|byte_array)_sized_new
        functions, that reserve a certain amount of memeory for the array
        at creation time to avoid reallocation. Fixes bug #6707 from
index 0b64b6e..b646c1f 100644 (file)
@@ -1,5 +1,15 @@
 2000-04-17  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
+       * configure.in, acconfig.h: Add configure test for garbage
+       collector friendliness for GLib. If enabled, ENABLE_GC_FRIENDLY
+       will be defined.
+
+       * garray.c, ghash.c, glist.c, gmain.c, gmem.c, gnode.c, gqueue.c,
+       gslist.c, gtree.c: If ENABLE_GC_FRIENDLY is defined, NULLify all
+       memory released by the user, but cached by GLib. This lets a
+       garbage collector have a more correct view of the actually used
+       memory.
+       
        * garray.c, glib.h: Added g_(array|ptr_array|byte_array)_sized_new
        functions, that reserve a certain amount of memeory for the array
        at creation time to avoid reallocation. Fixes bug #6707 from
index 0b64b6e..b646c1f 100644 (file)
@@ -1,5 +1,15 @@
 2000-04-17  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
+       * configure.in, acconfig.h: Add configure test for garbage
+       collector friendliness for GLib. If enabled, ENABLE_GC_FRIENDLY
+       will be defined.
+
+       * garray.c, ghash.c, glist.c, gmain.c, gmem.c, gnode.c, gqueue.c,
+       gslist.c, gtree.c: If ENABLE_GC_FRIENDLY is defined, NULLify all
+       memory released by the user, but cached by GLib. This lets a
+       garbage collector have a more correct view of the actually used
+       memory.
+       
        * garray.c, glib.h: Added g_(array|ptr_array|byte_array)_sized_new
        functions, that reserve a certain amount of memeory for the array
        at creation time to avoid reallocation. Fixes bug #6707 from
index 0b64b6e..b646c1f 100644 (file)
@@ -1,5 +1,15 @@
 2000-04-17  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
+       * configure.in, acconfig.h: Add configure test for garbage
+       collector friendliness for GLib. If enabled, ENABLE_GC_FRIENDLY
+       will be defined.
+
+       * garray.c, ghash.c, glist.c, gmain.c, gmem.c, gnode.c, gqueue.c,
+       gslist.c, gtree.c: If ENABLE_GC_FRIENDLY is defined, NULLify all
+       memory released by the user, but cached by GLib. This lets a
+       garbage collector have a more correct view of the actually used
+       memory.
+       
        * garray.c, glib.h: Added g_(array|ptr_array|byte_array)_sized_new
        functions, that reserve a certain amount of memeory for the array
        at creation time to avoid reallocation. Fixes bug #6707 from
index 0b64b6e..b646c1f 100644 (file)
@@ -1,5 +1,15 @@
 2000-04-17  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
+       * configure.in, acconfig.h: Add configure test for garbage
+       collector friendliness for GLib. If enabled, ENABLE_GC_FRIENDLY
+       will be defined.
+
+       * garray.c, ghash.c, glist.c, gmain.c, gmem.c, gnode.c, gqueue.c,
+       gslist.c, gtree.c: If ENABLE_GC_FRIENDLY is defined, NULLify all
+       memory released by the user, but cached by GLib. This lets a
+       garbage collector have a more correct view of the actually used
+       memory.
+       
        * garray.c, glib.h: Added g_(array|ptr_array|byte_array)_sized_new
        functions, that reserve a certain amount of memeory for the array
        at creation time to avoid reallocation. Fixes bug #6707 from
index 0b64b6e..b646c1f 100644 (file)
@@ -1,5 +1,15 @@
 2000-04-17  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
+       * configure.in, acconfig.h: Add configure test for garbage
+       collector friendliness for GLib. If enabled, ENABLE_GC_FRIENDLY
+       will be defined.
+
+       * garray.c, ghash.c, glist.c, gmain.c, gmem.c, gnode.c, gqueue.c,
+       gslist.c, gtree.c: If ENABLE_GC_FRIENDLY is defined, NULLify all
+       memory released by the user, but cached by GLib. This lets a
+       garbage collector have a more correct view of the actually used
+       memory.
+       
        * garray.c, glib.h: Added g_(array|ptr_array|byte_array)_sized_new
        functions, that reserve a certain amount of memeory for the array
        at creation time to avoid reallocation. Fixes bug #6707 from
index 0b64b6e..b646c1f 100644 (file)
@@ -1,5 +1,15 @@
 2000-04-17  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
+       * configure.in, acconfig.h: Add configure test for garbage
+       collector friendliness for GLib. If enabled, ENABLE_GC_FRIENDLY
+       will be defined.
+
+       * garray.c, ghash.c, glist.c, gmain.c, gmem.c, gnode.c, gqueue.c,
+       gslist.c, gtree.c: If ENABLE_GC_FRIENDLY is defined, NULLify all
+       memory released by the user, but cached by GLib. This lets a
+       garbage collector have a more correct view of the actually used
+       memory.
+       
        * garray.c, glib.h: Added g_(array|ptr_array|byte_array)_sized_new
        functions, that reserve a certain amount of memeory for the array
        at creation time to avoid reallocation. Fixes bug #6707 from
index 0b64b6e..b646c1f 100644 (file)
@@ -1,5 +1,15 @@
 2000-04-17  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
+       * configure.in, acconfig.h: Add configure test for garbage
+       collector friendliness for GLib. If enabled, ENABLE_GC_FRIENDLY
+       will be defined.
+
+       * garray.c, ghash.c, glist.c, gmain.c, gmem.c, gnode.c, gqueue.c,
+       gslist.c, gtree.c: If ENABLE_GC_FRIENDLY is defined, NULLify all
+       memory released by the user, but cached by GLib. This lets a
+       garbage collector have a more correct view of the actually used
+       memory.
+       
        * garray.c, glib.h: Added g_(array|ptr_array|byte_array)_sized_new
        functions, that reserve a certain amount of memeory for the array
        at creation time to avoid reallocation. Fixes bug #6707 from
index d73fc50..70d0114 100644 (file)
@@ -36,6 +36,7 @@
 
 #undef ENABLE_MEM_CHECK
 #undef ENABLE_MEM_PROFILE
+#undef ENABLE_GC_FRIENDLY
 
 #undef REALLOC_0_WORKS
 
index b1a074a..8f95f92 100644 (file)
@@ -105,6 +105,7 @@ AC_ARG_ENABLE(debug, [  --enable-debug=[no/minimum/yes] turn on debugging [defau
 AC_ARG_ENABLE(msg-prefix, [  --enable-msg-prefix     turn on program name and PID prefixing of messages and warnings],,enable_msg_prefix=no)
 AC_ARG_ENABLE(mem_check, [  --enable-mem-check      turn on malloc/free sanity checking [default=no]],,enable_mem_check=no)
 AC_ARG_ENABLE(mem_profile, [  --enable-mem-profile    turn on malloc profiling atexit [default=no]],,enable_mem_profile=no)
+AC_ARG_ENABLE(gc_friendly, [  --enable-gc-friendly    turn on garbage collector friendliness [default=no]],,enable_gc_friendly=no)
 AC_ARG_ENABLE(ansi, [  --enable-ansi           turn on strict ansi [default=no]],
                    , enable_ansi=no)
 AC_ARG_ENABLE(threads, [  --enable-threads        turn on basic thread support [default=yes]
@@ -132,6 +133,15 @@ else
   AC_MSG_RESULT(no)
 fi
 
+AC_MSG_CHECKING(whether to enable garbage collector friendliness)
+if test "x$enable_gc_friendly" = "xyes"; then
+  AC_DEFINE(ENABLE_GC_FRIENDLY, 1)
+  AC_SUBST(ENABLE_GC_FRIENDLY)
+  AC_MSG_RESULT(yes)
+else
+  AC_MSG_RESULT(no)
+fi
+
 if test "x$enable_debug" = "xyes"; then
   test "$cflags_set" = set || CFLAGS="$CFLAGS -g"
   GLIB_DEBUG_FLAGS="-DG_ENABLE_DEBUG"
index 2769c25..e90dcd4 100644 (file)
--- a/garray.c
+++ b/garray.c
@@ -48,11 +48,11 @@ struct _GRealArray
 
 #define g_array_elt_len(array,i) ((array)->elt_size * (i))
 #define g_array_elt_pos(array,i) ((array)->data + g_array_elt_len((array),(i)))
-#define g_array_elt_zero(array, pos, len)                               \
+#define g_array_elt_zero(array, pos, len)                              \
   (memset (g_array_elt_pos ((array), pos), 0,  g_array_elt_len ((array), len)))
-#define g_array_zero_terminate(array) G_STMT_START{                     \
-  if ((array)->zero_terminated)                                         \
-    g_array_elt_zero ((array), (array)->len, 1);                        \
+#define g_array_zero_terminate(array) G_STMT_START{                    \
+  if ((array)->zero_terminated)                                                \
+    g_array_elt_zero ((array), (array)->len, 1);                       \
 }G_STMT_END
 
 static gint g_nearest_pow        (gint        num);
@@ -182,14 +182,17 @@ g_array_set_size (GArray *farray,
                  guint   length)
 {
   GRealArray *array = (GRealArray*) farray;
-
-  if (array->len < length)
+  if (length > array->len)
     {
       g_array_maybe_expand (array, length - array->len);
       
       if (array->clear)
        g_array_elt_zero (array, array->len, length - array->len);
     }
+#ifdef ENABLE_GC_FRIENDLY  
+  else if (length < array->len)
+    g_array_elt_zero (array, length, array->len - length);
+#endif /* ENABLE_GC_FRIENDLY */  
   
   array->len = length;
   
@@ -215,7 +218,11 @@ g_array_remove_index (GArray* farray,
   
   array->len -= 1;
 
+#ifdef ENABLE_GC_FRIENDLY
+  g_array_elt_zero (array, array->len, 1);
+#else /* !ENABLE_GC_FRIENDLY */
   g_array_zero_terminate (array);
+#endif /* ENABLE_GC_FRIENDLY */  
 
   return farray;
 }
@@ -237,7 +244,11 @@ g_array_remove_index_fast (GArray* farray,
   
   array->len -= 1;
 
+#ifdef ENABLE_GC_FRIENDLY
+  g_array_elt_zero (array, array->len, 1);
+#else /* !ENABLE_GC_FRIENDLY */
   g_array_zero_terminate (array);
+#endif /* ENABLE_GC_FRIENDLY */  
 
   return farray;
 }
@@ -262,10 +273,16 @@ g_array_maybe_expand (GRealArray *array,
 
   if (want_alloc > array->alloc)
     {
-      array->alloc = g_nearest_pow (want_alloc);
-      array->alloc = MAX (array->alloc, MIN_ARRAY_SIZE);
+      want_alloc = g_nearest_pow (want_alloc);
+      want_alloc = MAX (want_alloc, MIN_ARRAY_SIZE);
 
-      array->data = g_realloc (array->data, array->alloc);
+      array->data = g_realloc (array->data, want_alloc);
+
+#ifdef ENABLE_GC_FRIENDLY
+      memset (array->data + array->alloc, 0, want_alloc - array->alloc);
+#endif /* ENABLE_GC_FRIENDLY */
+
+      array->alloc = want_alloc;
     }
 }
 
@@ -338,9 +355,16 @@ g_ptr_array_maybe_expand (GRealPtrArray *array,
 {
   if ((array->len + len) > array->alloc)
     {
+#ifdef ENABLE_GC_FRIENDLY
+      guint old_alloc = array->alloc;
+#endif /* ENABLE_GC_FRIENDLY */
       array->alloc = g_nearest_pow (array->len + len);
       array->alloc = MAX (array->alloc, MIN_ARRAY_SIZE);
       array->pdata = g_realloc (array->pdata, sizeof(gpointer) * array->alloc);
+#ifdef ENABLE_GC_FRIENDLY
+      for ( ; old_alloc < array->alloc; old_alloc++)
+       array->pdata [old_alloc] = NULL;
+#endif /* ENABLE_GC_FRIENDLY */
     }
 }
 
@@ -365,6 +389,14 @@ g_ptr_array_set_size  (GPtrArray   *farray,
       for (i = array->len; i < length; i++)
        array->pdata[i] = NULL;
     }
+#ifdef ENABLE_GC_FRIENDLY  
+  else if (length < array->len)
+    {
+      int i;
+      for (i = length; i < array->len; i++)
+       array->pdata[i] = NULL;
+    }
+#endif /* ENABLE_GC_FRIENDLY */  
 
   array->len = length;
 }
@@ -388,6 +420,10 @@ g_ptr_array_remove_index (GPtrArray* farray,
   
   array->len -= 1;
 
+#ifdef ENABLE_GC_FRIENDLY  
+  array->pdata[array->len] = NULL;
+#endif /* ENABLE_GC_FRIENDLY */  
+
   return result;
 }
 
@@ -409,6 +445,10 @@ g_ptr_array_remove_index_fast (GPtrArray* farray,
 
   array->len -= 1;
 
+#ifdef ENABLE_GC_FRIENDLY  
+  array->pdata[array->len] = NULL;
+#endif /* ENABLE_GC_FRIENDLY */  
+
   return result;
 }
 
diff --git a/ghash.c b/ghash.c
index 331a1ab..adc3b62 100644 (file)
--- a/ghash.c
+++ b/ghash.c
@@ -380,6 +380,12 @@ g_hash_node_new (gpointer key,
 static void
 g_hash_node_destroy (GHashNode *hash_node)
 {
+
+#ifdef ENABLE_GC_FRIENDLY
+  hash_node->key = NULL;
+  hash_node->value = NULL;
+#endif /* ENABLE_GC_FRIENDLY */
+
   G_LOCK (g_hash_global);
   hash_node->next = node_free_list;
   node_free_list = hash_node;
@@ -394,8 +400,19 @@ g_hash_nodes_destroy (GHashNode *hash_node)
       GHashNode *node = hash_node;
   
       while (node->next)
-        node = node->next;
-  
+       {
+#ifdef ENABLE_GC_FRIENDLY
+         node->key = NULL;
+         node->value = NULL;
+#endif /* ENABLE_GC_FRIENDLY */
+         node = node->next;
+       }
+
+#ifdef ENABLE_GC_FRIENDLY
+      node->key = NULL;
+      node->value = NULL;
+#endif /* ENABLE_GC_FRIENDLY */
       G_LOCK (g_hash_global);
       node->next = node_free_list;
       node_free_list = hash_node;
index 2769c25..e90dcd4 100644 (file)
@@ -48,11 +48,11 @@ struct _GRealArray
 
 #define g_array_elt_len(array,i) ((array)->elt_size * (i))
 #define g_array_elt_pos(array,i) ((array)->data + g_array_elt_len((array),(i)))
-#define g_array_elt_zero(array, pos, len)                               \
+#define g_array_elt_zero(array, pos, len)                              \
   (memset (g_array_elt_pos ((array), pos), 0,  g_array_elt_len ((array), len)))
-#define g_array_zero_terminate(array) G_STMT_START{                     \
-  if ((array)->zero_terminated)                                         \
-    g_array_elt_zero ((array), (array)->len, 1);                        \
+#define g_array_zero_terminate(array) G_STMT_START{                    \
+  if ((array)->zero_terminated)                                                \
+    g_array_elt_zero ((array), (array)->len, 1);                       \
 }G_STMT_END
 
 static gint g_nearest_pow        (gint        num);
@@ -182,14 +182,17 @@ g_array_set_size (GArray *farray,
                  guint   length)
 {
   GRealArray *array = (GRealArray*) farray;
-
-  if (array->len < length)
+  if (length > array->len)
     {
       g_array_maybe_expand (array, length - array->len);
       
       if (array->clear)
        g_array_elt_zero (array, array->len, length - array->len);
     }
+#ifdef ENABLE_GC_FRIENDLY  
+  else if (length < array->len)
+    g_array_elt_zero (array, length, array->len - length);
+#endif /* ENABLE_GC_FRIENDLY */  
   
   array->len = length;
   
@@ -215,7 +218,11 @@ g_array_remove_index (GArray* farray,
   
   array->len -= 1;
 
+#ifdef ENABLE_GC_FRIENDLY
+  g_array_elt_zero (array, array->len, 1);
+#else /* !ENABLE_GC_FRIENDLY */
   g_array_zero_terminate (array);
+#endif /* ENABLE_GC_FRIENDLY */  
 
   return farray;
 }
@@ -237,7 +244,11 @@ g_array_remove_index_fast (GArray* farray,
   
   array->len -= 1;
 
+#ifdef ENABLE_GC_FRIENDLY
+  g_array_elt_zero (array, array->len, 1);
+#else /* !ENABLE_GC_FRIENDLY */
   g_array_zero_terminate (array);
+#endif /* ENABLE_GC_FRIENDLY */  
 
   return farray;
 }
@@ -262,10 +273,16 @@ g_array_maybe_expand (GRealArray *array,
 
   if (want_alloc > array->alloc)
     {
-      array->alloc = g_nearest_pow (want_alloc);
-      array->alloc = MAX (array->alloc, MIN_ARRAY_SIZE);
+      want_alloc = g_nearest_pow (want_alloc);
+      want_alloc = MAX (want_alloc, MIN_ARRAY_SIZE);
 
-      array->data = g_realloc (array->data, array->alloc);
+      array->data = g_realloc (array->data, want_alloc);
+
+#ifdef ENABLE_GC_FRIENDLY
+      memset (array->data + array->alloc, 0, want_alloc - array->alloc);
+#endif /* ENABLE_GC_FRIENDLY */
+
+      array->alloc = want_alloc;
     }
 }
 
@@ -338,9 +355,16 @@ g_ptr_array_maybe_expand (GRealPtrArray *array,
 {
   if ((array->len + len) > array->alloc)
     {
+#ifdef ENABLE_GC_FRIENDLY
+      guint old_alloc = array->alloc;
+#endif /* ENABLE_GC_FRIENDLY */
       array->alloc = g_nearest_pow (array->len + len);
       array->alloc = MAX (array->alloc, MIN_ARRAY_SIZE);
       array->pdata = g_realloc (array->pdata, sizeof(gpointer) * array->alloc);
+#ifdef ENABLE_GC_FRIENDLY
+      for ( ; old_alloc < array->alloc; old_alloc++)
+       array->pdata [old_alloc] = NULL;
+#endif /* ENABLE_GC_FRIENDLY */
     }
 }
 
@@ -365,6 +389,14 @@ g_ptr_array_set_size  (GPtrArray   *farray,
       for (i = array->len; i < length; i++)
        array->pdata[i] = NULL;
     }
+#ifdef ENABLE_GC_FRIENDLY  
+  else if (length < array->len)
+    {
+      int i;
+      for (i = length; i < array->len; i++)
+       array->pdata[i] = NULL;
+    }
+#endif /* ENABLE_GC_FRIENDLY */  
 
   array->len = length;
 }
@@ -388,6 +420,10 @@ g_ptr_array_remove_index (GPtrArray* farray,
   
   array->len -= 1;
 
+#ifdef ENABLE_GC_FRIENDLY  
+  array->pdata[array->len] = NULL;
+#endif /* ENABLE_GC_FRIENDLY */  
+
   return result;
 }
 
@@ -409,6 +445,10 @@ g_ptr_array_remove_index_fast (GPtrArray* farray,
 
   array->len -= 1;
 
+#ifdef ENABLE_GC_FRIENDLY  
+  array->pdata[array->len] = NULL;
+#endif /* ENABLE_GC_FRIENDLY */  
+
   return result;
 }
 
index 331a1ab..adc3b62 100644 (file)
@@ -380,6 +380,12 @@ g_hash_node_new (gpointer key,
 static void
 g_hash_node_destroy (GHashNode *hash_node)
 {
+
+#ifdef ENABLE_GC_FRIENDLY
+  hash_node->key = NULL;
+  hash_node->value = NULL;
+#endif /* ENABLE_GC_FRIENDLY */
+
   G_LOCK (g_hash_global);
   hash_node->next = node_free_list;
   node_free_list = hash_node;
@@ -394,8 +400,19 @@ g_hash_nodes_destroy (GHashNode *hash_node)
       GHashNode *node = hash_node;
   
       while (node->next)
-        node = node->next;
-  
+       {
+#ifdef ENABLE_GC_FRIENDLY
+         node->key = NULL;
+         node->value = NULL;
+#endif /* ENABLE_GC_FRIENDLY */
+         node = node->next;
+       }
+
+#ifdef ENABLE_GC_FRIENDLY
+      node->key = NULL;
+      node->value = NULL;
+#endif /* ENABLE_GC_FRIENDLY */
       G_LOCK (g_hash_global);
       node->next = node_free_list;
       node_free_list = hash_node;
index e719e1c..2cb4a31 100644 (file)
@@ -78,7 +78,7 @@ void
 g_list_push_allocator(GAllocator *allocator)
 {
   G_LOCK (current_allocator);
-  g_list_validate_allocator ( allocator );
+  g_list_validate_allocator (allocator);
   allocator->last = current_allocator;
   current_allocator = allocator;
   G_UNLOCK (current_allocator);
@@ -151,9 +151,23 @@ g_list_free (GList *list)
 {
   if (list)
     {
+      GList *last_node = list;
+
+#ifdef ENABLE_GC_FRIENDLY
+      while (last_node->next)
+        {
+          last_node->data = NULL;
+          last_node->prev = NULL;
+          last_node = last_node->next;
+        }
+      last_node->data = NULL
+      last_node->prev = NULL
+#else /* !ENABLE_GC_FRIENDLY */
       list->data = list->next;  
+#endif /* ENABLE_GC_FRIENDLY */
+
       G_LOCK (current_allocator);
-      list->next = current_allocator->free_lists;
+      last_node->next = current_allocator->free_lists;
       current_allocator->free_lists = list;
       G_UNLOCK (current_allocator);
     }
@@ -165,6 +179,11 @@ _g_list_free_1 (GList *list)
   if (list)
     {
       list->data = NULL;  
+
+#ifdef ENABLE_GC_FRIENDLY
+      list->prev = NULL;  
+#endif /* ENABLE_GC_FRIENDLY */
+
       G_LOCK (current_allocator);
       list->next = current_allocator->free_lists;
       current_allocator->free_lists = list;
index a2ca73a..e7161c4 100644 (file)
@@ -1186,6 +1186,10 @@ g_main_remove_poll (GPollFD *fd)
          else
            poll_records = pollrec->next;
 
+#ifdef ENABLE_GC_FRIENDLY
+         pollrec->fd = NULL;  
+#endif /* ENABLE_GC_FRIENDLY */
+
          pollrec->next = poll_free_list;
          poll_free_list = pollrec;
 
index 360b02f..eaa6990 100644 (file)
@@ -648,9 +648,15 @@ g_mem_chunk_alloc (GMemChunk *mem_chunk)
         }
       else
         {
+#ifdef ENABLE_GC_FRIENDLY
+         rmem_chunk->mem_area = (GMemArea*) g_malloc0 (sizeof (GMemArea) -
+                                                       MEM_AREA_SIZE +
+                                                       rmem_chunk->area_size); 
+#else /* !ENABLE_GC_FRIENDLY */
          rmem_chunk->mem_area = (GMemArea*) g_malloc (sizeof (GMemArea) -
                                                       MEM_AREA_SIZE +
                                                       rmem_chunk->area_size);
+#endif /* ENABLE_GC_FRIENDLY */
          
          rmem_chunk->num_mem_areas += 1;
          rmem_chunk->mem_area->next = rmem_chunk->mem_areas;
@@ -715,6 +721,10 @@ g_mem_chunk_free (GMemChunk *mem_chunk,
 
   rmem_chunk = (GRealMemChunk*) mem_chunk;
   
+#ifdef ENABLE_GC_FRIENDLY
+  memset (mem, 0, rmem_chunk->atom_size);
+#endif /* ENABLE_GC_FRIENDLY */
+
   /* Don't do anything if this is an ALLOC_ONLY chunk
    */
   if (rmem_chunk->type == G_ALLOC_AND_FREE)
index 5db03c6..a21b78e 100644 (file)
@@ -82,7 +82,7 @@ void
 g_node_push_allocator (GAllocator *allocator)
 {
   G_LOCK (current_allocator);
-  g_node_validate_allocator ( allocator );
+  g_node_validate_allocator (allocator);
   allocator->last = current_allocator;
   current_allocator = allocator;
   G_UNLOCK (current_allocator);
@@ -148,6 +148,14 @@ g_nodes_free (GNode *node)
     {
       if (parent->children)
        g_nodes_free (parent->children);
+
+#ifdef ENABLE_GC_FRIENDLY
+      parent->data = NULL;
+      parent->prev = NULL;
+      parent->parent = NULL;
+      parent->children = NULL;
+#endif /* ENABLE_GC_FRIENDLY */
+
       if (parent->next)
        parent = parent->next;
       else
index 1616ea9..6338c53 100644 (file)
@@ -64,6 +64,11 @@ g_queue_free (GQueue *queue)
 
   g_list_free (queue->head);
 
+#ifdef ENABLE_GC_FRIENDLY
+  queue->head = NULL;
+  queue->tail = NULL;
+#endif /* ENABLE_GC_FRIENDLY */
+
   G_LOCK (queue_memchunk);
   g_trash_stack_push (&free_queue_nodes, queue);
   G_UNLOCK (queue_memchunk);
index 2f01673..bcb481f 100644 (file)
@@ -151,9 +151,21 @@ g_slist_free (GSList *list)
 {
   if (list)
     {
-      list->data = list->next;
+      GSList *last_node = list;
+  
+#ifdef ENABLE_GC_FRIENDLY
+      while (last_node->next)
+       {
+         last_node->data = NULL;
+         last_node = last_node->next;
+       }
+      last_node->data = NULL
+#else /* !ENABLE_GC_FRIENDLY */
+      list->data = list->next;  
+#endif /* ENABLE_GC_FRIENDLY */
+       
       G_LOCK (current_allocator);
-      list->next = current_allocator->free_lists;
+      last_node->next = current_allocator->free_lists;
       current_allocator->free_lists = list;
       G_UNLOCK (current_allocator);
     }
index 557aa27..c2f97de 100644 (file)
@@ -135,6 +135,13 @@ g_tree_node_destroy (GTreeNode *node)
     {
       g_tree_node_destroy (node->right);
       g_tree_node_destroy (node->left);
+
+#ifdef ENABLE_GC_FRIENDLY
+      node->left = NULL;
+      node->key = NULL;
+      node->value = NULL;
+#endif /* ENABLE_GC_FRIENDLY */
+
       G_LOCK (g_tree_global);
       node->right = node_free_list;
       node_free_list = node;
@@ -396,6 +403,12 @@ g_tree_node_remove (GTreeNode    *node,
          node = g_tree_node_restore_right_balance (new_root, old_balance);
        }
 
+#ifdef ENABLE_GC_FRIENDLY
+      garbage->left = NULL;
+      garbage->key = NULL;
+      garbage->value = NULL;
+#endif /* ENABLE_GC_FRIENDLY */
+
       G_LOCK (g_tree_global);
       garbage->right = node_free_list;
       node_free_list = garbage;
diff --git a/glist.c b/glist.c
index e719e1c..2cb4a31 100644 (file)
--- a/glist.c
+++ b/glist.c
@@ -78,7 +78,7 @@ void
 g_list_push_allocator(GAllocator *allocator)
 {
   G_LOCK (current_allocator);
-  g_list_validate_allocator ( allocator );
+  g_list_validate_allocator (allocator);
   allocator->last = current_allocator;
   current_allocator = allocator;
   G_UNLOCK (current_allocator);
@@ -151,9 +151,23 @@ g_list_free (GList *list)
 {
   if (list)
     {
+      GList *last_node = list;
+
+#ifdef ENABLE_GC_FRIENDLY
+      while (last_node->next)
+        {
+          last_node->data = NULL;
+          last_node->prev = NULL;
+          last_node = last_node->next;
+        }
+      last_node->data = NULL
+      last_node->prev = NULL
+#else /* !ENABLE_GC_FRIENDLY */
       list->data = list->next;  
+#endif /* ENABLE_GC_FRIENDLY */
+
       G_LOCK (current_allocator);
-      list->next = current_allocator->free_lists;
+      last_node->next = current_allocator->free_lists;
       current_allocator->free_lists = list;
       G_UNLOCK (current_allocator);
     }
@@ -165,6 +179,11 @@ _g_list_free_1 (GList *list)
   if (list)
     {
       list->data = NULL;  
+
+#ifdef ENABLE_GC_FRIENDLY
+      list->prev = NULL;  
+#endif /* ENABLE_GC_FRIENDLY */
+
       G_LOCK (current_allocator);
       list->next = current_allocator->free_lists;
       current_allocator->free_lists = list;
diff --git a/gmain.c b/gmain.c
index a2ca73a..e7161c4 100644 (file)
--- a/gmain.c
+++ b/gmain.c
@@ -1186,6 +1186,10 @@ g_main_remove_poll (GPollFD *fd)
          else
            poll_records = pollrec->next;
 
+#ifdef ENABLE_GC_FRIENDLY
+         pollrec->fd = NULL;  
+#endif /* ENABLE_GC_FRIENDLY */
+
          pollrec->next = poll_free_list;
          poll_free_list = pollrec;
 
diff --git a/gmem.c b/gmem.c
index 360b02f..eaa6990 100644 (file)
--- a/gmem.c
+++ b/gmem.c
@@ -648,9 +648,15 @@ g_mem_chunk_alloc (GMemChunk *mem_chunk)
         }
       else
         {
+#ifdef ENABLE_GC_FRIENDLY
+         rmem_chunk->mem_area = (GMemArea*) g_malloc0 (sizeof (GMemArea) -
+                                                       MEM_AREA_SIZE +
+                                                       rmem_chunk->area_size); 
+#else /* !ENABLE_GC_FRIENDLY */
          rmem_chunk->mem_area = (GMemArea*) g_malloc (sizeof (GMemArea) -
                                                       MEM_AREA_SIZE +
                                                       rmem_chunk->area_size);
+#endif /* ENABLE_GC_FRIENDLY */
          
          rmem_chunk->num_mem_areas += 1;
          rmem_chunk->mem_area->next = rmem_chunk->mem_areas;
@@ -715,6 +721,10 @@ g_mem_chunk_free (GMemChunk *mem_chunk,
 
   rmem_chunk = (GRealMemChunk*) mem_chunk;
   
+#ifdef ENABLE_GC_FRIENDLY
+  memset (mem, 0, rmem_chunk->atom_size);
+#endif /* ENABLE_GC_FRIENDLY */
+
   /* Don't do anything if this is an ALLOC_ONLY chunk
    */
   if (rmem_chunk->type == G_ALLOC_AND_FREE)
diff --git a/gnode.c b/gnode.c
index 5db03c6..a21b78e 100644 (file)
--- a/gnode.c
+++ b/gnode.c
@@ -82,7 +82,7 @@ void
 g_node_push_allocator (GAllocator *allocator)
 {
   G_LOCK (current_allocator);
-  g_node_validate_allocator ( allocator );
+  g_node_validate_allocator (allocator);
   allocator->last = current_allocator;
   current_allocator = allocator;
   G_UNLOCK (current_allocator);
@@ -148,6 +148,14 @@ g_nodes_free (GNode *node)
     {
       if (parent->children)
        g_nodes_free (parent->children);
+
+#ifdef ENABLE_GC_FRIENDLY
+      parent->data = NULL;
+      parent->prev = NULL;
+      parent->parent = NULL;
+      parent->children = NULL;
+#endif /* ENABLE_GC_FRIENDLY */
+
       if (parent->next)
        parent = parent->next;
       else
index 1616ea9..6338c53 100644 (file)
--- a/gqueue.c
+++ b/gqueue.c
@@ -64,6 +64,11 @@ g_queue_free (GQueue *queue)
 
   g_list_free (queue->head);
 
+#ifdef ENABLE_GC_FRIENDLY
+  queue->head = NULL;
+  queue->tail = NULL;
+#endif /* ENABLE_GC_FRIENDLY */
+
   G_LOCK (queue_memchunk);
   g_trash_stack_push (&free_queue_nodes, queue);
   G_UNLOCK (queue_memchunk);
index 2f01673..bcb481f 100644 (file)
--- a/gslist.c
+++ b/gslist.c
@@ -151,9 +151,21 @@ g_slist_free (GSList *list)
 {
   if (list)
     {
-      list->data = list->next;
+      GSList *last_node = list;
+  
+#ifdef ENABLE_GC_FRIENDLY
+      while (last_node->next)
+       {
+         last_node->data = NULL;
+         last_node = last_node->next;
+       }
+      last_node->data = NULL
+#else /* !ENABLE_GC_FRIENDLY */
+      list->data = list->next;  
+#endif /* ENABLE_GC_FRIENDLY */
+       
       G_LOCK (current_allocator);
-      list->next = current_allocator->free_lists;
+      last_node->next = current_allocator->free_lists;
       current_allocator->free_lists = list;
       G_UNLOCK (current_allocator);
     }
diff --git a/gtree.c b/gtree.c
index 557aa27..c2f97de 100644 (file)
--- a/gtree.c
+++ b/gtree.c
@@ -135,6 +135,13 @@ g_tree_node_destroy (GTreeNode *node)
     {
       g_tree_node_destroy (node->right);
       g_tree_node_destroy (node->left);
+
+#ifdef ENABLE_GC_FRIENDLY
+      node->left = NULL;
+      node->key = NULL;
+      node->value = NULL;
+#endif /* ENABLE_GC_FRIENDLY */
+
       G_LOCK (g_tree_global);
       node->right = node_free_list;
       node_free_list = node;
@@ -396,6 +403,12 @@ g_tree_node_remove (GTreeNode    *node,
          node = g_tree_node_restore_right_balance (new_root, old_balance);
        }
 
+#ifdef ENABLE_GC_FRIENDLY
+      garbage->left = NULL;
+      garbage->key = NULL;
+      garbage->value = NULL;
+#endif /* ENABLE_GC_FRIENDLY */
+
       G_LOCK (g_tree_global);
       garbage->right = node_free_list;
       node_free_list = garbage;