[Xfce4-commits] <xfdesktop:xfce-4.6> don't misuse the g_return_(val_)?if_fail() macros as much (bug 5791)

Brian J. Tarricone noreply at xfce.org
Mon Oct 19 08:44:01 CEST 2009


Updating branch refs/heads/xfce-4.6
         to 666d693b4044c2ac20b54ebc292d5b0610636c99 (commit)
       from 04a0e9411408d3992269d8327ebf8d2dcb254746 (commit)

commit 666d693b4044c2ac20b54ebc292d5b0610636c99
Author: Brian J. Tarricone <brian at tarricone.org>
Date:   Sun Oct 18 23:42:32 2009 -0700

    don't misuse the g_return_(val_)?if_fail() macros as much (bug 5791)

 src/xfdesktop-file-icon-manager.c      |   51 +++++++++++++++++++++----------
 src/xfdesktop-file-icon.c              |    3 +-
 src/xfdesktop-file-properties-dialog.c |    3 +-
 src/xfdesktop-file-utils.c             |   17 +++++-----
 src/xfdesktop-icon-view.c              |   12 +++++--
 src/xfdesktop-regular-file-icon.c      |   17 +++++++---
 src/xfdesktop-special-file-icon.c      |   14 +++++---
 src/xfdesktop-volume-icon.c            |   14 +++++---
 src/xfdesktop-window-icon-manager.c    |    3 +-
 9 files changed, 88 insertions(+), 46 deletions(-)

