diff --git a/glnx-backports.h b/glnx-backports.h index cd853cca250af80f01e601c636f78eddc0f4df18..b6d93c05fbe4b1d0c242fa6c2f5053a1898a5394 100644 --- a/glnx-backports.h +++ b/glnx-backports.h @@ -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 diff --git a/glnx-fdio.c b/glnx-fdio.c index 12879cd77b995f164dc5e5afb04349c7b79e1a7c..31bb15d246c8691ffb5132481d5dcaeb960c794f 100644 --- a/glnx-fdio.c +++ b/glnx-fdio.c @@ -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>