[Xfce4-commits] [apps/mousepad] 01/01: Fix a bunch of minor compiler warnings

noreply at xfce.org noreply at xfce.org
Mon Jul 14 23:38:19 CEST 2014


This is an automated email from the git hooks/post-receive script.

mbrush pushed a commit to branch master
in repository apps/mousepad.

commit 58adbe72f42976da32fad2dd1e1c894baa97eb5a
Author: Matthew Brush <mbrush at codebrainz.ca>
Date:   Mon Jul 14 14:36:49 2014 -0700

    Fix a bunch of minor compiler warnings
    
    The flags used were:
    
        -Wall -Wextra -Wno-unused-parameter -Wno-overlength-strings
        -std=c99 -pedantic
    
    The `-Wno-overlength-strings` is needed because we use a tool to convert
    text files into C strings that are compiled into the program. Strictly
    speaking this is non-standard behaviour as the standard defines a maximum
    length of a string literal (probably from the old days when compilers didn't
    have enough memory available to handle them?).
    
    Most of the "fixes" were extremely trivial:
    
    * Don't forward declare enums with typedef and then define them.
    * Remove semi-colon after `G_DEFINE_TYPE()` since after the macro is expanded
      it leaves a stray semi-colon in the file.
    * Add wrapper macro+function `mousepad_disconnect_by_func` to hide the fact
      that GLib's macros are passing our `GCallback` as a gpointer, which is not
      valid C but happens to work most of the time. The new function uses a union
      hack (having same issues as existing) to trick the compiler and a
      function-like wrapper macro to cast the callback function parameter to
      `GCallback` so we still don't need to put `G_CALLBACK()` casts everywhere
      in the code that uses it.
    
    There's still quite a few warnings left but they are not in our code or are
    in our generated code. For example with my version of headers Pango is using
    values outside the range of `int` as enum values and the generated code for
    `mousepad-marshal.c` and `mousepad-dbus-infos.h` is treating function
    pointers like void pointers as mentioned above.
---
 mousepad/mousepad-application.c     |    5 +++--
 mousepad/mousepad-dbus.c            |    2 +-
 mousepad/mousepad-document.c        |    2 +-
 mousepad/mousepad-encoding-dialog.c |    2 +-
 mousepad/mousepad-encoding.h        |    6 +++---
 mousepad/mousepad-file.c            |    2 +-
 mousepad/mousepad-file.h            |    6 +++---
 mousepad/mousepad-print.c           |    2 +-
 mousepad/mousepad-private.h         |   22 +++++++++++++++++++
 mousepad/mousepad-replace-dialog.c  |    2 +-
 mousepad/mousepad-search-bar.c      |    2 +-
 mousepad/mousepad-statusbar.c       |    2 +-
 mousepad/mousepad-util.h            |    7 +++---
 mousepad/mousepad-view.c            |    2 +-
 mousepad/mousepad-view.h            |    1 -
 mousepad/mousepad-window.c          |   40 +++++++++++++++++------------------
 16 files changed, 63 insertions(+), 42 deletions(-)

diff --git a/mousepad/mousepad-application.c b/mousepad/mousepad-application.c
index b1725c5..ac3bc99 100644
--- a/mousepad/mousepad-application.c
+++ b/mousepad/mousepad-application.c
@@ -25,6 +25,7 @@
 #include <mousepad/mousepad-prefs-dialog.h>
 #include <mousepad/mousepad-replace-dialog.h>
 #include <mousepad/mousepad-window.h>
+#include <mousepad/mousepad-private.h>
 
 
 
@@ -60,7 +61,7 @@ struct _MousepadApplication
 
 
 
-G_DEFINE_TYPE (MousepadApplication, mousepad_application, G_TYPE_OBJECT);
+G_DEFINE_TYPE (MousepadApplication, mousepad_application, G_TYPE_OBJECT)
 
 
 
@@ -126,7 +127,7 @@ mousepad_application_finalize (GObject *object)
   /* destroy the windows if they are still opened */
   for (li = application->windows; li != NULL; li = li->next)
     {
-      g_signal_handlers_disconnect_by_func (G_OBJECT (li->data), G_CALLBACK (mousepad_application_window_destroyed), application);
+      mousepad_disconnect_by_func (G_OBJECT (li->data), mousepad_application_window_destroyed, application);
       gtk_widget_destroy (GTK_WIDGET (li->data));
     }
 
