From 86c073dba9d82ef3f1bc3d3116b058b9b5c3b1eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 23 Oct 2018 18:30:43 -0500 Subject: [PATCH] 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); } \