diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2012-06-16 12:51:02 +0200 |
---|---|---|
committer | Marc-André Lureau <marcandre.lureau@redhat.com> | 2012-07-16 17:46:40 +0200 |
commit | d809b2ce54fb61081bc6d3d1f67068093f5532ec (patch) | |
tree | cf4408665659efcf2d2469672e53c683f5edf0f9 | |
parent | 6bea13927e6c1833e2c12b604c51bb265cede305 (diff) |
glib-compat: add g_clear_pointer
A helpful macro from glib 2.34
-rw-r--r-- | gtk/glib-compat.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/gtk/glib-compat.h b/gtk/glib-compat.h index bd8f3de..aa750b2 100644 --- a/gtk/glib-compat.h +++ b/gtk/glib-compat.h @@ -106,4 +106,24 @@ GType spice_main_context_get_type (void) G_GNUC_CONST; # define G_SIGNAL_DEPRECATED (1 << 9) #endif +#ifndef g_clear_pointer +#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 /* GLIB_COMPAT_H */ |