diff --git a/src/xfdesktop-file-icon-manager.c b/src/xfdesktop-file-icon-manager.c
index 8873399..a838b55 100644
--- a/src/xfdesktop-file-icon-manager.c
+++ b/src/xfdesktop-file-icon-manager.c
@@ -845,7 +845,8 @@ xfdesktop_file_icon_manager_delete_selected(XfdesktopFileIconManager *fmanager,
     GList *selected, *l;
     
     selected = xfdesktop_icon_view_get_selected_items(fmanager->priv->icon_view);
-    g_return_if_fail(selected);
+    if(!selected)
+        return;
     
     /* remove anybody that's not deletable */
     for(l = selected; l; ) {
@@ -893,7 +894,7 @@ xfdesktop_file_icon_menu_mime_app_executed(GtkWidget *widget,
     XfdesktopFileIcon *icon;
     ThunarVfsMimeApplication *mime_app;
     const ThunarVfsInfo *info;
-    GList *path_list, *selected;
+    GList *path_list = NULL, *selected;
     GtkWidget *toplevel;
     GError *error = NULL;
     
@@ -904,10 +905,13 @@ xfdesktop_file_icon_menu_mime_app_executed(GtkWidget *widget,
     toplevel = gtk_widget_get_toplevel(GTK_WIDGET(fmanager->priv->icon_view));
     
     info = xfdesktop_file_icon_peek_info(icon);
-    path_list = g_list_append(NULL, info->path);
+    path_list = g_list_append(path_list, info->path);
     
     mime_app = g_object_get_qdata(G_OBJECT(widget), xfdesktop_mime_app_quark);
-    g_return_if_fail(mime_app);
+    if(!mime_app) {
+        g_list_free(path_list);
+        return;
+    }
     
     if(!thunar_vfs_mime_handler_exec(THUNAR_VFS_MIME_HANDLER(mime_app),
                                      gtk_widget_get_screen(widget),
@@ -942,7 +946,8 @@ xfdesktop_file_icon_menu_open_folder(GtkWidget *widget,
     g_list_free(selected);
     
     info = xfdesktop_file_icon_peek_info(icon);
-    g_return_if_fail(info);
+    if(!info)
+        return;
     
     toplevel = gtk_widget_get_toplevel(GTK_WIDGET(fmanager->priv->icon_view));
     
@@ -960,7 +965,8 @@ xfdesktop_file_icon_menu_open_desktop(GtkWidget *widget,
     GtkWidget *toplevel;
     
     info = xfdesktop_file_icon_peek_info(icon);
-    g_return_if_fail(info);
+    if(!info)
+        return;
     
     toplevel = gtk_widget_get_toplevel(GTK_WIDGET(fmanager->priv->icon_view));
     
@@ -1009,7 +1015,8 @@ xfdesktop_file_icon_menu_other_app(GtkWidget *widget,
     g_list_free(selected);
     
     info = xfdesktop_file_icon_peek_info(icon);
-    g_return_if_fail(info);
+    if(!info)
+        return;
     
     fileman_proxy = xfdesktop_file_utils_peek_filemanager_proxy();
     if(fileman_proxy) {
@@ -1041,7 +1048,8 @@ xfdesktop_file_icon_menu_cut(GtkWidget *widget,
     GList *files;
     
     files = xfdesktop_icon_view_get_selected_items(fmanager->priv->icon_view);
-    g_return_if_fail(files);
+    if(!files)
+        return;
     
     xfdesktop_clipboard_manager_cut_files(clipboard_manager, files);
     
@@ -1056,7 +1064,8 @@ xfdesktop_file_icon_menu_copy(GtkWidget *widget,
     GList *files;
     
     files = xfdesktop_icon_view_get_selected_items(fmanager->priv->icon_view);
-    g_return_if_fail(files);
+    if(!files)
+        return;
     
     xfdesktop_clipboard_manager_copy_files(clipboard_manager, files);
     
@@ -2804,7 +2813,8 @@ xfdesktop_file_icon_manager_load_removable_media(XfdesktopFileIconManager *fmana
     ThunarVfsVolume *volume;
     
     /* ensure we don't re-enter if we're already set up */
-    g_return_if_fail(!fmanager->priv->removable_icons);
+    if(fmanager->priv->removable_icons)
+        return;
     
     if(!thunar_volume_manager) {
         thunar_volume_manager = thunar_vfs_volume_manager_get_default();
@@ -2850,7 +2860,8 @@ xfdesktop_file_icon_manager_remove_removable_media(XfdesktopFileIconManager *fma
 {
     GList *volumes, *l;
     
-    g_return_if_fail(fmanager->priv->removable_icons);
+    if(!fmanager->priv->removable_icons)
+        return;
     
     volumes = thunar_vfs_volume_manager_get_volumes(thunar_volume_manager);
     for(l = volumes; l; l = l->next) {
@@ -2889,9 +2900,12 @@ xfdesktop_file_icon_manager_real_init(XfdesktopIconViewManager *manager,
 #ifdef HAVE_THUNARX
     ThunarxProviderFactory *thunarx_pfac;
 #endif
-    
-    g_return_val_if_fail(!fmanager->priv->inited, FALSE);
-    
+
+    if(fmanager->priv->inited) {
+        g_warning("Initializing icon manager when already inited");
+        return FALSE;
+    }
+
     fmanager->priv->icon_view = icon_view;
     
     fmanager->priv->desktop = gtk_widget_get_toplevel(GTK_WIDGET(icon_view));
@@ -2992,9 +3006,12 @@ xfdesktop_file_icon_manager_fini(XfdesktopIconViewManager *manager)
 {
     XfdesktopFileIconManager *fmanager = XFDESKTOP_FILE_ICON_MANAGER(manager);
     gint i;
-    
-    g_return_if_fail(fmanager->priv->inited);
-    
+
+    if(!fmanager->priv->inited) {
+        g_warning("Trying to de-init icon manager when it was never inited");
+        return;
+    }
+
     fmanager->priv->inited = FALSE;
     
     if(fmanager->priv->list_job) {
diff --git a/src/xfdesktop-file-icon.c b/src/xfdesktop-file-icon.c
index b4e9bc6..ab32f98 100644
--- a/src/xfdesktop-file-icon.c
+++ b/src/xfdesktop-file-icon.c
@@ -106,7 +106,8 @@ xfdesktop_file_icon_activated(XfdesktopIcon *icon)
     
     TRACE("entering");
     
-    g_return_val_if_fail(info, FALSE);
+    if(!info)
+        return FALSE;
     
     icon_view = xfdesktop_icon_peek_icon_view(icon);
     toplevel = gtk_widget_get_toplevel(icon_view);
diff --git a/src/xfdesktop-file-properties-dialog.c b/src/xfdesktop-file-properties-dialog.c
index d68cde4..ac78962 100644
--- a/src/xfdesktop-file-properties-dialog.c
+++ b/src/xfdesktop-file-properties-dialog.c
@@ -140,7 +140,8 @@ xfdesktop_file_properties_dialog_show(GtkWindow *parent,
     
     g_return_if_fail(icon);
     info = xfdesktop_file_icon_peek_info(icon);
-    g_return_if_fail(info);
+    if(!info)
+        return;
     
     pfd = pango_font_description_from_string("bold");
     gtk_icon_size_lookup(GTK_ICON_SIZE_DIALOG, &dw, &dh);
diff --git a/src/xfdesktop-file-utils.c b/src/xfdesktop-file-utils.c
index bdec471..c7c2233 100644
--- a/src/xfdesktop-file-utils.c
+++ b/src/xfdesktop-file-utils.c
@@ -254,7 +254,10 @@ xfdesktop_file_utils_get_file_icon(const gchar *custom_icon_name,
         pix = xfdesktop_file_utils_get_fallback_icon(size);
     
     /* sanity check */
-    g_return_val_if_fail(pix, NULL);
+    if(G_UNLIKELY(!pix)) {
+        g_warning("Unable to find fallback icon");
+        return NULL;
+    }
     
     if(emblem) {
         gint emblem_pix_size = gdk_pixbuf_get_width(emblem);
@@ -377,7 +380,7 @@ xfdesktop_file_utils_display_folder_cb(DBusGProxy *proxy,
 {
     XfdesktopDisplayFolderData *dfdata = user_data;
     
-    g_return_if_fail(user_data);
+    g_return_if_fail(dfdata);
     
     xfdesktop_file_utils_set_window_cursor(dfdata->parent, GDK_LEFT_PTR);
     
@@ -525,9 +528,8 @@ xfdesktop_thunarx_file_info_get_uri(ThunarxFileInfo *file_info)
     if(!info)
         return NULL;
         
-    g_return_val_if_fail(thunar_vfs_path_to_uri(info->path, buf, PATH_MAX,
-                                                NULL) > 0,
-                         NULL);
+    if(thunar_vfs_path_to_uri(info->path, buf, PATH_MAX, NULL) <= 0)
+        return NULL;
     
     return g_strdup(buf);
 }
@@ -548,9 +550,8 @@ xfdesktop_thunarx_file_info_get_parent_uri(ThunarxFileInfo *file_info)
     if(G_UNLIKELY(!parent))
         return NULL;
     
-    g_return_val_if_fail(thunar_vfs_path_to_uri(parent, buf, PATH_MAX,
-                                                NULL) > 0,
-                         NULL);
+    if(thunar_vfs_path_to_uri(parent, buf, PATH_MAX, NULL) <= 0)
+        return NULL;
     
     return g_strdup(buf);
 }
diff --git a/src/xfdesktop-icon-view.c b/src/xfdesktop-icon-view.c
index afa6c51..0d7ba89 100644
--- a/src/xfdesktop-icon-view.c
+++ b/src/xfdesktop-icon-view.c
@@ -2943,7 +2943,10 @@ xfdesktop_grid_unset_position_free(XfdesktopIconView *icon_view,
 {
     guint16 row, col;
     
-    g_return_val_if_fail(xfdesktop_icon_get_position(icon, &row, &col), FALSE);
+    if(!xfdesktop_icon_get_position(icon, &row, &col)) {
+        g_warning("Trying to set free position of an icon with no position");
+        return FALSE;
+    }
     
     return xfdesktop_grid_unset_position_free_raw(icon_view, row, col, icon);
 }
@@ -3043,7 +3046,7 @@ xfdesktop_icon_view_new(XfdesktopIconViewManager *manager)
 {
     XfdesktopIconView *icon_view;
     
-    g_return_val_if_fail(manager, NULL);
+    g_return_val_if_fail(XFDESKTOP_IS_ICON_VIEW_MANAGER(manager), NULL);
     
     icon_view = g_object_new(XFDESKTOP_TYPE_ICON_VIEW, NULL);
     icon_view->priv->manager = manager;
@@ -3059,7 +3062,10 @@ xfdesktop_icon_view_add_item_internal(XfdesktopIconView *icon_view,
     GdkRectangle fake_area;
     
     /* sanity check: at this point this should be taken care of */
-    g_return_if_fail(xfdesktop_icon_get_position(icon, &row, &col));
+    if(!xfdesktop_icon_get_position(icon, &row, &col)) {
+        g_warning("Attempting to add item without a position");
+        return;
+    }
     
     xfdesktop_grid_unset_position_free(icon_view, icon);
     
diff --git a/src/xfdesktop-regular-file-icon.c b/src/xfdesktop-regular-file-icon.c
index ab1f6c7..54ab849 100644
--- a/src/xfdesktop-regular-file-icon.c
+++ b/src/xfdesktop-regular-file-icon.c
@@ -254,7 +254,8 @@ xfdesktop_regular_file_icon_get_allowed_drag_actions(XfdesktopIcon *icon)
     const ThunarVfsInfo *info = xfdesktop_file_icon_peek_info(XFDESKTOP_FILE_ICON(icon));
     GdkDragAction actions = GDK_ACTION_LINK;  /* we can always link */
     
-    g_return_val_if_fail(info, 0);
+    if(!info)
+        return 0;
     
     if(info->flags & THUNAR_VFS_FILE_FLAGS_READABLE) {
         ThunarVfsPath *parent_path;
@@ -282,7 +283,8 @@ xfdesktop_regular_file_icon_get_allowed_drop_actions(XfdesktopIcon *icon)
 {
     const ThunarVfsInfo *info = xfdesktop_file_icon_peek_info(XFDESKTOP_FILE_ICON(icon));
     
-    g_return_val_if_fail(info, 0);
+    if(!info)
+        return 0;
     
     /* if it's executable we can 'copy'.  if it's a folder we can do anything
      * if it's writable. */
@@ -307,7 +309,10 @@ xfdesktop_regular_file_icon_drag_job_error(ThunarVfsJob *job,
     XfdesktopFileUtilsFileop fileop = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(job),
                                                                         "--xfdesktop-file-icon-action"));
     
-    g_return_if_fail(regular_file_icon && src_file_icon);
+    g_return_if_fail(regular_file_icon);
+    
+    if(!src_file_icon)
+        return;
     
     xfdesktop_file_utils_handle_fileop_error(NULL,
                                              xfdesktop_file_icon_peek_info(src_file_icon),
@@ -400,11 +405,13 @@ xfdesktop_regular_file_icon_do_drop_dest(XfdesktopIcon *icon,
             return FALSE;
         
         name = thunar_vfs_path_get_name(src_info->path);
-        g_return_val_if_fail(name, FALSE);
+        if(!name)
+            return FALSE;
         
         dest_path = thunar_vfs_path_relative(regular_file_icon->priv->info->path,
                                              name);
-        g_return_val_if_fail(dest_path, FALSE);
+        if(!dest_path)
+            return FALSE;
         
         switch(action) {
             case GDK_ACTION_MOVE:
diff --git a/src/xfdesktop-special-file-icon.c b/src/xfdesktop-special-file-icon.c
index bab1f82..efc6b46 100644
--- a/src/xfdesktop-special-file-icon.c
+++ b/src/xfdesktop-special-file-icon.c
@@ -333,7 +333,10 @@ xfdesktop_special_file_icon_drag_job_error(ThunarVfsJob *job,
                                                                         "--xfdesktop-file-icon-action"));
     const ThunarVfsInfo *src_info = xfdesktop_file_icon_peek_info(src_file_icon);
     
-    g_return_if_fail(special_file_icon && src_file_icon);
+    g_return_if_fail(special_file_icon);
+
+    if(!src_file_icon)
+        return;
     
     xfdesktop_file_utils_handle_fileop_error(NULL, src_info,
                                              special_file_icon->priv->info,
@@ -386,8 +389,7 @@ xfdesktop_special_file_icon_do_drop_dest(XfdesktopIcon *icon,
     
     DBG("entering");
     
-    g_return_val_if_fail(special_file_icon && src_file_icon,
-                         FALSE);
+    g_return_val_if_fail(special_file_icon && src_file_icon, FALSE);
     g_return_val_if_fail(xfdesktop_special_file_icon_get_allowed_drop_actions(icon),
                          FALSE);
     
@@ -399,11 +401,13 @@ xfdesktop_special_file_icon_do_drop_dest(XfdesktopIcon *icon,
         return FALSE;
     
     name = thunar_vfs_path_get_name(src_info->path);
-    g_return_val_if_fail(name, FALSE);
+    if(!name)
+        return FALSE;
     
     dest_path = thunar_vfs_path_relative(special_file_icon->priv->info->path,
                                          name);
-    g_return_val_if_fail(dest_path, FALSE);
+    if(!dest_path)
+        return FALSE;
     
     if(special_file_icon->priv->type == XFDESKTOP_SPECIAL_FILE_ICON_TRASH)  {
         /* any drop to the trash is a move */
diff --git a/src/xfdesktop-volume-icon.c b/src/xfdesktop-volume-icon.c
index 9de606d..94e5bb2 100644
--- a/src/xfdesktop-volume-icon.c
+++ b/src/xfdesktop-volume-icon.c
@@ -310,7 +310,10 @@ xfdesktop_volume_icon_drag_job_error(ThunarVfsJob *job,
                                                                         "--xfdesktop-file-icon-action"));
     const ThunarVfsInfo *src_info = xfdesktop_file_icon_peek_info(src_file_icon);
     
-    g_return_if_fail(volume_icon && src_file_icon);
+    g_return_if_fail(volume_icon);
+    
+    if(!src_file_icon)
+        return;
     
     xfdesktop_file_utils_handle_fileop_error(NULL, src_info,
                                              volume_icon->priv->info,
@@ -363,8 +366,7 @@ xfdesktop_volume_icon_do_drop_dest(XfdesktopIcon *icon,
     
     DBG("entering");
     
-    g_return_val_if_fail(volume_icon && src_file_icon,
-                         FALSE);
+    g_return_val_if_fail(volume_icon && src_file_icon, FALSE);
     g_return_val_if_fail(xfdesktop_volume_icon_get_allowed_drop_actions(icon),
                          FALSE);
     
@@ -376,11 +378,13 @@ xfdesktop_volume_icon_do_drop_dest(XfdesktopIcon *icon,
         return FALSE;
     
     name = thunar_vfs_path_get_name(src_info->path);
-    g_return_val_if_fail(name, FALSE);
+    if(!name)
+        return FALSE;
         
     dest_path = thunar_vfs_path_relative(volume_icon->priv->info->path,
                                          name);
-    g_return_val_if_fail(dest_path, FALSE);
+    if(!dest_path)
+        return FALSE;
     
     switch(action) {
         case GDK_ACTION_MOVE:
diff --git a/src/xfdesktop-window-icon-manager.c b/src/xfdesktop-window-icon-manager.c
index ff414e7..4a63ef7 100644
--- a/src/xfdesktop-window-icon-manager.c
+++ b/src/xfdesktop-window-icon-manager.c
@@ -389,7 +389,8 @@ window_state_changed_cb(WnckWindow *window,
         i = 0;
         max_i = wmanager->priv->nworkspaces;
     } else {
-        g_return_if_fail(ws_num != -1);
+        if(ws_num == -1)
+            return;
         i = ws_num;
         max_i = i + 1;
     }



More information about the Xfce4-commits mailing list