[libdazzle] macros: use g_clear_pointer() on newer glib
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libdazzle] macros: use g_clear_pointer() on newer glib
- Date: Wed, 25 Jul 2018 23:59:37 +0000 (UTC)
commit 3ce09af70f3668f4f886fea3a24cb7e951d6a8f3
Author: Christian Hergert <chergert redhat com>
Date: Wed Jul 25 16:59:15 2018 -0700
macros: use g_clear_pointer() on newer glib
We can avoid the type checking helper and use glib directly on newer
versions of glib, since it has the same type checks now.
src/util/dzl-macros.h | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/src/util/dzl-macros.h b/src/util/dzl-macros.h
index b4e60c5..5d65deb 100644
--- a/src/util/dzl-macros.h
+++ b/src/util/dzl-macros.h
@@ -42,8 +42,13 @@ G_BEGIN_DECLS
#define dzl_clear_weak_pointer(ptr) g_clear_weak_pointer(ptr)
#define dzl_set_weak_pointer(ptr,obj) g_set_weak_pointer(ptr,obj)
-/* A more type-correct form of g_clear_pointer(), to help find bugs. */
-#define dzl_clear_pointer(pptr, free_func) \
+/* A more type-correct form of g_clear_pointer(), to help find bugs.
+ * GLib ended up with a similar feature which we can rely on now.
+ */
+#if GLIB_CHECK_VERSION(2,57,2)
+# define dzl_clear_pointer g_clear_pointer
+#else
+# define dzl_clear_pointer(pptr, free_func) \
G_STMT_START { \
G_STATIC_ASSERT (sizeof (*(pptr)) == sizeof (gpointer)); \
typeof(*(pptr)) _dzl_tmp_clear = *(pptr); \
@@ -51,6 +56,7 @@ G_BEGIN_DECLS
if (_dzl_tmp_clear) \
free_func (_dzl_tmp_clear); \
} G_STMT_END
+#endif
/* strlen() gets hoisted out automatically at -O0 for everything but MSVC */
#define DZL_LITERAL_LENGTH(s) (strlen(s))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]