Skip to content
Snippets Groups Projects
Commit 46ba6b41 authored by Simon McVittie's avatar Simon McVittie
Browse files

backports: Add a backport of g_clear_pointer()


This will be necessary if targeting GLib versions older than 2.34,
such as GLib 2.32 in Ubuntu 12.04 and the Steam Runtime.

Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
parent 9d0711fe
No related branches found
No related tags found
No related merge requests found
......@@ -27,6 +27,26 @@
G_BEGIN_DECLS
#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; work around type aliasing */ \
union { char *in; gpointer *out; } _pp; \
gpointer _p; \
/* This assignment is needed to avoid a gcc warning */ \
GDestroyNotify _destroy = (GDestroyNotify) (destroy); \
\
_pp.in = (char *) (pp); \
_p = *_pp.out; \
if (_p) \
{ \
*_pp.out = NULL; \
_destroy (_p); \
} \
} G_STMT_END
#endif
#if !GLIB_CHECK_VERSION(2, 44, 0)
#define g_strv_contains glnx_strv_contains
......
......@@ -37,6 +37,7 @@
#include <glnx-errors.h>
#include <glnx-xattrs.h>
#include <glnx-backport-autoptr.h>
#include <glnx-backports.h>
#include <glnx-local-alloc.h>
#include <glnx-missing.h>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment