From e58d86450d59846f72ae27282e367b0005def784 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Wed, 3 Apr 2013 12:56:13 -0400 Subject: [PATCH] core: fix build with glib < 2.34 Using g_clear_pointer() didn't trigger G_UNAVAILABLE warnings because it's a macro. Fix the build on older glibs by just pulling in the definition. --- include/nm-glib-compat.h | 19 +++++++++++++++++++ src/config/nm-config.c | 1 + 2 files changed, 20 insertions(+) diff --git a/include/nm-glib-compat.h b/include/nm-glib-compat.h index 07b81a40d4..58e92cfea2 100644 --- a/include/nm-glib-compat.h +++ b/include/nm-glib-compat.h @@ -36,6 +36,25 @@ g_type_ensure (GType type) if (G_UNLIKELY (type == (GType)-1)) g_error ("can't happen"); } + +#define g_clear_pointer(pp, destroy) \ + G_STMT_START { \ + G_STATIC_ASSERT (sizeof *(pp) == sizeof (gpointer)); \ + /* Only one access, please */ \ + gpointer *_pp = (gpointer *) (pp); \ + gpointer _p; \ + /* This assignment is needed to avoid a gcc warning */ \ + GDestroyNotify _destroy = (GDestroyNotify) (destroy); \ + \ + (void) (0 ? (gpointer) *(pp) : 0); \ + do \ + _p = g_atomic_pointer_get (_pp); \ + while G_UNLIKELY (!g_atomic_pointer_compare_and_exchange (_pp, _p, NULL)); \ + \ + if (_p) \ + _destroy (_p); \ + } G_STMT_END + #endif #endif /* NM_GLIB_COMPAT_H */ diff --git a/src/config/nm-config.c b/src/config/nm-config.c index 606a889308..5a7e2ecd17 100644 --- a/src/config/nm-config.c +++ b/src/config/nm-config.c @@ -26,6 +26,7 @@ #include "nm-config.h" #include "nm-logging.h" #include "nm-utils.h" +#include "nm-glib-compat.h" #include #include