[Xfce4-commits] <garcon:master> Add macro to free list with destroy function.

Nick Schermer noreply at xfce.org
Mon Jun 27 21:28:01 CEST 2011


Updating branch refs/heads/master
         to ba62f4e94bc79e63c0ef515b0d746077258affe2 (commit)
       from 1d816daaaff26e7ee7bbfafa2aed9a38febb5c91 (commit)

commit ba62f4e94bc79e63c0ef515b0d746077258affe2
Author: Nick Schermer <nick at xfce.org>
Date:   Mon Jun 27 21:24:58 2011 +0200

    Add macro to free list with destroy function.
    
    Used quite often in garcon and since 2.28 there is a
    function for this in glib. Bit easier on the eye.

 garcon/garcon-menu-item.c   |    9 +++------
 garcon/garcon-menu-merger.c |   12 ++++--------
 garcon/garcon-menu.c        |   18 ++++++------------
 garcon/garcon-private.h     |   15 +++++++++++++++
 4 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/garcon/garcon-menu-item.c b/garcon/garcon-menu-item.c
index 5c5d2c4..4588727 100644
--- a/garcon/garcon-menu-item.c
+++ b/garcon/garcon-menu-item.c
@@ -419,8 +419,7 @@ garcon_menu_item_finalize (GObject *object)
   g_strfreev (item->priv->only_show_in);
   g_strfreev (item->priv->not_show_in);
 
-  g_list_foreach (item->priv->categories, (GFunc) g_free, NULL);
-  g_list_free (item->priv->categories);
+  _garcon_g_list_free_full (item->priv->categories, g_free);
 
   if (item->priv->file != NULL)
     g_object_unref (G_OBJECT (item->priv->file));
@@ -975,8 +974,7 @@ garcon_menu_item_reload_from_file (GarconMenuItem  *item,
       if (!garcon_menu_item_category_lists_equal (old_categories, categories))
         *affects_the_outside = TRUE;
 
-      g_list_foreach (old_categories, (GFunc) g_free, NULL);
-      g_list_free (old_categories);
+      _garcon_g_list_free_full (old_categories, g_free);
     }
     
 
@@ -1072,8 +1070,7 @@ garcon_menu_item_set_categories (GarconMenuItem *item,
     return;
 
   /* Free old list */
-  g_list_foreach (item->priv->categories, (GFunc) g_free, NULL);
-  g_list_free (item->priv->categories);
+  _garcon_g_list_free_full (item->priv->categories, g_free);
 
   /* Assign new list */
   item->priv->categories = categories;
diff --git a/garcon/garcon-menu-merger.c b/garcon/garcon-menu-merger.c
index 179191c..fd0aa6e 100644
--- a/garcon/garcon-menu-merger.c
+++ b/garcon/garcon-menu-merger.c
@@ -335,8 +335,7 @@ garcon_menu_merger_run (GarconMenuMerger *merger,
   garcon_menu_merger_clean_up_elements (merger->priv->menu, GARCON_MENU_NODE_TYPE_DEFAULT_LAYOUT);
   garcon_menu_merger_clean_up_elements (merger->priv->menu, GARCON_MENU_NODE_TYPE_LAYOUT);
 
-  g_list_foreach (context.file_stack, (GFunc) g_object_unref, NULL);
-  g_list_free (context.file_stack);
+  _garcon_g_list_free_full (context.file_stack, g_object_unref);
 
   return context.success;
 }
@@ -691,8 +690,7 @@ garcon_menu_merger_remove_duplicate_paths (GNode             *node,
         }
     }
 
-  g_slist_foreach (destroy_nodes, (GFunc) garcon_menu_node_tree_free, NULL);
-  g_slist_free (destroy_nodes);
+  _garcon_g_slist_free_full (destroy_nodes, garcon_menu_node_tree_free);
   g_slist_free (remaining_nodes);
 }
 
@@ -994,8 +992,7 @@ garcon_menu_merger_clean_up_elements (GNode             *node,
         remaining_node = child;
     }
 
-  g_list_foreach (destroy_list, (GFunc) garcon_menu_node_tree_free, NULL);
-  g_list_free (destroy_list);
+  _garcon_g_list_free_full (destroy_list, garcon_menu_node_tree_free);
 
   if (type == GARCON_MENU_NODE_TYPE_LAYOUT 
       && remaining_node != NULL
@@ -1227,8 +1224,7 @@ garcon_menu_merger_resolve_moves (GNode *node)
       g_strfreev (new_path);
     }
 
