[libglnx] backports: g_autofree



commit 37082ed867f2c3e545b178aef2f4c1b48ea2c484
Author: Colin Walters <walters verbum org>
Date:   Wed Feb 25 21:44:42 2015 -0500

    backports: g_autofree

 glnx-backport-autocleanups.h |   10 +++++++++-
 glnx-backport-autoptr.h      |    1 +
 2 files changed, 10 insertions(+), 1 deletions(-)
---
diff --git a/glnx-backport-autocleanups.h b/glnx-backport-autocleanups.h
index dfc8daf..daa89a9 100644
--- a/glnx-backport-autocleanups.h
+++ b/glnx-backport-autocleanups.h
@@ -21,7 +21,15 @@
 
 #include <glnx-backport-autoptr.h>
 
-#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 fd5f5d0..b36919d 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:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]