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.
This commit is contained in:
Dan Winship 2014-02-08 14:03:49 +01:00
parent 9c4d86ee80
commit 64c5395cb1
6 changed files with 52 additions and 7 deletions

View file

@ -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

View file

@ -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)

View file

@ -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 */

View file

@ -1,4 +1,5 @@
AM_CPPFLAGS= \
-I$(top_srcdir)/include \
$(GLIB_CFLAGS) \
$(NEWT_CFLAGS) \
$(NULL)

View file

@ -21,6 +21,7 @@
#include <glib-object.h>
#include <newt.h>
#include "nm-glib-compat.h"
G_BEGIN_DECLS

View file

@ -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);