From dcb25a37a599c2f269228bc0060d2284a8d511ff Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 12 Nov 2014 10:54:37 +0100 Subject: [PATCH] glib-compat: sync local definition of g_clear_pointer() with upstream glib and remove atomic operations Upstream glib changed g_clear_pointer() not to use atomic functions. Update or local definition to b1dd594a22e3499caafdeccd7fa223a032b9e177 glib/gmem.h (glib 2.41.3). (fixup whitespace to match our style). See also the related bug https://bugzilla.gnome.org/show_bug.cgi?id=733969 from glib. Signed-off-by: Thomas Haller --- include/nm-glib-compat.h | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/include/nm-glib-compat.h b/include/nm-glib-compat.h index 7a9bb3160a..1dc939feac 100644 --- a/include/nm-glib-compat.h +++ b/include/nm-glib-compat.h @@ -59,23 +59,22 @@ __g_type_ensure (GType type) #if !GLIB_CHECK_VERSION(2,34,0) -#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 +#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); \ + \ + _p = *_pp; \ + if (_p) \ + { \ + *_pp = NULL; \ + _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.