summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gtk/glib-compat.h20
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 */