From 8c90d7766b1708a8bcb3cb96988b6b7fc92c2e59 Mon Sep 17 00:00:00 2001 From: Sebastian Wilhelmi Date: Mon, 17 Apr 2000 13:23:27 +0000 Subject: [PATCH] Add configure test for garbage collector friendliness for GLib. If 2000-04-17 Sebastian Wilhelmi * 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. --- ChangeLog | 10 ++++++++ ChangeLog.pre-2-0 | 10 ++++++++ ChangeLog.pre-2-10 | 10 ++++++++ ChangeLog.pre-2-12 | 10 ++++++++ ChangeLog.pre-2-2 | 10 ++++++++ ChangeLog.pre-2-4 | 10 ++++++++ ChangeLog.pre-2-6 | 10 ++++++++ ChangeLog.pre-2-8 | 10 ++++++++ acconfig.h | 1 + configure.in | 10 ++++++++ garray.c | 58 +++++++++++++++++++++++++++++++++++++++------- ghash.c | 21 +++++++++++++++-- glib/garray.c | 58 +++++++++++++++++++++++++++++++++++++++------- glib/ghash.c | 21 +++++++++++++++-- glib/glist.c | 23 ++++++++++++++++-- glib/gmain.c | 4 ++++ glib/gmem.c | 10 ++++++++ glib/gnode.c | 10 +++++++- glib/gqueue.c | 5 ++++ glib/gslist.c | 16 +++++++++++-- glib/gtree.c | 13 +++++++++++ glist.c | 23 ++++++++++++++++-- gmain.c | 4 ++++ gmem.c | 10 ++++++++ gnode.c | 10 +++++++- gqueue.c | 5 ++++ gslist.c | 16 +++++++++++-- gtree.c | 13 +++++++++++ 28 files changed, 379 insertions(+), 32 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0b64b6e73..b646c1f33 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2000-04-17 Sebastian Wilhelmi + * 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 diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 0b64b6e73..b646c1f33 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,5 +1,15 @@ 2000-04-17 Sebastian Wilhelmi + * 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 diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 0b64b6e73..b646c1f33 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,5 +1,15 @@ 2000-04-17 Sebastian Wilhelmi + * 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 diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 0b64b6e73..b646c1f33 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,5 +1,15 @@ 2000-04-17 Sebastian Wilhelmi + * 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 diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 0b64b6e73..b646c1f33 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,5 +1,15 @@ 2000-04-17 Sebastian Wilhelmi + * 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 diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 0b64b6e73..b646c1f33 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,5 +1,15 @@ 2000-04-17 Sebastian Wilhelmi + * 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 diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 0b64b6e73..b646c1f33 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,5 +1,15 @@ 2000-04-17 Sebastian Wilhelmi + * 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 diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 0b64b6e73..b646c1f33 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,5 +1,15 @@ 2000-04-17 Sebastian Wilhelmi + * 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 diff --git a/acconfig.h b/acconfig.h index d73fc50a0..70d0114e1 100644 --- a/acconfig.h +++ b/acconfig.h @@ -36,6 +36,7 @@ #undef ENABLE_MEM_CHECK #undef ENABLE_MEM_PROFILE +#undef ENABLE_GC_FRIENDLY #undef REALLOC_0_WORKS diff --git a/configure.in b/configure.in index b1a074acc..8f95f92aa 100644 --- a/configure.in +++ b/configure.in @@ -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" diff --git a/garray.c b/garray.c index 2769c2588..e90dcd429 100644 --- 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 331a1ab2d..adc3b620a 100644 --- 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; diff --git a/glib/garray.c b/glib/garray.c index 2769c2588..e90dcd429 100644 --- a/glib/garray.c +++ b/glib/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/glib/ghash.c b/glib/ghash.c index 331a1ab2d..adc3b620a 100644 --- a/glib/ghash.c +++ b/glib/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; diff --git a/glib/glist.c b/glib/glist.c index e719e1c9e..2cb4a31b0 100644 --- a/glib/glist.c +++ b/glib/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/glib/gmain.c b/glib/gmain.c index a2ca73a1c..e7161c43c 100644 --- a/glib/gmain.c +++ b/glib/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/glib/gmem.c b/glib/gmem.c index 360b02f1c..eaa699020 100644 --- a/glib/gmem.c +++ b/glib/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/glib/gnode.c b/glib/gnode.c index 5db03c639..a21b78e4d 100644 --- a/glib/gnode.c +++ b/glib/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 diff --git a/glib/gqueue.c b/glib/gqueue.c index 1616ea9a1..6338c5375 100644 --- a/glib/gqueue.c +++ b/glib/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); diff --git a/glib/gslist.c b/glib/gslist.c index 2f01673b0..bcb481f05 100644 --- a/glib/gslist.c +++ b/glib/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/glib/gtree.c b/glib/gtree.c index 557aa2719..c2f97deaa 100644 --- a/glib/gtree.c +++ b/glib/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; diff --git a/glist.c b/glist.c index e719e1c9e..2cb4a31b0 100644 --- 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 a2ca73a1c..e7161c43c 100644 --- 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 360b02f1c..eaa699020 100644 --- 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 5db03c639..a21b78e4d 100644 --- 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 diff --git a/gqueue.c b/gqueue.c index 1616ea9a1..6338c5375 100644 --- 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); diff --git a/gslist.c b/gslist.c index 2f01673b0..bcb481f05 100644 --- 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 557aa2719..c2f97deaa 100644 --- 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;