[glib: 2/4] gmacros: remove duplication on autoptr cleanup definition
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 2/4] gmacros: remove duplication on autoptr cleanup definition
- Date: Thu, 15 Nov 2018 10:26:03 +0000 (UTC)
commit 86c073dba9d82ef3f1bc3d3116b058b9b5c3b1eb
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date: Tue Oct 23 18:30:43 2018 -0500
gmacros: remove duplication on autoptr cleanup definition
Define _GLIB_DEFINE_AUTOPTR_CLEANUP_FUNCS and reuse it for both
_GLIB_DEFINE_AUTOPTR_CHAINUP and G_DEFINE_AUTOPTR_CLEANUP_FUNC
glib/gmacros.h | 36 +++++++++++++++++-------------------
1 file changed, 17 insertions(+), 19 deletions(-)
---
diff --git a/glib/gmacros.h b/glib/gmacros.h
index 28a01a33f..437330f76 100644
--- a/glib/gmacros.h
+++ b/glib/gmacros.h
@@ -489,6 +489,7 @@
/* these macros are private */
#define _GLIB_AUTOPTR_FUNC_NAME(TypeName) glib_autoptr_cleanup_##TypeName
+#define _GLIB_AUTOPTR_CLEAR_FUNC_NAME(TypeName) glib_autoptr_clear_##TypeName
#define _GLIB_AUTOPTR_TYPENAME(TypeName) TypeName##_autoptr
#define _GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName) glib_listautoptr_cleanup_##TypeName
#define _GLIB_AUTOPTR_LIST_TYPENAME(TypeName) TypeName##_listautoptr
@@ -496,30 +497,27 @@
#define _GLIB_AUTOPTR_SLIST_TYPENAME(TypeName) TypeName##_slistautoptr
#define _GLIB_AUTO_FUNC_NAME(TypeName) glib_auto_cleanup_##TypeName
#define _GLIB_CLEANUP(func) __attribute__((cleanup(func)))
-#define _GLIB_DEFINE_AUTOPTR_CHAINUP(ModuleObjName, ParentName) \
- typedef ModuleObjName *_GLIB_AUTOPTR_TYPENAME(ModuleObjName);
\
- typedef GList *_GLIB_AUTOPTR_LIST_TYPENAME(ModuleObjName);
\
- typedef GSList *_GLIB_AUTOPTR_SLIST_TYPENAME(ModuleObjName);
\
+#define _GLIB_DEFINE_AUTOPTR_CLEANUP_FUNCS(TypeName, ParentName, cleanup) \
+ typedef TypeName *_GLIB_AUTOPTR_TYPENAME(TypeName);
\
+ typedef GList *_GLIB_AUTOPTR_LIST_TYPENAME(TypeName);
\
+ typedef GSList *_GLIB_AUTOPTR_SLIST_TYPENAME(TypeName);
\
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
\
- static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_FUNC_NAME(ModuleObjName) (ModuleObjName **_ptr) {
\
- _GLIB_AUTOPTR_FUNC_NAME(ParentName) ((ParentName **) _ptr); }
\
- static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_LIST_FUNC_NAME(ModuleObjName) (GList **_l) {
\
- _GLIB_AUTOPTR_LIST_FUNC_NAME(ParentName) (_l); }
\
- static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_SLIST_FUNC_NAME(ModuleObjName) (GSList **_l) {
\
- _GLIB_AUTOPTR_SLIST_FUNC_NAME(ParentName) (_l); }
\
- G_GNUC_END_IGNORE_DEPRECATIONS
\
+ static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_CLEAR_FUNC_NAME(TypeName) (TypeName *_ptr)
\
+ { if (_ptr) (cleanup) ((ParentName *) _ptr); }
\
+ static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_FUNC_NAME(TypeName) (TypeName **_ptr)
\
+ { _GLIB_AUTOPTR_CLEAR_FUNC_NAME(TypeName) (*_ptr); }
\
+ static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName) (GList **_l)
\
+ { g_list_free_full (*_l, (GDestroyNotify) (void(*)(void)) cleanup); }
\
+ static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_SLIST_FUNC_NAME(TypeName) (GSList **_l)
\
+ { g_slist_free_full (*_l, (GDestroyNotify) (void(*)(void)) cleanup); }
\
+ G_GNUC_END_IGNORE_DEPRECATIONS
+#define _GLIB_DEFINE_AUTOPTR_CHAINUP(ModuleObjName, ParentName) \
+ _GLIB_DEFINE_AUTOPTR_CLEANUP_FUNCS(ModuleObjName, ParentName, _GLIB_AUTOPTR_CLEAR_FUNC_NAME(ParentName))
/* these macros are API */
#define G_DEFINE_AUTOPTR_CLEANUP_FUNC(TypeName, func) \
- typedef TypeName *_GLIB_AUTOPTR_TYPENAME(TypeName);
\
- typedef GList *_GLIB_AUTOPTR_LIST_TYPENAME(TypeName);
\
- typedef GSList *_GLIB_AUTOPTR_SLIST_TYPENAME(TypeName);
\
- G_GNUC_BEGIN_IGNORE_DEPRECATIONS
\
- static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_FUNC_NAME(TypeName) (TypeName **_ptr) { if (*_ptr) (func)
(*_ptr); } \
- static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName) (GList **_l) { g_list_free_full
(*_l, (GDestroyNotify) (void(*)(void)) func); } \
- static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_SLIST_FUNC_NAME(TypeName) (GSList **_l) { g_slist_free_full
(*_l, (GDestroyNotify) (void(*)(void)) func); } \
- G_GNUC_END_IGNORE_DEPRECATIONS
+ _GLIB_DEFINE_AUTOPTR_CLEANUP_FUNCS(TypeName, TypeName, func)
#define G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TypeName, func) \
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
\
static inline void _GLIB_AUTO_FUNC_NAME(TypeName) (TypeName *_ptr) { (func) (_ptr); }
\
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]