diff --git a/mousepad/mousepad-dbus.c b/mousepad/mousepad-dbus.c
index 8b7e769..ad45fca 100644
--- a/mousepad/mousepad-dbus.c
+++ b/mousepad/mousepad-dbus.c
@@ -69,7 +69,7 @@ struct _MousepadDBusService
 
 
 
-G_DEFINE_TYPE (MousepadDBusService, mousepad_dbus_service, G_TYPE_OBJECT);
+G_DEFINE_TYPE (MousepadDBusService, mousepad_dbus_service, G_TYPE_OBJECT)
 
 
 
diff --git a/mousepad/mousepad-document.c b/mousepad/mousepad-document.c
index e92c7d1..19d6886 100644
--- a/mousepad/mousepad-document.c
+++ b/mousepad/mousepad-document.c
@@ -112,7 +112,7 @@ mousepad_document_new (void)
 
 
 
-G_DEFINE_TYPE (MousepadDocument, mousepad_document, GTK_TYPE_SCROLLED_WINDOW);
+G_DEFINE_TYPE (MousepadDocument, mousepad_document, GTK_TYPE_SCROLLED_WINDOW)
 
 
 
diff --git a/mousepad/mousepad-encoding-dialog.c b/mousepad/mousepad-encoding-dialog.c
index 9a0fc3e..f91500a 100644
--- a/mousepad/mousepad-encoding-dialog.c
+++ b/mousepad/mousepad-encoding-dialog.c
@@ -94,7 +94,7 @@ struct _MousepadEncodingDialog
 
 
 
-G_DEFINE_TYPE (MousepadEncodingDialog, mousepad_encoding_dialog, GTK_TYPE_DIALOG);
+G_DEFINE_TYPE (MousepadEncodingDialog, mousepad_encoding_dialog, GTK_TYPE_DIALOG)
 
 
 
diff --git a/mousepad/mousepad-encoding.h b/mousepad/mousepad-encoding.h
index eee8528..5addfe1 100644
--- a/mousepad/mousepad-encoding.h
+++ b/mousepad/mousepad-encoding.h
@@ -19,10 +19,9 @@
 
 G_BEGIN_DECLS
 
-typedef enum   _MousepadEncoding     MousepadEncoding;
 typedef struct _MousepadEncodingInfo MousepadEncodingInfo;
 
-enum _MousepadEncoding
+typedef enum
 {
   MOUSEPAD_ENCODING_NONE,
   MOUSEPAD_ENCODING_CUSTOM,
@@ -96,7 +95,8 @@ enum _MousepadEncoding
   MOUSEPAD_ENCODING_WINDOWS_1256,
   MOUSEPAD_ENCODING_WINDOWS_1257,
   MOUSEPAD_ENCODING_WINDOWS_1258
-};
+}
+MousepadEncoding;
 
 struct _MousepadEncodingInfo
 {
diff --git a/mousepad/mousepad-file.c b/mousepad/mousepad-file.c
index 48130fe..b2b2904 100644
--- a/mousepad/mousepad-file.c
+++ b/mousepad/mousepad-file.c
@@ -99,7 +99,7 @@ static guint file_signals[LAST_SIGNAL];
 
 
 
-G_DEFINE_TYPE (MousepadFile, mousepad_file, G_TYPE_OBJECT);
+G_DEFINE_TYPE (MousepadFile, mousepad_file, G_TYPE_OBJECT)
 
 
 
diff --git a/mousepad/mousepad-file.h b/mousepad/mousepad-file.h
index 1b1ed94..2b2f519 100644
--- a/mousepad/mousepad-file.h
+++ b/mousepad/mousepad-file.h
@@ -23,7 +23,6 @@ G_BEGIN_DECLS
 
 typedef struct _MousepadFileClass  MousepadFileClass;
 typedef struct _MousepadFile       MousepadFile;
-typedef enum   _MousepadLineEnding MousepadLineEnding;
 
 #define MOUSEPAD_TYPE_FILE            (mousepad_file_get_type ())
 #define MOUSEPAD_FILE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), MOUSEPAD_TYPE_FILE, MousepadFile))
@@ -32,12 +31,13 @@ typedef enum   _MousepadLineEnding MousepadLineEnding;
 #define MOUSEPAD_IS_FILE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOUSEPAD_TYPE_FILE))
 #define MOUSEPAD_FILE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), MOUSEPAD_TYPE_FILE, MousepadFileClass))
 
-enum _MousepadLineEnding
+typedef enum
 {
   MOUSEPAD_EOL_UNIX,
   MOUSEPAD_EOL_MAC,
   MOUSEPAD_EOL_DOS
-};
+}
+MousepadLineEnding;
 
 GType               mousepad_file_get_type                 (void) G_GNUC_CONST;
 