-  g_list_foreach (pairs, (GFunc) g_free, NULL);
-  g_list_free (pairs);
+  _garcon_g_list_free_full (pairs, g_free);
 }
 
 
diff --git a/garcon/garcon-menu.c b/garcon/garcon-menu.c
index 8022e50..f19d9b4 100644
--- a/garcon/garcon-menu.c
+++ b/garcon/garcon-menu.c
@@ -357,19 +357,16 @@ garcon_menu_clear (GarconMenu *menu)
       menu->priv->tree = NULL;
 
       /* Release the merge files */
-      g_list_foreach (menu->priv->merge_files, (GFunc) g_object_unref, NULL);
-      g_list_free (menu->priv->merge_files);
+      _garcon_g_list_free_full (menu->priv->merge_files, g_object_unref);
       menu->priv->merge_files = NULL;
 
       /* Release the merge dirs */
-      g_list_foreach (menu->priv->merge_dirs, (GFunc) g_object_unref, NULL);
-      g_list_free (menu->priv->merge_dirs);
+      _garcon_g_list_free_full (menu->priv->merge_dirs, g_object_unref);
       menu->priv->merge_dirs = NULL;
     }
 
   /* Free submenus */
-  g_list_foreach (menu->priv->submenus, (GFunc) g_object_unref, NULL);
-  g_list_free (menu->priv->submenus);
+  _garcon_g_list_free_full (menu->priv->submenus, g_object_unref);
   menu->priv->submenus = NULL;
 
   /* Free directory */
@@ -1840,8 +1837,7 @@ garcon_menu_stop_monitoring (GarconMenu *menu)
     g_source_remove (menu->priv->file_changed_idle);
 
   /* Free the hash table for merging consecutive file change events */
-  g_slist_foreach (menu->priv->changed_files, (GFunc) g_object_unref, NULL);
-  g_slist_free (menu->priv->changed_files);
+  _garcon_g_slist_free_full (menu->priv->changed_files, g_object_unref);
   menu->priv->changed_files = NULL;
 }
 
@@ -1986,8 +1982,7 @@ garcon_menu_monitor_app_dirs (GarconMenu *menu)
   garcon_menu_monitor_files (menu, dirs, garcon_menu_app_dir_changed);
 
   /* Release the allocated GFiles and free the list */
-  g_list_foreach (dirs, (GFunc) g_object_unref, NULL);
-  g_list_free (dirs);
+  _garcon_g_list_free_full (dirs, g_object_unref);
 
   /* Free app dir list */
   g_list_free (app_dirs);
@@ -2274,8 +2269,7 @@ garcon_menu_process_file_changes (GarconMenu *menu)
     }
 
   /* reset the changed files list, all events processed */
-  g_slist_foreach (menu->priv->changed_files, (GFunc) g_object_unref, NULL);
-  g_slist_free (menu->priv->changed_files);
+  _garcon_g_slist_free_full (menu->priv->changed_files, g_object_unref);
   menu->priv->changed_files = NULL;
 
   /* reset the idle source ID */
diff --git a/garcon/garcon-private.h b/garcon/garcon-private.h
index 4882ab3..15e1d87 100644
--- a/garcon/garcon-private.h
+++ b/garcon/garcon-private.h
@@ -28,6 +28,21 @@
 
 G_BEGIN_DECLS
 
+/* Macro for new g_?list_free_full function */
+#if GLIB_CHECK_VERSION (2, 28, 0)
+#define _garcon_g_slist_free_full(list,free_func) \
+  g_slist_free_full (list, (GDestroyNotify) free_func)
+#define _garcon_g_list_free_full(list,free_func) \
+  g_list_free_full (list, (GDestroyNotify) free_func)
+#else
+#define _garcon_g_slist_free_full(list,free_func) G_STMT_START { \
+  g_slist_foreach (list, (GFunc) free_func, NULL); \
+  g_slist_free (list); } G_STMT_END
+#define _garcon_g_list_free_full(list,free_func) G_STMT_START { \
+  g_list_foreach (list, (GFunc) free_func, NULL); \
+  g_list_free (list); } G_STMT_END
+#endif
+
 /* if XDG_MENU_PREFIX is not set, default to "xfce-" so garcon doesn't
  * break when xfce is not started with startxfce4 */
 #define GARCON_DEFAULT_MENU_PREFIX "xfce-"



More information about the Xfce4-commits mailing list