[Xfce4-commits] <xfdesktop:master> 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:02 CEST 2009


Updating branch refs/heads/master
         to 9727fa646f0a5c7f476e863bf63c6542b5f603b6 (commit)
       from f180721dc5313b68f55296ce06c76b7e4ea22817 (commit)

commit 9727fa646f0a5c7f476e863bf63c6542b5f603b6
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 7e66215..be4a810 100644
--- a/src/xfdesktop-file-icon-manager.c
+++ b/src/xfdesktop-file-icon-manager.c
@@ -846,7 +846,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; ) {
@@ -894,7 +895,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;
     
@@ -905,10 +906,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),
@@ -943,7 +947,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));
     
@@ -961,7 +966,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));
     
@@ -1010,7 +1016,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) {
@@ -1042,7 +1049,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);
     
@@ -1057,7 +1065,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);
     
@@ -2848,7 +2857,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();
@@ -2894,7 +2904,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) {
@@ -2933,9 +2944,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));
@@ -3036,9 +3050,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 e96a9a7..4c97463 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 96ca2b1..0c51381 100644
--- a/src/xfdesktop-file-properties-dialog.c
+++ b/src/xfdesktop-file-properties-dialog.c
@@ -141,7 +141,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 42bf1dd..498e547 100644
--- a/src/xfdesktop-file-utils.c
+++ b/src/xfdesktop-file-utils.c
@@ -262,7 +262,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);
@@ -384,7 +387,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);
     
@@ -532,9 +535,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);
 }
@@ -555,9 +557,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 5eb822a..db36a74 100644
--- a/src/xfdesktop-icon-view.c
+++ b/src/xfdesktop-icon-view.c
@@ -3041,7 +3041,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);
 }
@@ -3151,7 +3154,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;
@@ -3167,7 +3170,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 898e4e7..ced25f9 100644
--- a/src/xfdesktop-regular-file-icon.c
+++ b/src/xfdesktop-regular-file-icon.c
@@ -258,7 +258,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;
@@ -286,7 +287,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. */
@@ -311,7 +313,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),
@@ -404,11 +409,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 5e8c602..e448a60 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 12ca833..4b3648a 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 4b0f262..491e307 100644
--- a/src/xfdesktop-window-icon-manager.c
+++ b/src/xfdesktop-window-icon-manager.c
@@ -390,7 +390,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