[Xfce4-commits] <xfce4-appfinder:nick/xfrun4-merge> Use custom error macros.

Nick Schermer noreply at xfce.org
Sun Jul 3 21:38:01 CEST 2011


Updating branch refs/heads/nick/xfrun4-merge
         to cb96cdd1bd7addecf72f301a0ac5f67172b97894 (commit)
       from e432a997903e1cc76ea8d57b16d65b04264cd6b0 (commit)

commit cb96cdd1bd7addecf72f301a0ac5f67172b97894
Author: Nick Schermer <nick at xfce.org>
Date:   Sun Jul 3 21:35:48 2011 +0200

    Use custom error macros.

 src/appfinder-category-model.c |   36 ++++++++--------
 src/appfinder-model.c          |   90 ++++++++++++++++++++--------------------
 src/appfinder-private.h        |   12 +++++
 src/appfinder-window.c         |    2 +-
 4 files changed, 76 insertions(+), 64 deletions(-)

diff --git a/src/appfinder-category-model.c b/src/appfinder-category-model.c
index 3f5cb82..f7860d9 100644
--- a/src/appfinder-category-model.c
+++ b/src/appfinder-category-model.c
@@ -183,7 +183,7 @@ xfce_appfinder_category_model_get_column_type (GtkTreeModel *tree_model,
       return GARCON_TYPE_MENU_DIRECTORY;
 
     default:
-      g_assert_not_reached ();
+      appfinder_assert_not_reached ();
       return G_TYPE_INVALID;
     }
 }
