]> granicus.if.org Git - transmission/commitdiff
Fix -Wcast-function-type warnings in GTK+ app code
authorCharles Kerr <ckerr@github.com>
Sat, 26 Oct 2019 22:16:01 +0000 (17:16 -0500)
committerCharles Kerr <ckerr@github.com>
Sat, 26 Oct 2019 22:16:01 +0000 (17:16 -0500)
https://gitlab.gnome.org/GNOME/gnome-terminal/issues/96 talks about both
the issue and its solution.

GCC 8's -Wcast-function-type, enabled by -Wextra, is problematic in glib
applications because it's idiomatic there to recast function signatures,
e.g. `g_slist_free(list, (GFunc)g_free, NULL);`.

Disabling the warning with pragmas causes "unrecognized pragma" warnings
on clang and older versions of gcc, and disabling the warning could miss
actual bugs. GCC defines `void (*)(void)` as a special case that matches
anything so we can silence warnings by double-casting through GCallback.

In the previous example, the warning is silenced by changing the code to
read `g_slist_free(list, (GFunc)(GCallback)g_free, NULL);`).

gtk/main.c
gtk/notify.c
gtk/open-dialog.c
gtk/tr-core.c

index 8f12360a03461f271eecc1a674f493b4aca50314..d2b522896c3337eaa2bbc15fa5dd637f80a9c935 100644 (file)
@@ -533,7 +533,7 @@ static void on_startup(GApplication* application, gpointer user_data)
     win = GTK_WINDOW(gtr_window_new(GTK_APPLICATION(application), ui_manager, cbdata->core));
     g_signal_connect(win, "size-allocate", G_CALLBACK(on_main_window_size_allocated), cbdata);
     g_application_hold(application);
-    g_object_weak_ref(G_OBJECT(win), (GWeakNotify)g_application_release, application);
+    g_object_weak_ref(G_OBJECT(win), (GWeakNotify)(GCallback)g_application_release, application);
     app_setup(win, cbdata);
     tr_sessionSetRPCCallback(session, on_rpc_changed, cbdata);
 
@@ -848,7 +848,7 @@ static void on_drag_data_received(GtkWidget* widget UNUSED, GdkDragContext* drag
     open_files(files, gdata);
 
     /* cleanup */
-    g_slist_foreach(files, (GFunc)g_object_unref, NULL);
+    g_slist_foreach(files, (GFunc)(GCallback)g_object_unref, NULL);
     g_slist_free(files);
     g_strfreev(uris);
 
@@ -885,7 +885,7 @@ static gboolean on_session_closed(gpointer gdata)
     struct cbdata* cbdata = gdata;
 
     tmp = g_slist_copy(cbdata->details);
-    g_slist_foreach(tmp, (GFunc)gtk_widget_destroy, NULL);
+    g_slist_foreach(tmp, (GFunc)(GCallback)gtk_widget_destroy, NULL);
     g_slist_free(tmp);
 
     if (cbdata->prefs != NULL)
@@ -905,9 +905,9 @@ static gboolean on_session_closed(gpointer gdata)
         g_object_unref(cbdata->icon);
     }
 
-    g_slist_foreach(cbdata->error_list, (GFunc)g_free, NULL);
+    g_slist_foreach(cbdata->error_list, (GFunc)(GCallback)g_free, NULL);
     g_slist_free(cbdata->error_list);
-    g_slist_foreach(cbdata->duplicates_list, (GFunc)g_free, NULL);
+    g_slist_foreach(cbdata->duplicates_list, (GFunc)(GCallback)g_free, NULL);
     g_slist_free(cbdata->duplicates_list);
 
     return G_SOURCE_REMOVE;
@@ -1031,7 +1031,7 @@ static void show_torrent_errors(GtkWindow* window, char const* primary, GSList**
     gtk_widget_show(w);
     g_string_free(s, TRUE);
 
-    g_slist_foreach(*files, (GFunc)g_free, NULL);
+    g_slist_foreach(*files, (GFunc)(GCallback)g_free, NULL);
     g_slist_free(*files);
     *files = NULL;
 }
@@ -1488,7 +1488,7 @@ static tr_torrent* get_first_selected_torrent(struct cbdata* data)
         }
     }
 
-    g_list_foreach(l, (GFunc)gtk_tree_path_free, NULL);
+    g_list_foreach(l, (GFunc)(GCallback)gtk_tree_path_free, NULL);
     g_list_free(l);
     return tor;
 }
index 4b2bf6b778bd1c98074d6ed12fb55ffff6be6b91..1a31e102f6c72dcab258fad1aaff8ac636c47072 100644 (file)
@@ -191,7 +191,8 @@ void gtr_notify_torrent_completed(TrCore* core, int torrent_id)
     tor = gtr_core_find_torrent(core, torrent_id);
 
     n = g_new0(TrNotification, 1);
-    n->core = g_object_ref(G_OBJECT(core));
+    g_object_ref(G_OBJECT(core));
+    n->core = core;
     n->torrent_id = torrent_id;
 
     g_variant_builder_init(&actions_builder, G_VARIANT_TYPE("as"));
index 01ade625817c34cd4b2be26156a050d74343088a..93b7b32a143ffef842da8c6f90be258f12b8d2a1 100644 (file)
@@ -84,7 +84,7 @@ static void save_recent_destination(TrCore* core, char const* dir)
     gtr_pref_save(gtr_core_session(core));
 
     /* cleanup */
-    g_slist_foreach(list, (GFunc)g_free, NULL);
+    g_slist_foreach(list, (GFunc)(GCallback)g_free, NULL);
     g_slist_free(list);
 }
 
@@ -440,7 +440,7 @@ static void onOpenDialogResponse(GtkDialog* dialog, int response, gpointer core)
         GSList* files = gtk_file_chooser_get_files(chooser);
 
         gtr_core_add_files(core, files, do_start, do_prompt, do_notify);
-        g_slist_foreach(files, (GFunc)g_object_unref, NULL);
+        g_slist_foreach(files, (GFunc)(GCallback)g_object_unref, NULL);
         g_slist_free(files);
     }
 
index f62d777d530694784c83604f66e65233390f4bca..9b3c9238b87931f391ef189d92546fa16ecd16ce 100644 (file)
@@ -742,7 +742,7 @@ static gboolean core_watchdir_idle(gpointer gcore)
 
         core->priv->adding_from_watch_dir = TRUE;
         gtr_core_add_files(core, unchanging, do_start, do_prompt, TRUE);
-        g_slist_foreach(unchanging, (GFunc)rename_torrent_and_unref_file, NULL);
+        g_slist_foreach(unchanging, (GFunc)(GCallback)rename_torrent_and_unref_file, NULL);
         g_slist_free(unchanging);
         core->priv->adding_from_watch_dir = FALSE;
     }