moved GFunc cast to macro GFUNC_COMPAT_CAST
authorFriedrich Beckmann <friedrich.beckmann@gmx.de>
Sun, 30 Aug 2020 12:56:21 +0000 (14:56 +0200)
committerFriedrich Beckmann <friedrich.beckmann@gmx.de>
Sun, 30 Aug 2020 12:56:21 +0000 (14:56 +0200)
I moved the GFunc cast for g_list_foreach to a macro with
some explaining comment. The macro is in helper.h

src/ui/gui/helper.h
src/ui/gui/psppire-acr.c
src/ui/gui/psppire-dialog-action-autorecode.c
src/ui/gui/psppire-dialog-action-recode-different.c
src/ui/gui/psppire-selector.c

index c1d93a8c033dbc5db277a74e9a109251a2bbd654..8d18fcf4b44e4b318d5bb29eb4686f389d77afa7 100644 (file)
@@ -65,5 +65,13 @@ psppire_box_pack_start_defaults (GtkBox *box, GtkWidget *widget)
   gtk_box_pack_start (box, widget, TRUE, TRUE, 0);
 }
 
+/* Starting with gcc8 the warning Wcast-function-type will
+   trigger if no intermediate (void (*)(void)) cast is done
+   for a function cast to GFunc when the number of parameters
+   is not 2. The reason is that the compiler behaviour in this
+   situation is undefined according to C standard although many
+   implementations rely on this. */
+#define GFUNC_COMPAT_CAST(x) ((GFunc) (void (*)(void)) (x))
+
 #endif
 
index 82f9aa2c16231969454ec16583e0d8671d69830a..0b397fe3dcbd97edc8a65462a4294a42a3d255b6 100644 (file)
@@ -183,7 +183,7 @@ on_change_button_clicked (PsppireAcr *acr)
       g_value_unset (&value);
     }
 
-  g_list_foreach (l, (GFunc) (void (*)(void)) gtk_tree_path_free, NULL);
+  g_list_foreach (l, GFUNC_COMPAT_CAST (gtk_tree_path_free), NULL);
   g_list_free (l);
 
   if (acr->update) acr->update (acr->update_data);
@@ -209,7 +209,7 @@ on_remove_button_clicked (PsppireAcr *acr)
 
   gtk_list_store_remove (acr->list_store, &iter);
 
-  g_list_foreach (l, (GFunc) (void (*)(void)) gtk_tree_path_free, NULL);
+  g_list_foreach (l, GFUNC_COMPAT_CAST (gtk_tree_path_free), NULL);
   g_list_free (l);
 }
 
@@ -225,7 +225,7 @@ row_is_selected (const PsppireAcr *acr)
 
   result = (l != NULL);
 
-  g_list_foreach (l, (GFunc) (void (*)(void)) gtk_tree_path_free, NULL);
+  g_list_foreach (l, GFUNC_COMPAT_CAST (gtk_tree_path_free), NULL);
   g_list_free (l);
 
   return result;
index a2ec9739840b4b2b9679073e5fc891118813e860..2f1bdcbecbe7986ebd12e7b984b4d69bcd4fd0f6 100644 (file)
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include "psppire-dialog.h"
 #include "builder-wrapper.h"
+#include "helper.h"
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
@@ -192,7 +193,7 @@ on_change_clicked (GObject *obj, gpointer data)
   gtk_tree_model_row_changed (model, rows->data, &iter);
 
  finish:
-  g_list_foreach (rows, (GFunc) (void (*)(void)) gtk_tree_path_free, NULL);
+  g_list_foreach (rows, GFUNC_COMPAT_CAST (gtk_tree_path_free), NULL);
   g_list_free (rows);
   var_unref (var);
 }
@@ -275,7 +276,7 @@ on_selection_change (GtkTreeSelection *selection, gpointer data)
       gtk_widget_set_sensitive  (rd->change_button, FALSE);
     }
 
-  g_list_foreach (rows, (GFunc) (void (*)(void)) gtk_tree_path_free, NULL);
+  g_list_foreach (rows, GFUNC_COMPAT_CAST (gtk_tree_path_free), NULL);
   g_list_free (rows);
 }
 
index 594f8bc9a28bec923764cb89e8c00534859e78eb..a49d05306ea1f17820d3b429a17dc2374374a505 100644 (file)
@@ -208,7 +208,7 @@ on_change_clicked (GObject *obj, gpointer data)
   gtk_tree_model_row_changed (model, rows->data, &iter);
 
  finish:
-  g_list_foreach (rows, (GFunc) (void (*)(void)) gtk_tree_path_free, NULL);
+  g_list_foreach (rows, GFUNC_COMPAT_CAST (gtk_tree_path_free), NULL);
   g_list_free (rows);
 }
 
@@ -272,7 +272,7 @@ on_selection_change (GtkTreeSelection *selection, gpointer data)
     }
 
 
-  g_list_foreach (rows, (GFunc) (void (*)(void)) gtk_tree_path_free, NULL);
+  g_list_foreach (rows, GFUNC_COMPAT_CAST (gtk_tree_path_free), NULL);
   g_list_free (rows);
 }
 
index a551573fe9b215d2cf1b30c1361d661361f7ef75..678c2a749f240af62e12219cb58b4006ae15af8f 100644 (file)
@@ -62,6 +62,7 @@
 #include "psppire-dict.h"
 #include "psppire-select-dest.h"
 #include "psppire-means-layer.h"
+#include "helper.h"
 
 #include <gtk/gtk.h>
 
@@ -575,7 +576,7 @@ de_select_tree_model (GtkTreeSelection *selection, GtkTreeModel *model)
     }
 
   /* Delete list of RowRefs and its contents */
-  g_list_foreach (selected_rows, (GFunc) (void (*)(void)) gtk_tree_row_reference_free, NULL);
+  g_list_foreach (selected_rows, GFUNC_COMPAT_CAST (gtk_tree_row_reference_free), NULL);
   g_list_free (selected_rows);
 }
 
@@ -662,7 +663,7 @@ select_selection (PsppireSelector *selector)
                        );
     }
 
-  g_list_foreach (selected_rows, (GFunc) (void (*)(void)) gtk_tree_path_free, NULL);
+  g_list_foreach (selected_rows, GFUNC_COMPAT_CAST (gtk_tree_path_free), NULL);
   g_list_free (selected_rows);
 
   refilter (selector);