[glib/wip/gcleanup] WIP more gcleanup bug fixes



commit 606e4fea15c467b86aa3eb7cfc1d2fc63154c50c
Author: Stef Walter <stefw gnome org>
Date:   Thu Nov 7 22:27:58 2013 +0100

    WIP more gcleanup bug fixes

 glib/gcleanup.c |   47 ++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 36 insertions(+), 11 deletions(-)
---
diff --git a/glib/gcleanup.c b/glib/gcleanup.c
index e8e9d70..0a42aa5 100644
--- a/glib/gcleanup.c
+++ b/glib/gcleanup.c
@@ -24,10 +24,10 @@
 #include "gcleanup.h"
 
 #include "glib-init.h"
-#include "gmessages.h"
 #include "gatomic.h"
 
 #include <stdlib.h>
+#include <string.h>
 
 /*
  * NOTE: most glib functions are off limits in this function without
@@ -83,6 +83,13 @@ phase_to_string (GCleanupPhase phase)
   }
 }
 
+static gboolean
+check_if_verbose (const gchar *log_domain)
+{
+  const gchar *env = getenv ("G_MESSAGES_DEBUG");
+  return (env && (strcmp (env, "all") == 0 || strstr (env, log_domain)));
+}
+
 /**
  * g_cleanup_is_enabled:
  *
@@ -134,6 +141,7 @@ g_cleanup_list_push (GCleanupList *list,
                      const gchar  *location)
 {
   GCleanupNode *node;
+  const gchar *log_domain;
 
   g_return_if_fail (cleanup_func != NULL);
 
@@ -155,14 +163,20 @@ g_cleanup_list_push (GCleanupList *list,
   while (!g_atomic_pointer_compare_and_exchange (&list->priv[P_NODES],
                                                  node->next, node));
 
-  fprintf (stderr, "g_cleanup_list_push: pushed %p/%s at %s\n", user_data, phase_to_string (phase), 
location);
+  log_domain = list->priv[P_LOG];
+  if (check_if_verbose (log_domain))
+    {
+      fprintf (stderr, "%s-DEBUG: g_cleanup_list_push: pushed %p/%s at %s\n",
+               log_domain, user_data, phase_to_string (phase), location);
+    }
 }
 
 static GCleanupNode *
-cleanup_pass (GCleanupList *list,
-              GCleanupNode *clear,
+cleanup_pass (GCleanupNode *clear,
               GCleanupNode *also,
               GCleanupPhase phase,
+              gboolean verbose,
+              const gchar *log_domain,
               gboolean *cleaned_up)
 {
   GCleanupNode *later;
@@ -188,11 +202,15 @@ cleanup_pass (GCleanupList *list,
           node->next = NULL;
           *later_next = node;
           later_next = &node->next;
-          fprintf (stderr, "g_cleanup_list_clear: delaying till %s: %p at %s\n", phase_to_string 
(node->phase), node->data, node->location);
         }
       else
         {
-          fprintf (stderr, "g_cleanup_list_clear: cleanup at %s: %p at %s\n", phase_to_string (node->phase), 
node->data, node->location);
+          if (verbose)
+            {
+              fprintf (stderr, "%s-DEBUG: g_cleanup_list_clear: cleanup at %s: %p at %s\n",
+                       log_domain, phase_to_string (node->phase), node->data, node->location);
+            }
+
           (*node->func) (node->data);
           *cleaned_up = TRUE;
           free (node);
@@ -223,16 +241,22 @@ g_cleanup_list_clear (GCleanupList *list)
   GCleanupNode *clear;
   GCleanupPhase phase;
   gboolean progressed;
+  const gchar *log_domain;
+  gboolean verbose;
   gint i;
 
   if (!list || !g_cleanup_enabled)
     return;
 
+  log_domain = list->priv[P_LOG];
+  verbose = check_if_verbose (log_domain);
+
   /* Note that we're starting to clear */
   phase = G_CLEANUP_PHASE_EARLY;
   if (!g_atomic_int_compare_and_exchange (&list->vals[V_PHASE], 0, phase))
     {
-      g_critical ("g_cleanup_list_clear() called twice for the same GCleanupList");
+      fprintf (stderr, "%s-CRITICAL: g_cleanup_list_clear() called twice for the same GCleanupList\n",
+               log_domain);
       return;
     }
 
@@ -240,7 +264,6 @@ g_cleanup_list_clear (GCleanupList *list)
 
   while (phase <= G_CLEANUP_PHASE_GRAVEYARD)
     {
-      fprintf (stderr, "g_cleanup_list_clear: at phase %s\n", phase_to_string (phase));
       for (i = 0; i < MAX_PASSES + 1; i++)
         {
           progressed = FALSE;
@@ -254,11 +277,12 @@ g_cleanup_list_clear (GCleanupList *list)
 
           if (clear && i == MAX_PASSES)
             {
-              fprintf (stderr, "g_cleanup_list_clear: gave up after %d passes\n", MAX_PASSES);
+              fprintf (stderr, "%s-WARNING: g_cleanup_list_clear: gave up after %d passes\n",
+                       log_domain, MAX_PASSES);
               return;
             }
 
-          later = cleanup_pass (list, clear, later, phase, &progressed);
+          later = cleanup_pass (later, clear, phase, verbose, log_domain, &progressed);
 
           if (!progressed)
             break;
@@ -267,7 +291,8 @@ g_cleanup_list_clear (GCleanupList *list)
       phase = g_atomic_int_add (&list->vals[V_PHASE], 1) + 1;
     }
 
-  fprintf (stderr, "g_cleanup_list_clear: cleanup done\n");
+  if (verbose)
+    fprintf (stderr, "%s-DEBUG: g_cleanup_list_clear: cleanup done\n", log_domain);
 }
 
 /**


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]