@@ -197,8 +197,8 @@ xfce_appfinder_category_model_get_iter (GtkTreeModel *tree_model,
 {
   XfceAppfinderCategoryModel *model = XFCE_APPFINDER_CATEGORY_MODEL (tree_model);
 
-  g_return_val_if_fail (XFCE_IS_APPFINDER_CATEGORY_MODEL (model), FALSE);
-  g_return_val_if_fail (gtk_tree_path_get_depth (path) > 0, FALSE);
+  appfinder_return_val_if_fail (XFCE_IS_APPFINDER_CATEGORY_MODEL (model), FALSE);
+  appfinder_return_val_if_fail (gtk_tree_path_get_depth (path) > 0, FALSE);
 
   iter->stamp = model->stamp;
   iter->user_data = g_slist_nth (model->categories, gtk_tree_path_get_indices (path)[0]);
@@ -215,8 +215,8 @@ xfce_appfinder_category_model_get_path (GtkTreeModel *tree_model,
   XfceAppfinderCategoryModel *model = XFCE_APPFINDER_CATEGORY_MODEL (tree_model);
   gint                        idx;
 
-  g_return_val_if_fail (XFCE_IS_APPFINDER_CATEGORY_MODEL (model), NULL);
-  g_return_val_if_fail (iter->stamp == model->stamp, NULL);
+  appfinder_return_val_if_fail (XFCE_IS_APPFINDER_CATEGORY_MODEL (model), NULL);
+  appfinder_return_val_if_fail (iter->stamp == model->stamp, NULL);
 
   /* determine the index of the iter */
   idx = g_slist_position (model->categories, iter->user_data);
@@ -238,11 +238,11 @@ xfce_appfinder_category_model_get_value (GtkTreeModel *tree_model,
   CategoryItem               *item;
   const gchar                *icon_name;
 
-  g_return_if_fail (XFCE_IS_APPFINDER_CATEGORY_MODEL (model));
-  g_return_if_fail (iter->stamp == model->stamp);
+  appfinder_return_if_fail (XFCE_IS_APPFINDER_CATEGORY_MODEL (model));
+  appfinder_return_if_fail (iter->stamp == model->stamp);
 
   item = ITER_GET_DATA (iter);
-  g_return_if_fail (item->directory == NULL || GARCON_IS_MENU_DIRECTORY (item->directory));
+  appfinder_return_if_fail (item->directory == NULL || GARCON_IS_MENU_DIRECTORY (item->directory));
 
   switch (column)
     {
@@ -272,7 +272,7 @@ xfce_appfinder_category_model_get_value (GtkTreeModel *tree_model,
       break;
 
     default:
-      g_assert_not_reached ();
+      appfinder_assert_not_reached ();
       break;
     }
 }
@@ -283,8 +283,8 @@ static gboolean
 xfce_appfinder_category_model_iter_next (GtkTreeModel *tree_model,
                                          GtkTreeIter  *iter)
 {
-  g_return_val_if_fail (XFCE_IS_APPFINDER_CATEGORY_MODEL (tree_model), FALSE);
-  g_return_val_if_fail (iter->stamp == XFCE_APPFINDER_CATEGORY_MODEL (tree_model)->stamp, FALSE);
+  appfinder_return_val_if_fail (XFCE_IS_APPFINDER_CATEGORY_MODEL (tree_model), FALSE);
+  appfinder_return_val_if_fail (iter->stamp == XFCE_APPFINDER_CATEGORY_MODEL (tree_model)->stamp, FALSE);
 
   iter->user_data = g_slist_next (iter->user_data);
   return (iter->user_data != NULL);
@@ -299,7 +299,7 @@ xfce_appfinder_category_model_iter_children (GtkTreeModel *tree_model,
 {
   XfceAppfinderCategoryModel *model = XFCE_APPFINDER_CATEGORY_MODEL (tree_model);
 
-  g_return_val_if_fail (XFCE_IS_APPFINDER_CATEGORY_MODEL (model), FALSE);
+  appfinder_return_val_if_fail (XFCE_IS_APPFINDER_CATEGORY_MODEL (model), FALSE);
 
   if (G_LIKELY (parent == NULL && model->categories != NULL))
     {
@@ -328,7 +328,7 @@ xfce_appfinder_category_model_iter_n_children (GtkTreeModel *tree_model,
 {
   XfceAppfinderCategoryModel *model = XFCE_APPFINDER_CATEGORY_MODEL (tree_model);
 
-  g_return_val_if_fail (XFCE_IS_APPFINDER_CATEGORY_MODEL (model), 0);
+  appfinder_return_val_if_fail (XFCE_IS_APPFINDER_CATEGORY_MODEL (model), 0);
 
   return (iter == NULL) ? g_slist_length (model->categories) : 0;
 }
@@ -343,7 +343,7 @@ xfce_appfinder_category_model_iter_nth_child (GtkTreeModel *tree_model,
 {
   XfceAppfinderCategoryModel *model = XFCE_APPFINDER_CATEGORY_MODEL (tree_model);
 
-  g_return_val_if_fail (XFCE_IS_APPFINDER_CATEGORY_MODEL (model), FALSE);
+  appfinder_return_val_if_fail (XFCE_IS_APPFINDER_CATEGORY_MODEL (model), FALSE);
 
   if (G_LIKELY (parent != NULL))
     {
@@ -408,7 +408,7 @@ xfce_appfinder_category_model_set_categories (XfceAppfinderCategoryModel *model,
      model->categories = NULL;
     }
 
-  g_assert (model->categories == NULL);
+  appfinder_assert (model->categories == NULL);
 
   /* separator and the main categories */
   item = g_slice_new0 (CategoryItem);
@@ -454,7 +454,7 @@ xfce_appfinder_category_model_row_separator_func (GtkTreeModel *tree_model,
 {
   CategoryItem *item = ITER_GET_DATA (iter);
 
-  g_return_val_if_fail (XFCE_IS_APPFINDER_CATEGORY_MODEL (tree_model), FALSE);
+  appfinder_return_val_if_fail (XFCE_IS_APPFINDER_CATEGORY_MODEL (tree_model), FALSE);
 
   return (item->directory == NULL);
 }
@@ -470,7 +470,7 @@ xfce_appfinder_category_model_icon_theme_changed (XfceAppfinderCategoryModel *mo
   GtkTreeIter   iter;
   GtkTreePath  *path;
 
-  g_return_if_fail (XFCE_IS_APPFINDER_CATEGORY_MODEL (model));
+  appfinder_return_if_fail (XFCE_IS_APPFINDER_CATEGORY_MODEL (model));
 
   for (li = model->categories, idx = 0; li != NULL; li = li->next, idx++)
     {
@@ -499,7 +499,7 @@ xfce_appfinder_category_model_find_category (XfceAppfinderCategoryModel *model,
   GSList       *li;
   gint          idx;
 
-  g_return_val_if_fail (XFCE_IS_APPFINDER_CATEGORY_MODEL (model), NULL);
+  appfinder_return_val_if_fail (XFCE_IS_APPFINDER_CATEGORY_MODEL (model), NULL);
 
   if (IS_STRING (name))
     {
diff --git a/src/appfinder-model.c b/src/appfinder-model.c
index 801847c..3696ce2 100644
--- a/src/appfinder-model.c
+++ b/src/appfinder-model.c
@@ -288,8 +288,8 @@ xfce_appfinder_model_get_iter (GtkTreeModel *tree_model,
 {
   XfceAppfinderModel *model = XFCE_APPFINDER_MODEL (tree_model);
 
-  g_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (model), FALSE);
-  g_return_val_if_fail (gtk_tree_path_get_depth (path) > 0, FALSE);
+  appfinder_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (model), FALSE);
+  appfinder_return_val_if_fail (gtk_tree_path_get_depth (path) > 0, FALSE);
 
   iter->stamp = model->stamp;
   iter->user_data = g_slist_nth (model->items, gtk_tree_path_get_indices (path)[0]);
@@ -306,8 +306,8 @@ xfce_appfinder_model_get_path (GtkTreeModel *tree_model,
   XfceAppfinderModel *model = XFCE_APPFINDER_MODEL (tree_model);
   gint                idx;
 
-  g_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (model), NULL);
-  g_return_val_if_fail (iter->stamp == model->stamp, NULL);
+  appfinder_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (model), NULL);
+  appfinder_return_val_if_fail (iter->stamp == model->stamp, NULL);
 
   /* determine the index of the iter */
   idx = g_slist_position (model->items, iter->user_data);
@@ -336,11 +336,11 @@ xfce_appfinder_model_get_value (GtkTreeModel *tree_model,
   gchar               *cat_str;
   guint                i;
 
-  g_return_if_fail (XFCE_IS_APPFINDER_MODEL (model));
-  g_return_if_fail (iter->stamp == model->stamp);
+  appfinder_return_if_fail (XFCE_IS_APPFINDER_MODEL (model));
+  appfinder_return_if_fail (iter->stamp == model->stamp);
 
   item = ITER_GET_DATA (iter);
-  g_return_if_fail ((item->item == NULL && item->command != NULL)
+  appfinder_return_if_fail ((item->item == NULL && item->command != NULL)
                     || (item->item != NULL && GARCON_IS_MENU_ITEM (item->item)));
 
   switch (column)
@@ -449,8 +449,8 @@ static gboolean
 xfce_appfinder_model_iter_next (GtkTreeModel *tree_model,
                                 GtkTreeIter  *iter)
 {
-  g_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (tree_model), FALSE);
-  g_return_val_if_fail (iter->stamp == XFCE_APPFINDER_MODEL (tree_model)->stamp, FALSE);
+  appfinder_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (tree_model), FALSE);
+  appfinder_return_val_if_fail (iter->stamp == XFCE_APPFINDER_MODEL (tree_model)->stamp, FALSE);
 
   iter->user_data = g_slist_next (iter->user_data);
   return (iter->user_data != NULL);
@@ -465,7 +465,7 @@ xfce_appfinder_model_iter_children (GtkTreeModel *tree_model,
 {
   XfceAppfinderModel *model = XFCE_APPFINDER_MODEL (tree_model);
 
-  g_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (model), FALSE);
+  appfinder_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (model), FALSE);
 
   if (G_LIKELY (parent == NULL && model->items != NULL))
     {
@@ -494,7 +494,7 @@ xfce_appfinder_model_iter_n_children (GtkTreeModel *tree_model,
 {
   XfceAppfinderModel *model = XFCE_APPFINDER_MODEL (tree_model);
 
-  g_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (model), 0);
+  appfinder_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (model), 0);
 
   return (iter == NULL) ? g_slist_length (model->items) : 0;
 }
@@ -509,7 +509,7 @@ xfce_appfinder_model_iter_nth_child (GtkTreeModel *tree_model,
 {
   XfceAppfinderModel *model = XFCE_APPFINDER_MODEL (tree_model);
 
-  g_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (model), FALSE);
+  appfinder_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (model), FALSE);
 
   if (G_LIKELY (parent != NULL))
     {
@@ -543,8 +543,8 @@ xfce_appfinder_model_collect_idle (gpointer user_data)
   GSList             *tmp;
   ModelItem          *item;
 
-  g_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (model), FALSE);
-  g_return_val_if_fail (model->items == NULL, FALSE);
+  appfinder_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (model), FALSE);
+  appfinder_return_val_if_fail (model->items == NULL, FALSE);
 
   APPFINDER_DEBUG ("insert idle start");
 
@@ -687,7 +687,7 @@ xfce_appfinder_model_item_new (GarconMenuItem *menu_item)
   ModelItem   *item;
   const gchar *command, *p;
 
-  g_return_val_if_fail (GARCON_IS_MENU_ITEM (menu_item), NULL);
+  appfinder_return_val_if_fail (GARCON_IS_MENU_ITEM (menu_item), NULL);
 
   item = g_slice_new0 (ModelItem);
   item->item = g_object_ref (G_OBJECT (menu_item));
@@ -795,8 +795,8 @@ xfce_appfinder_model_category_compare (gconstpointer a,
   const CategoryItem *cat_a = a;
   const CategoryItem *cat_b = b;
 
-  g_return_val_if_fail (GARCON_IS_MENU_DIRECTORY (cat_a->directory), 0);
-  g_return_val_if_fail (GARCON_IS_MENU_DIRECTORY (cat_b->directory), 0);
+  appfinder_return_val_if_fail (GARCON_IS_MENU_DIRECTORY (cat_a->directory), 0);
+  appfinder_return_val_if_fail (GARCON_IS_MENU_DIRECTORY (cat_b->directory), 0);
 
   return g_utf8_collate (garcon_menu_directory_get_name (cat_a->directory),
                          garcon_menu_directory_get_name (cat_b->directory));
@@ -873,8 +873,8 @@ xfce_appfinder_model_collect_item (const gchar    *desktop_id,
 {
   ModelItem *item;
 
-  g_return_if_fail (GARCON_IS_MENU_ITEM (menu_item));
-  g_return_if_fail (desktop_id != NULL);
+  appfinder_return_if_fail (GARCON_IS_MENU_ITEM (menu_item));
+  appfinder_return_if_fail (desktop_id != NULL);
 
   /* check if we alread have the item */
   item = g_hash_table_lookup (context->desktop_ids, desktop_id);
@@ -916,12 +916,12 @@ xfce_appfinder_model_collect_items (GarconMenu           *menu,
   GarconMenuItemPool  *pool;
   CollectContext      *context;
 
-  g_return_val_if_fail (GARCON_IS_MENU (menu), FALSE);
-  g_return_val_if_fail (cancelled == NULL || G_IS_CANCELLABLE (cancelled), FALSE);
-  g_return_val_if_fail (category == NULL || GARCON_IS_MENU_DIRECTORY (category), FALSE);
-  g_return_val_if_fail (items != NULL, FALSE);
-  g_return_val_if_fail (categories != NULL, FALSE);
-  g_return_val_if_fail (desktop_ids != NULL, FALSE);
+  appfinder_return_val_if_fail (GARCON_IS_MENU (menu), FALSE);
+  appfinder_return_val_if_fail (cancelled == NULL || G_IS_CANCELLABLE (cancelled), FALSE);
+  appfinder_return_val_if_fail (category == NULL || GARCON_IS_MENU_DIRECTORY (category), FALSE);
+  appfinder_return_val_if_fail (items != NULL, FALSE);
+  appfinder_return_val_if_fail (categories != NULL, FALSE);
+  appfinder_return_val_if_fail (desktop_ids != NULL, FALSE);
 
   if (g_cancellable_is_cancelled (cancelled))
     return FALSE;
@@ -1040,9 +1040,9 @@ xfce_appfinder_model_menu_changed (GarconMenu         *menu,
   GtkTreePath  *path;
   CategoryItem *cat_a, *cat_b;
 
-  g_return_if_fail (GARCON_IS_MENU (menu));
-  g_return_if_fail (XFCE_IS_APPFINDER_MODEL (model));
-  g_return_if_fail (model->menu == menu);
+  appfinder_return_if_fail (GARCON_IS_MENU (menu));
+  appfinder_return_if_fail (XFCE_IS_APPFINDER_MODEL (model));
+  appfinder_return_if_fail (model->menu == menu);
 
   APPFINDER_DEBUG ("menu changed");
 
@@ -1143,9 +1143,9 @@ xfce_appfinder_model_collect_thread (gpointer user_data)
   gchar              *filename;
   GMappedFile        *history;
 
-  g_return_val_if_fail (GARCON_IS_MENU (model->menu), NULL);
-  g_return_val_if_fail (model->collect_items == NULL, NULL);
-  g_return_val_if_fail (model->collect_categories == NULL, NULL);
+  appfinder_return_val_if_fail (GARCON_IS_MENU (model->menu), NULL);
+  appfinder_return_val_if_fail (model->collect_items == NULL, NULL);
+  appfinder_return_val_if_fail (model->collect_categories == NULL, NULL);
 
   APPFINDER_DEBUG ("collect thread start");
 
@@ -1228,7 +1228,7 @@ xfce_appfinder_model_get (void)
 GSList *
 xfce_appfinder_model_get_categories (XfceAppfinderModel *model)
 {
-  g_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (model), NULL);
+  appfinder_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (model), NULL);
   return model->categories;
 }
 
@@ -1242,16 +1242,16 @@ xfce_appfinder_model_get_visible (XfceAppfinderModel        *model,
 {
   ModelItem *item;
 
-  g_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (model), FALSE);
-  g_return_val_if_fail (iter->stamp == model->stamp, FALSE);
-  g_return_val_if_fail (category == NULL || GARCON_IS_MENU_DIRECTORY (category), FALSE);
-  g_return_val_if_fail (GARCON_IS_MENU_DIRECTORY (model->command_category), FALSE);
+  appfinder_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (model), FALSE);
+  appfinder_return_val_if_fail (iter->stamp == model->stamp, FALSE);
+  appfinder_return_val_if_fail (category == NULL || GARCON_IS_MENU_DIRECTORY (category), FALSE);
+  appfinder_return_val_if_fail (GARCON_IS_MENU_DIRECTORY (model->command_category), FALSE);
 
   item = ITER_GET_DATA (iter);
 
   if (item->item != NULL)
     {
-      g_return_val_if_fail (GARCON_IS_MENU_ITEM (item->item), FALSE);
+      appfinder_return_val_if_fail (GARCON_IS_MENU_ITEM (item->item), FALSE);
 
       if (item->not_visible)
         return FALSE;
@@ -1266,7 +1266,7 @@ xfce_appfinder_model_get_visible (XfceAppfinderModel        *model,
     }
   else /* command item */
     {
-      g_return_val_if_fail (item->command != NULL, FALSE);
+      appfinder_return_val_if_fail (item->command != NULL, FALSE);
 
       if (category != model->command_category)
         return FALSE;
@@ -1294,9 +1294,9 @@ xfce_appfinder_model_execute (XfceAppfinderModel  *model,
   gboolean         succeed = FALSE;
   gchar          **argv;
 
-  g_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (model), FALSE);
-  g_return_val_if_fail (iter->stamp == model->stamp, FALSE);
-  g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
+  appfinder_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (model), FALSE);
+  appfinder_return_val_if_fail (iter->stamp == model->stamp, FALSE);
+  appfinder_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
 
   mitem = ITER_GET_DATA (iter);
   item = mitem->item;
@@ -1306,7 +1306,7 @@ xfce_appfinder_model_execute (XfceAppfinderModel  *model,
   if (item == NULL)
     return FALSE;
 
-  g_return_val_if_fail (GARCON_IS_MENU_ITEM (item), FALSE);
+  appfinder_return_val_if_fail (GARCON_IS_MENU_ITEM (item), FALSE);
 
   command = garcon_menu_item_get_command (item);
   if (!IS_STRING (command))
@@ -1443,7 +1443,7 @@ xfce_appfinder_model_save_command (XfceAppfinderModel  *model,
   gchar     *filename;
   ModelItem *item;
 
-  g_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (model), FALSE);
+  appfinder_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (model), FALSE);
 
   if (!IS_STRING (command)
       || g_hash_table_lookup (model->items_hash, command) != NULL)
@@ -1497,7 +1497,7 @@ xfce_appfinder_model_get_icon_for_command (XfceAppfinderModel *model,
   ModelItem   *item;
   const gchar *icon_name;
 
-  g_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (model), NULL);
+  appfinder_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (model), NULL);
 
   if (IS_STRING (command))
     {
@@ -1530,7 +1530,7 @@ xfce_appfinder_model_icon_theme_changed (XfceAppfinderModel *model)
   gboolean     item_changed;
   GSList      *li;
 
-  g_return_if_fail (XFCE_IS_APPFINDER_MODEL (model));
+  appfinder_return_if_fail (XFCE_IS_APPFINDER_MODEL (model));
 
   APPFINDER_DEBUG ("icon theme changed");
 
diff --git a/src/appfinder-private.h b/src/appfinder-private.h
index 67e285d..5b0b5af 100644
--- a/src/appfinder-private.h
+++ b/src/appfinder-private.h
@@ -36,4 +36,16 @@ G_STMT_START { \
 #define APPFINDER_DEBUG(...) G_STMT_START{ (void)0; }G_STMT_END
 #endif
 
+#ifdef DEBUG
+#define appfinder_assert(expr)                 g_assert (expr)
+#define appfinder_assert_not_reached()         g_assert_not_reached ()
+#define appfinder_return_if_fail(expr)         g_return_if_fail (expr)
+#define appfinder_return_val_if_fail(expr,val) g_return_val_if_fail (expr, val)
+#else
+#define appfinder_assert(expr)                 G_STMT_START{ (void)0; }G_STMT_END
+#define appfinder_assert_not_reached()         G_STMT_START{ (void)0; }G_STMT_END
+#define appfinder_return_if_fail(expr)         G_STMT_START{ (void)0; }G_STMT_END
+#define appfinder_return_val_if_fail(expr,val) G_STMT_START{ (void)0; }G_STMT_END
+#endif
+
 #endif /* !__XFCE_APPFINDER_PRIVATE_H__ */
diff --git a/src/appfinder-window.c b/src/appfinder-window.c
index 2af5e3d..1bdd5a1 100644
--- a/src/appfinder-window.c
+++ b/src/appfinder-window.c
@@ -663,7 +663,7 @@ xfce_appfinder_window_category_set_categories (XfceAppfinderWindow *window)
   GtkTreePath *path;
   gchar       *name;
 
-  g_return_if_fail (GTK_IS_TREE_VIEW (window->sidepane));
+  appfinder_return_if_fail (GTK_IS_TREE_VIEW (window->sidepane));
 
   categories = xfce_appfinder_model_get_categories (window->model);
   if (categories != NULL)



More information about the Xfce4-commits mailing list