Add g_log_set_handler_full
authorMatthias Clasen <mclasen@redhat.com>
Sat, 29 Nov 2014 04:31:00 +0000 (23:31 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 11 Jun 2015 02:03:19 +0000 (22:03 -0400)
This is a bindable version of g_log_set_handler that takes
a destroy notify for the user_data.

https://bugzilla.gnome.org/show_bug.cgi?id=740516

docs/reference/glib/glib-sections.txt
glib/gmessages.c
glib/gmessages.h

index 25b6146..4346ac2 100644 (file)
@@ -1142,6 +1142,7 @@ g_debug
 
 <SUBSECTION>
 g_log_set_handler
 
 <SUBSECTION>
 g_log_set_handler
+g_log_set_handler_full
 g_log_remove_handler
 g_log_set_always_fatal
 g_log_set_fatal_mask
 g_log_remove_handler
 g_log_set_always_fatal
 g_log_set_fatal_mask
index 5342596..fea3247 100644 (file)
@@ -279,6 +279,7 @@ struct _GLogHandler
   GLogLevelFlags log_level;
   GLogFunc      log_func;
   gpointer      data;
   GLogLevelFlags log_level;
   GLogFunc      log_func;
   gpointer      data;
+  GDestroyNotify destroy;
   GLogHandler  *next;
 };
 
   GLogHandler  *next;
 };
 
@@ -566,9 +567,37 @@ g_log_set_fatal_mask (const gchar   *log_domain,
  */
 guint
 g_log_set_handler (const gchar  *log_domain,
  */
 guint
 g_log_set_handler (const gchar  *log_domain,
-                  GLogLevelFlags log_levels,
-                  GLogFunc       log_func,
-                  gpointer       user_data)
+                   GLogLevelFlags log_levels,
+                   GLogFunc       log_func,
+                   gpointer       user_data)
+{
+  return g_log_set_handler_full (log_domain, log_levels, log_func, user_data, NULL);
+}
+
+/**
+ * g_log_set_handler_full: (rename-to g_log_set_handler)
+ * @log_domain: (allow-none): the log domain, or %NULL for the default ""
+ *     application domain
+ * @log_levels: the log levels to apply the log handler for.
+ *     To handle fatal and recursive messages as well, combine
+ *     the log levels with the #G_LOG_FLAG_FATAL and
+ *     #G_LOG_FLAG_RECURSION bit flags.
+ * @log_func: the log handler function
+ * @user_data: data passed to the log handler
+ * @destroy: destroy notify for @user_data, or %NULL
+ *
+ * Like g_log_sets_handler(), but takes a destroy notify for the @user_data.
+ *
+ * Returns: the id of the new handler
+ *
+ * Since: 2.44
+ */
+guint
+g_log_set_handler_full (const gchar    *log_domain,
+                        GLogLevelFlags  log_levels,
+                        GLogFunc        log_func,
+                        gpointer        user_data,
+                        GDestroyNotify  destroy)
 {
   static guint handler_id = 0;
   GLogDomain *domain;
 {
   static guint handler_id = 0;
   GLogDomain *domain;
@@ -592,6 +621,7 @@ g_log_set_handler (const gchar       *log_domain,
   handler->log_level = log_levels;
   handler->log_func = log_func;
   handler->data = user_data;
   handler->log_level = log_levels;
   handler->log_func = log_func;
   handler->data = user_data;
+  handler->destroy = destroy;
   handler->next = domain->handlers;
   domain->handlers = handler;
 
   handler->next = domain->handlers;
   domain->handlers = handler;
 
@@ -699,6 +729,8 @@ g_log_remove_handler (const gchar *log_domain,
                domain->handlers = work->next;
              g_log_domain_check_free_L (domain); 
              g_mutex_unlock (&g_messages_lock);
                domain->handlers = work->next;
              g_log_domain_check_free_L (domain); 
              g_mutex_unlock (&g_messages_lock);
+              if (work->destroy)
+                work->destroy (work->data);
              g_free (work);
              return;
            }
              g_free (work);
              return;
            }
index 497c669..d186c2b 100644 (file)
@@ -86,6 +86,12 @@ guint           g_log_set_handler       (const gchar    *log_domain,
                                          GLogLevelFlags  log_levels,
                                          GLogFunc        log_func,
                                          gpointer        user_data);
                                          GLogLevelFlags  log_levels,
                                          GLogFunc        log_func,
                                          gpointer        user_data);
+GLIB_AVAILABLE_IN_2_44
+guint           g_log_set_handler_full  (const gchar    *log_domain,
+                                         GLogLevelFlags  log_levels,
+                                         GLogFunc        log_func,
+                                         gpointer        user_data,
+                                         GDestroyNotify  destroy);
 GLIB_AVAILABLE_IN_ALL
 void            g_log_remove_handler    (const gchar    *log_domain,
                                          guint           handler_id);
 GLIB_AVAILABLE_IN_ALL
 void            g_log_remove_handler    (const gchar    *log_domain,
                                          guint           handler_id);