diff --git a/mousepad/mousepad-print.c b/mousepad/mousepad-print.c
index 2a97b45..13c478f 100644
--- a/mousepad/mousepad-print.c
+++ b/mousepad/mousepad-print.c
@@ -89,7 +89,7 @@ struct _MousepadPrint
 
 
 
-G_DEFINE_TYPE (MousepadPrint, mousepad_print, GTK_TYPE_PRINT_OPERATION);
+G_DEFINE_TYPE (MousepadPrint, mousepad_print, GTK_TYPE_PRINT_OPERATION)
 
 
 
diff --git a/mousepad/mousepad-private.h b/mousepad/mousepad-private.h
index ebdc5b5..422e916 100644
--- a/mousepad/mousepad-private.h
+++ b/mousepad/mousepad-private.h
@@ -122,6 +122,28 @@ enum
 #define mousepad_widget_set_tooltip_text(widget,text) (mousepad_util_set_tooltip (widget, text))
 #endif
 
+/* GLib does some questionable (ie. non-standard) stuff when passing function
+ * pointers as void pointers and such. This dirty little hack will at least
+ * squelch warnings about it so we can easily see warnings that we can
+ * actually fix in our code. */
+static inline guint
+mousepad_disconnect_by_func_ (gpointer  instance,
+                              GCallback callback,
+                              gpointer  data)
+{
+  union {
+      gpointer  ptr;
+      GCallback callback;
+  } bad_stuff;
+  /* we'll set it in the union as a GCallback type */
+  bad_stuff.callback = callback;
+  /* but we'll use it via the gpointer type */
+  return g_signal_handlers_disconnect_by_func (instance, bad_stuff.ptr, data);
+}
+
+#define mousepad_disconnect_by_func(instance, callback, data) \
+  mousepad_disconnect_by_func_ (instance, G_CALLBACK (callback), data)
+
 G_END_DECLS
 
 #endif /* !__MOUSEPAD_PRIVATE_H__ */
diff --git a/mousepad/mousepad-replace-dialog.c b/mousepad/mousepad-replace-dialog.c
index 6426453..bfec4c6 100644
--- a/mousepad/mousepad-replace-dialog.c
+++ b/mousepad/mousepad-replace-dialog.c
@@ -90,7 +90,7 @@ static guint   dialog_signals[LAST_SIGNAL];
 
 
 
-G_DEFINE_TYPE (MousepadReplaceDialog, mousepad_replace_dialog, GTK_TYPE_DIALOG);
+G_DEFINE_TYPE (MousepadReplaceDialog, mousepad_replace_dialog, GTK_TYPE_DIALOG)
 
 
 static void
diff --git a/mousepad/mousepad-search-bar.c b/mousepad/mousepad-search-bar.c
index 1f86fc2..26c2845 100644
--- a/mousepad/mousepad-search-bar.c
+++ b/mousepad/mousepad-search-bar.c
@@ -103,7 +103,7 @@ mousepad_search_bar_new (void)
 
 
 
-G_DEFINE_TYPE (MousepadSearchBar, mousepad_search_bar, GTK_TYPE_TOOLBAR);
+G_DEFINE_TYPE (MousepadSearchBar, mousepad_search_bar, GTK_TYPE_TOOLBAR)
 
 
 
diff --git a/mousepad/mousepad-statusbar.c b/mousepad/mousepad-statusbar.c
index 84f722b..a1cdcf2 100644
--- a/mousepad/mousepad-statusbar.c
+++ b/mousepad/mousepad-statusbar.c
@@ -66,7 +66,7 @@ static guint statusbar_signals[LAST_SIGNAL];
 
 
 
-G_DEFINE_TYPE (MousepadStatusbar, mousepad_statusbar, GTK_TYPE_STATUSBAR);
+G_DEFINE_TYPE (MousepadStatusbar, mousepad_statusbar, GTK_TYPE_STATUSBAR)
 
 
 
diff --git a/mousepad/mousepad-util.h b/mousepad/mousepad-util.h
index 6e48ddf..60334f8 100644
--- a/mousepad/mousepad-util.h
+++ b/mousepad/mousepad-util.h
@@ -21,9 +21,7 @@ G_BEGIN_DECLS
 
 #define MOUSEPAD_TYPE_SEARCH_FLAGS (mousepad_util_search_flags_get_type ())
 
