diff options
author | Dan Winship <danw@gnome.org> | 2013-04-03 12:56:13 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2013-04-03 13:11:31 -0400 |
commit | e58d86450d59846f72ae27282e367b0005def784 (patch) | |
tree | 9a883a8d742c5d66ca9b939640f6f99161091927 /include | |
parent | 8b3d609404ef3a94ae0f160dc6b44f4b9e57619c (diff) | |
download | NetworkManager-e58d86450d59846f72ae27282e367b0005def784.tar.gz |
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.
Diffstat (limited to 'include')
-rw-r--r-- | include/nm-glib-compat.h | 19 |
1 files changed, 19 insertions, 0 deletions
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 */ |