From 5aec3cf4078f773903807677e8142a3ded337404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Sat, 28 Feb 2009 16:27:19 +0100 Subject: [PATCH] Add `DEBUG_GUARDIANS' macro for guardian finalization debugging. * libguile/guardians.c (finalize_guarded): Use `#ifdef DEBUG_GUARDIANS' instead of `#if 0'. Add " guardian for %p vanished\n" debugging statement. --- libguile/guardians.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/libguile/guardians.c b/libguile/guardians.c index 43edf818d..73730fc45 100644 --- a/libguile/guardians.c +++ b/libguile/guardians.c @@ -37,10 +37,13 @@ * Scheme guardians should be simple and friendly, not like the greedy * monsters we had... * - * Rewritten for the Boehm-Wiser GC by Ludovic Courtès. + * Rewritten for the Boehm-Demers-Weiser GC by Ludovic Courtès. * FIXME: This is currently not thread-safe. */ +/* Uncomment the following line to debug guardian finalization. */ +/* #define DEBUG_GUARDIANS 1 */ + #ifdef HAVE_CONFIG_H # include #endif @@ -109,7 +112,7 @@ finalize_guarded (GC_PTR ptr, GC_PTR finalizer_data) guardian_list = SCM_CDR (PTR2SCM (finalizer_data)); proxied_finalizer = SCM_CAR (PTR2SCM (finalizer_data)); -#if 0 +#ifdef DEBUG_GUARDIANS printf ("finalizing guarded %p (%u guardians)\n", ptr, scm_to_uint (scm_length (guardian_list))); #endif @@ -130,8 +133,13 @@ finalize_guarded (GC_PTR ptr, GC_PTR finalizer_data) t_guardian *g; if (SCM_WEAK_PAIR_CAR_DELETED_P (guardian_list)) - /* The guardian itself vanished in the meantime. */ - continue; + { + /* The guardian itself vanished in the meantime. */ +#ifdef DEBUG_GUARDIANS + printf (" guardian for %p vanished\n", ptr); +#endif + continue; + } g = GUARDIAN_DATA (SCM_CAR (guardian_list)); if (g->live == 0) @@ -166,12 +174,12 @@ finalize_guarded (GC_PTR ptr, GC_PTR finalizer_data) GC_REGISTER_FINALIZER_NO_ORDER (ptr, finalizer, finalizer_data, &prev_finalizer, &prev_finalizer_data); -#if 0 +#ifdef DEBUG_GUARDIANS printf (" reinstalled proxied finalizer %p for %p\n", finalizer, ptr); #endif } -#if 0 +#ifdef DEBUG_GUARDIANS printf ("end of finalize (%p)\n", ptr); #endif }