-typedef enum _MousepadSearchFlags MousepadSearchFlags;
-
-enum _MousepadSearchFlags
+typedef enum
 {
   /* search area */
   MOUSEPAD_SEARCH_FLAGS_AREA_DOCUMENT     = 1 << 0,  /* search the entire document */
@@ -53,7 +51,8 @@ enum _MousepadSearchFlags
   MOUSEPAD_SEARCH_FLAGS_ACTION_CLEANUP    = 1 << 15, /* cleanup the highlighted occurences */
   MOUSEPAD_SEARCH_FLAGS_ACTION_SELECT     = 1 << 16, /* select the match */
   MOUSEPAD_SEARCH_FLAGS_ACTION_REPLACE    = 1 << 17, /* replace the match */
-};
+}
+MousepadSearchFlags;
 
 gboolean   mousepad_util_iter_starts_word                 (const GtkTextIter   *iter);
 
diff --git a/mousepad/mousepad-view.c b/mousepad/mousepad-view.c
index d6739d2..5f935b8 100644
--- a/mousepad/mousepad-view.c
+++ b/mousepad/mousepad-view.c
@@ -152,7 +152,7 @@ enum
 
 
 
-G_DEFINE_TYPE (MousepadView, mousepad_view, GTK_TYPE_SOURCE_VIEW);
+G_DEFINE_TYPE (MousepadView, mousepad_view, GTK_TYPE_SOURCE_VIEW)
 
 
 
diff --git a/mousepad/mousepad-view.h b/mousepad/mousepad-view.h
index 491c32c..14c5fce 100644
--- a/mousepad/mousepad-view.h
+++ b/mousepad/mousepad-view.h
@@ -28,7 +28,6 @@ G_BEGIN_DECLS
 
 typedef struct _MousepadViewClass MousepadViewClass;
 typedef struct _MousepadView      MousepadView;
