From 37082ed867f2c3e545b178aef2f4c1b48ea2c484 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 25 Feb 2015 21:44:42 -0500 Subject: [PATCH] backports: g_autofree --- glnx-backport-autocleanups.h | 10 +++++++++- glnx-backport-autoptr.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/glnx-backport-autocleanups.h b/glnx-backport-autocleanups.h index dfc8dafb..daa89a9b 100644 --- a/glnx-backport-autocleanups.h +++ b/glnx-backport-autocleanups.h @@ -21,7 +21,15 @@ #include -#if !GLIB_CHECK_VERSION(2, 43, 3) +#if !GLIB_CHECK_VERSION(2, 43, 4) + +static inline void +g_autoptr_cleanup_generic_gfree (void *p) +{ + void **pp = (void**)p; + if (*pp) + g_free (*pp); +} G_DEFINE_AUTOPTR_CLEANUP_FUNC(GAsyncQueue, g_async_queue_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC(GBookmarkFile, g_bookmark_file_free) diff --git a/glnx-backport-autoptr.h b/glnx-backport-autoptr.h index fd5f5d01..b36919dc 100644 --- a/glnx-backport-autoptr.h +++ b/glnx-backport-autoptr.h @@ -55,6 +55,7 @@ G_BEGIN_DECLS G_GNUC_END_IGNORE_DEPRECATIONS #define g_autoptr(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_TYPENAME(TypeName) #define g_auto(TypeName) _GLIB_CLEANUP(_GLIB_AUTO_FUNC_NAME(TypeName)) TypeName +#define g_autofree _GLIB_CLEANUP(g_autoptr_cleanup_generic_gfree) /** * g_steal_pointer: