Re: [PATCH] g_log_set/remove_handler



On Thu, 3 Aug 2000, Gady Kozma wrote:

> Sorry about sending the entire gmessages.c file rather than a diff, I work 
> on windows and have no decent diff util.
> 
> There are two changes from glib 1.2.8 in this file.
> 
> 1) g_log_set_handler now actually appends the new handler to the end of the 
> list of handlers rather than overwriting it.

i don't see how this is usefull, the function has _set_ semantics rather
than _add_ for a reson. installing multiple handlers for the same loglevels
in the same domain is of questionable benefit, and that's the only case
where you'd notice your append vs. the current prepend semantics.
note, btw, that your patch creates a circular list if handlers
are already installed:

@@ -257,7 +259,7 @@ g_log_set_handler (const gchar        *log_do
                   gpointer        user_data)
 {
   register GLogDomain *domain;
-  register GLogHandler *handler;
+  register GLogHandler *handler, *work, *last;
   static guint handler_id = 0;

   g_return_val_if_fail ((log_levels & G_LOG_LEVEL_MASK) != 0, 0);
@@ -267,8 +269,10 @@ g_log_set_handler (const gchar       *log_do
     log_domain = "";

   domain = g_log_find_domain (log_domain);
-  if (!domain)
+  if (!domain) {
     domain = g_log_domain_new (log_domain);
+    /*printf("G.K.: Added domain %s at %p\n", log_domain, domain);*/
+  }

   handler = g_new (GLogHandler, 1);
   g_mutex_lock (g_messages_lock);
@@ -278,7 +282,16 @@ g_log_set_handler (const gchar       *log_do
   handler->log_func = log_func;
   handler->data = user_data;
   handler->next = domain->handlers;
+  last = NULL;
+  work = domain->handlers;
+  while ( work != NULL ) {
+    last = work;
+    work = work->next;
+  }
+  if ( last == NULL )
   domain->handlers = handler;
+  else
+    last->next = handler;

   return handler_id;
 }

since you left
   handler->next = domain->handlers;
in place.

> 2) A nasty bug in g_log_domain_check_free which made it damage the list of 
> domains.

thanks, that needed to be fixed. g_log_remove_handler() had the same
problem.

> 
> Sorry also about the commented out printouts.

> 
> Gady.
> ________________________________________________________________________

---
ciaoTJ






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