From 7e5d8ec736085cbc5e896bc5b60735a427676f20 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 24 Jul 2017 12:30:57 +0100 Subject: [PATCH] Add a simplified backport of g_steal_pointer() This will be used in tests later in the branch. Sadly we can't use GLIB_VERSION_2_44 unless we are willing to have a hard dependency on GLib 2.44, which would force us to do all our Travis-CI builds in Docker containers rather than in ye olde base system, and that adds 50% to the time taken to do builds. Signed-off-by: Simon McVittie --- Avoid GLIB_VERSION_2_44 --- configure.ac | 2 +- test/test-utils-glib.h | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 7416fed7..467c17db 100644 --- a/configure.ac +++ b/configure.ac @@ -266,7 +266,7 @@ dnl Don't do anything too subtle here, because the CMake build system dnl parses these lines with regular expressions. If necessary, adjust dnl cmake/modules/MacrosAutotools.cmake to compensate. AC_DEFINE([GLIB_VERSION_MIN_REQUIRED], [GLIB_VERSION_2_40], [Ignore post-2.40 deprecations]) -AC_DEFINE([GLIB_VERSION_MAX_ALLOWED], [GLIB_VERSION_2_40], [Prevent post-2.40 APIs]) +AC_DEFINE([GLIB_VERSION_MAX_ALLOWED], [G_ENCODE_VERSION(2,44)], [Prevent post-2.44 APIs]) with_glib=yes diff --git a/test/test-utils-glib.h b/test/test-utils-glib.h index 2e1073f0..52d66b91 100644 --- a/test/test-utils-glib.h +++ b/test/test-utils-glib.h @@ -89,4 +89,19 @@ void test_rmdir_must_exist (const gchar *path); void test_rmdir_if_exists (const gchar *path); void test_mkdir (const gchar *path, gint mode); +#if !GLIB_CHECK_VERSION(2, 44, 0) +#define g_steal_pointer(x) backported_g_steal_pointer (x) +/* A simplified version of g_steal_pointer without type-safety. */ +static inline gpointer +backported_g_steal_pointer (gpointer pointer_to_pointer) +{ + gpointer *pp = pointer_to_pointer; + gpointer ret; + + ret = *pp; + *pp = NULL; + return ret; +} +#endif + #endif -- 2.13.3