[glib/wip/gcleanup: 6/21] gcleanup: Drop the G_CLEANUP_REMOVE() function and related func



commit acba03677c74b49b20c67a99b36ff0dad56a1230
Author: Stef Walter <stefw gnome org>
Date:   Thu Oct 31 23:16:14 2013 +0100

    gcleanup: Drop the G_CLEANUP_REMOVE() function and related func
    
    It shouldn't be necessary. Callers who want to stop or change
    a cleanup, can just keep around a pointer that they change or
    nullify. We *are* talking about static/global data here after all.
    
    In addition it was hard to get lockless operations here right, and
    G_CLEANUP_REMOVE implementation was really inefficient.
    
    We don't want to encourage people using this for things they really
    should be freeing themselves.
    
    Lastly clean up some old documentation
    
    https://bugzilla.gnome.org/show_bug.cgi?id=627423

 glib/gcleanup.c |   58 -------------------------------------------------------
 glib/gcleanup.h |   17 ----------------
 glib/gutils.c   |   16 ++++++++------
 3 files changed, 9 insertions(+), 82 deletions(-)
---
diff --git a/glib/gcleanup.c b/glib/gcleanup.c
index 92fb632..065c7bd 100644
--- a/glib/gcleanup.c
+++ b/glib/gcleanup.c
@@ -101,51 +101,6 @@ g_cleanup_list_add (GCleanupList *list,
 }
 
 /**
- * g_cleanup_list_remove:
- * @list: a #GCleanupList
- * @cleanup_func: the cleanup function
- * @user_data: data for the cleanup function
- *
- * Removes an item in the list.
- *
- * This function reverses a previous call to g_cleanup_list_add().
- *
- * Most typically, you will not use this function directly.  See
- * G_CLEANUP_REMOVE().
- *
- * This function is threadsafe.  Changes can occur while adds and
- * changes are occuring in other threads.
- *
- * Since: 2.38
- **/
-void
-g_cleanup_list_remove (GCleanupList *list,
-                       GCleanupFunc  cleanup_func,
-                       gpointer      user_data)
-{
-  GCleanupNode *node = NULL;
-  GCleanupNode **ptr;
-
-  if (!g_cleanup_enabled)
-    return;
-
-  g_mutex_lock (&lock);
-  for (ptr = (GCleanupNode **) &list->priv[0]; *ptr; ptr = &(*ptr)->next)
-    {
-      if ((*ptr)->data == user_data && (*ptr)->func == cleanup_func)
-        {
-          node = *ptr;
-          *ptr = node->next;
-          break;
-        }
-    }
-  g_mutex_unlock (&lock);
-
-  if (node)
-    free (node);
-}
-
-/**
  * g_cleanup_list_clear:
  * @list: a #GCleanupList
  *
@@ -237,16 +192,3 @@ g_cleanup_list_clear (GCleanupList *list)
  *
  * Since: 2.38
  **/
-
-/**
- * G_CLEANUP_READD:
- * @old_data: the data that would have been freed, non-%NULL
- * @new_data: the data that should now be freed, non-%NULL
- *
- * Modifies the data pointer used in a previous call to G_CLEANUP_ADD().
- *
- * As an example, you might need to use this in the case of needing to
- * realloc() something that had been previously marked for cleanup.
- *
- * Since: 2.38
- **/
diff --git a/glib/gcleanup.h b/glib/gcleanup.h
index 1272a39..5262afe 100644
--- a/glib/gcleanup.h
+++ b/glib/gcleanup.h
@@ -45,10 +45,6 @@ void                    g_cleanup_list_add                              (GCleanu
                                                                          GCleanupFunc  cleanup_func,
                                                                          gpointer      user_data);
 GLIB_AVAILABLE_IN_2_36
-void                    g_cleanup_list_remove                           (GCleanupList *list,
-                                                                         GCleanupFunc  cleanup_func,
-                                                                         gpointer      user_data);
-GLIB_AVAILABLE_IN_2_36
 void                    g_cleanup_list_clear                            (GCleanupList *list);
 
 
@@ -68,14 +64,6 @@ void                    g_cleanup_list_clear                            (GCleanu
     if (data)                                                                   \
       g_cleanup_list_add (&_glib_cleanup_list, (void*) (func), (data));         \
   } G_STMT_END
-#define G_CLEANUP_REMOVE(data, func) \
-  G_STMT_START {                                                                \
-    extern GCleanupList _glib_cleanup_list;                                     \
-    if (0) (func) ((data));                                                     \
-    g_warn_if_fail ((data) != NULL);                                            \
-    if (data)                                                                   \
-      g_cleanup_list_remove (&_glib_cleanup_list, (void*) (func), (data));      \
-  } G_STMT_END
 #define G_CLEANUP_ADD_FUNC(func) \
   G_STMT_START {                                                                \
     extern GCleanupList _glib_cleanup_list;                                     \
@@ -91,11 +79,6 @@ void                    g_cleanup_list_clear                            (GCleanu
     g_warn_if_fail ((data) != NULL);                                    \
     if (0) (func) (data);                                               \
   } G_STMT_END
-#define G_CLEANUP_REMOVE(data, func) \
-  G_STMT_START {                                                        \
-    g_warn_if_fail ((data) != NULL);                                    \
-    if (0) (func) (data);                                               \
-  } G_STMT_END
 #define G_CLEANUP_ADD_FUNC(func) \
   G_STMT_START {                                                        \
     if (0) (func) ();                                                   \
diff --git a/glib/gutils.c b/glib/gutils.c
index 6c8ff2e..acebc12 100644
--- a/glib/gutils.c
+++ b/glib/gutils.c
@@ -1076,6 +1076,12 @@ g_get_host_name (void)
 G_LOCK_DEFINE_STATIC (g_prgname);
 static gchar *g_prgname = NULL;
 
+static void
+cleanup_prgname (void)
+{
+  g_clear_pointer (&g_prgname, g_free);
+}
+
 /**
  * g_get_prgname:
  *
@@ -1112,7 +1118,7 @@ g_get_prgname (void)
          if (utf8_buf)
            {
              g_prgname = g_path_get_basename (utf8_buf);
-              G_CLEANUP_ADD (g_prgname, g_free);
+             G_CLEANUP_ADD_FUNC (cleanup_prgname);
              g_free (utf8_buf);
            }
        }
@@ -1141,13 +1147,9 @@ g_set_prgname (const gchar *prgname)
    * to show up in valgrind, so we should _not_ free the original string
    * during cleanup.
    */
-  if (g_prgname)
-    {
-      G_CLEANUP_REMOVE (g_prgname, g_free);
-      g_free (g_prgname);
-    }
+  if (!g_prgname)
+    G_CLEANUP_ADD_FUNC (cleanup_prgname);
   g_prgname = g_strdup (prgname);
-  G_CLEANUP_ADD (g_prgname, g_free);
   G_UNLOCK (g_prgname);
 }
 


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