summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2014-02-08 14:03:49 +0100
committerDan Winship <danw@gnome.org>2014-02-13 11:24:37 -0500
commit64c5395cb1cc9e491b96b6bb86df72cb3c606627 (patch)
treeb642c4b8f2849c7876e495057a623be7a561f14f
parent9c4d86ee8064fa36710b8d2d242d9618d4fc763a (diff)
downloadNetworkManager-64c5395cb1cc9e491b96b6bb86df72cb3c606627.tar.gz
build: improve our use of glib's version macros to catch more bugs
We were setting GLIB_VERSION_MAX_ALLOWED to 2.34, since we provide reimplementations of a few 2.34 functions in nm-glib-compat.h. But this was turning off warnings for the 2.34+ APIs we *didn't* have compat versions of too. Fix this by setting MAX_ALLOWED to 2.32 (same as MIN_REQUIRED), and defining macros to wrap calls to compat-ified functions and disable deprecation warnings around them. This points out several places where we were accidentally using 2.34 APIs without noticing, which need to be fixed now.
-rw-r--r--Makefile.am2
-rw-r--r--configure.ac10
-rw-r--r--include/nm-glib-compat.h34
-rw-r--r--tui/newt/Makefile.am1
-rw-r--r--tui/newt/nmt-newt-types.h1
-rw-r--r--tui/newt/nmt-newt-utils.c11
6 files changed, 52 insertions, 7 deletions
diff --git a/Makefile.am b/Makefile.am
index edeadf56a5..b41bfa90f1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -57,7 +57,7 @@ cscope:
cscope -b -q -R -Iinclude -ssrc -slibnm-glib -slibnm-util -scli/src;
libgsystem_srcpath := libgsystem
-libgsystem_cflags := $(GLIB_CFLAGS) -I$(srcdir)/libgsystem
+libgsystem_cflags := $(filter-out -DGLIB_VERSION%,$(GLIB_CFLAGS)) -I$(srcdir)/libgsystem
libgsystem_libs = $(GLIB_LIBS)
include libgsystem/Makefile-libgsystem.am
noinst_LTLIBRARIES = libgsystem.la
diff --git a/configure.ac b/configure.ac
index 9e29b715da..174b6bfa20 100644
--- a/configure.ac
+++ b/configure.ac
@@ -254,12 +254,10 @@ AM_CONDITIONAL(HAVE_DBUS_GLIB_100, test "${have_dbus_glib_100}" = "yes")
PKG_CHECK_MODULES(GLIB, gio-unix-2.0 >= 2.32 gmodule-2.0)
dnl GLIB_VERSION_MIN_REQUIRED should match the version above.
-dnl GLIB_VERSION_MAX_ALLOWED should be the largest version for which there
-dnl is a GLIB_CHECK_VERSION check. We currently have to use
-dnl G_ENCODE_VERSION(2,34) here rather than GLIB_VERSION_2_34, because
-dnl GLib 2.32 did not handle future version defines correctly.
-
-GLIB_CFLAGS="$GLIB_CFLAGS -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_32 '-DGLIB_VERSION_MAX_ALLOWED=G_ENCODE_VERSION(2,34)'"
+dnl GLIB_VERSION_MAX_ALLOWED should be set to the same version;
+dnl nm-glib-compat.h will cause it to be overridden for the functions
+dnl we have compat versions of.
+GLIB_CFLAGS="$GLIB_CFLAGS -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_32 -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_32"
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)
diff --git a/include/nm-glib-compat.h b/include/nm-glib-compat.h
index 58e92cfea2..9004e241c0 100644
--- a/include/nm-glib-compat.h
+++ b/include/nm-glib-compat.h
@@ -55,6 +55,40 @@ g_type_ensure (GType type)
_destroy (_p); \
} G_STMT_END
+/* These are used to clean up the output of test programs; we can just let
+ * them no-op in older glib.
+ */
+#define g_test_expect_message(log_domain, log_level, pattern)
+#define g_test_assert_expected_messages()
+
+#else
+
+/* We build with -DGLIB_MAX_ALLOWED_VERSION set to 2.32 to make sure we don't
+ * accidentally use new API that we shouldn't. But we don't want warnings for
+ * the APIs that we emulate above.
+ */
+
+#define g_type_ensure(t) \
+ G_STMT_START { \
+ G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
+ g_type_ensure (t); \
+ G_GNUC_END_IGNORE_DEPRECATIONS \
+ } G_STMT_END
+
+#define g_test_expect_message(domain, level, format...) \
+ G_STMT_START { \
+ G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
+ g_test_expect_message (domain, level, format); \
+ G_GNUC_END_IGNORE_DEPRECATIONS \
+ } G_STMT_END
+
+#define g_test_assert_expected_messages_internal(domain, file, line, func) \
+ G_STMT_START { \
+ G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
+ g_test_assert_expected_messages_internal (domain, file, line, func); \
+ G_GNUC_END_IGNORE_DEPRECATIONS \
+ } G_STMT_END
+
#endif
#endif /* NM_GLIB_COMPAT_H */
diff --git a/tui/newt/Makefile.am b/tui/newt/Makefile.am
index c5b295cade..7dc35bb0fb 100644
--- a/tui/newt/Makefile.am
+++ b/tui/newt/Makefile.am
@@ -1,4 +1,5 @@
AM_CPPFLAGS= \
+ -I$(top_srcdir)/include \
$(GLIB_CFLAGS) \
$(NEWT_CFLAGS) \
$(NULL)
diff --git a/tui/newt/nmt-newt-types.h b/tui/newt/nmt-newt-types.h
index c26ff900ef..608f7ff6fa 100644
--- a/tui/newt/nmt-newt-types.h
+++ b/tui/newt/nmt-newt-types.h
@@ -21,6 +21,7 @@
#include <glib-object.h>
#include <newt.h>
+#include "nm-glib-compat.h"
G_BEGIN_DECLS
diff --git a/tui/newt/nmt-newt-utils.c b/tui/newt/nmt-newt-utils.c
index 028c2438c6..10e8484927 100644
--- a/tui/newt/nmt-newt-utils.c
+++ b/tui/newt/nmt-newt-utils.c
@@ -26,6 +26,7 @@
#include <errno.h>
#include <stdarg.h>
#include <unistd.h>
+#include <sys/wait.h>
#include <glib/gi18n-lib.h>
@@ -350,11 +351,21 @@ nmt_newt_edit_string (const char *data)
goto done;
}
+#if GLIB_CHECK_VERSION (2, 34, 0)
+ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
if (!g_spawn_check_exit_status (status, &error)) {
nmt_newt_message_dialog (_("Editor failed: %s"), error->message);
g_error_free (error);
goto done;
}
+ G_GNUC_END_IGNORE_DEPRECATIONS
+#else
+ if (WIFEXITED (status)) {
+ if (WEXITSTATUS (status) != 0)
+ nmt_newt_message_dialog (_("Editor failed with status %d"), WEXITSTATUS (status));
+ } else if (WIFSIGNALED (status))
+ nmt_newt_message_dialog (_("Editor failed with signal %d"), WTERMSIG (status));
+#endif
if (!g_file_get_contents (filename, &new_data, NULL, &error)) {
nmt_newt_message_dialog (_("Could not re-read file: %s"), error->message);