-typedef enum   _MousepadViewFlags MousepadViewFlags;
 
 enum
 {
diff --git a/mousepad/mousepad-window.c b/mousepad/mousepad-window.c
index c493f2d..47b8e62 100644
--- a/mousepad/mousepad-window.c
+++ b/mousepad/mousepad-window.c
@@ -506,7 +506,7 @@ static guint   clipboard_history_ref_count = 0;
 
 
 
-G_DEFINE_TYPE (MousepadWindow, mousepad_window, GTK_TYPE_WINDOW);
+G_DEFINE_TYPE (MousepadWindow, mousepad_window, GTK_TYPE_WINDOW)
 
 
 
@@ -1127,7 +1127,7 @@ mousepad_window_dispose (GObject *object)
 
   /* disconnect recent manager signal */
   if (G_LIKELY (window->recent_manager))
-    g_signal_handlers_disconnect_by_func (G_OBJECT (window->recent_manager), mousepad_window_recent_menu, window);
+    mousepad_disconnect_by_func (G_OBJECT (window->recent_manager), mousepad_window_recent_menu, window);
 
   /* destroy the save geometry timer source */
   if (G_UNLIKELY (window->save_geometry_timer_id != 0))
@@ -1256,8 +1256,8 @@ mousepad_window_disconnect_proxy (GtkUIManager   *manager,
   if (GTK_IS_MENU_ITEM (proxy))
     {
       /* disconnect from the select/deselect signals */
-      g_signal_handlers_disconnect_by_func (proxy, mousepad_window_menu_item_selected, window);
-      g_signal_handlers_disconnect_by_func (proxy, mousepad_window_menu_item_deselected, window);
+      mousepad_disconnect_by_func (proxy, mousepad_window_menu_item_selected, window);
+      mousepad_disconnect_by_func (proxy, mousepad_window_menu_item_deselected, window);
     }
   else if (GTK_IS_TOOL_ITEM (proxy))
     {
@@ -1267,10 +1267,10 @@ mousepad_window_disconnect_proxy (GtkUIManager   *manager,
       child = gtk_bin_get_child (GTK_BIN (proxy));
 
       /* disconnect from the gdk window event signals */
-      g_signal_handlers_disconnect_by_func (child, mousepad_window_tool_item_enter_event, window);
-      g_signal_handlers_disconnect_by_func (child, mousepad_window_tool_item_leave_event, window);
-      g_signal_handlers_disconnect_by_func (child, mousepad_window_tool_item_enter_event, window);
-      g_signal_handlers_disconnect_by_func (child, mousepad_window_tool_item_leave_event, window);
+      mousepad_disconnect_by_func (child, mousepad_window_tool_item_enter_event, window);
+      mousepad_disconnect_by_func (child, mousepad_window_tool_item_leave_event, window);
+      mousepad_disconnect_by_func (child, mousepad_window_tool_item_enter_event, window);
+      mousepad_disconnect_by_func (child, mousepad_window_tool_item_leave_event, window);
     }
 }
 
@@ -1882,16 +1882,16 @@ mousepad_window_notebook_removed (GtkNotebook     *notebook,
   mousepad_return_if_fail (GTK_IS_NOTEBOOK (notebook));
 
   /* disconnect the old document signals */
-  g_signal_handlers_disconnect_by_func (G_OBJECT (page), mousepad_window_button_close_tab, window);
-  g_signal_handlers_disconnect_by_func (G_OBJECT (page), mousepad_window_cursor_changed, window);
-  g_signal_handlers_disconnect_by_func (G_OBJECT (page), mousepad_window_selection_changed, window);
-  g_signal_handlers_disconnect_by_func (G_OBJECT (page), mousepad_window_overwrite_changed, window);
-  g_signal_handlers_disconnect_by_func (G_OBJECT (page), mousepad_window_buffer_language_changed, window);
-  g_signal_handlers_disconnect_by_func (G_OBJECT (page), mousepad_window_drag_data_received, window);
-  g_signal_handlers_disconnect_by_func (G_OBJECT (document->buffer), mousepad_window_can_undo, window);
-  g_signal_handlers_disconnect_by_func (G_OBJECT (document->buffer), mousepad_window_can_redo, window);
-  g_signal_handlers_disconnect_by_func (G_OBJECT (document->buffer), mousepad_window_modified_changed, window);
-  g_signal_handlers_disconnect_by_func (G_OBJECT (document->textview), mousepad_window_menu_textview_popup, window);
+  mousepad_disconnect_by_func (G_OBJECT (page), mousepad_window_button_close_tab, window);
+  mousepad_disconnect_by_func (G_OBJECT (page), mousepad_window_cursor_changed, window);
+  mousepad_disconnect_by_func (G_OBJECT (page), mousepad_window_selection_changed, window);
+  mousepad_disconnect_by_func (G_OBJECT (page), mousepad_window_overwrite_changed, window);
+  mousepad_disconnect_by_func (G_OBJECT (page), mousepad_window_buffer_language_changed, window);
+  mousepad_disconnect_by_func (G_OBJECT (page), mousepad_window_drag_data_received, window);
+  mousepad_disconnect_by_func (G_OBJECT (document->buffer), mousepad_window_can_undo, window);
+  mousepad_disconnect_by_func (G_OBJECT (document->buffer), mousepad_window_can_redo, window);
+  mousepad_disconnect_by_func (G_OBJECT (document->buffer), mousepad_window_modified_changed, window);
+  mousepad_disconnect_by_func (G_OBJECT (document->textview), mousepad_window_menu_textview_popup, window);
 
   /* unset the go menu item (part of the old window) */
   mousepad_object_set_data (G_OBJECT (page), "document-menu-action", NULL);
@@ -2515,7 +2515,7 @@ mousepad_window_menu_textview_deactivate (GtkWidget   *menu,
   mousepad_return_if_fail (textview->popup_menu == menu);
 
   /* disconnect this signal */
-  g_signal_handlers_disconnect_by_func (G_OBJECT (menu), mousepad_window_menu_textview_deactivate, textview);
+  mousepad_disconnect_by_func (G_OBJECT (menu), mousepad_window_menu_textview_deactivate, textview);
 
   /* unset the popup menu since your menu is owned by the ui manager */
   GTK_TEXT_VIEW (textview)->popup_menu = NULL;
@@ -4713,7 +4713,7 @@ mousepad_window_action_replace_destroy (MousepadWindow *window)
   mousepad_return_if_fail (MOUSEPAD_IS_WINDOW (window));
 
   /* disconnect tab switch signal */
-  g_signal_handlers_disconnect_by_func (G_OBJECT (window->notebook), mousepad_window_action_replace_switch_page, window);
+  mousepad_disconnect_by_func (G_OBJECT (window->notebook), mousepad_window_action_replace_switch_page, window);
 
   /* reset the dialog variable */
   window->replace_dialog = NULL;

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list