mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-01 13:23:07 +02:00
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
This commit is contained in:
parent
d58be1bda9
commit
86c073dba9
@ -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); \
|
||||
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 \
|
||||
|
||||
|
||||
/* these macros are API */
|
||||
#define G_DEFINE_AUTOPTR_CLEANUP_FUNC(TypeName, func) \
|
||||
#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(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); } \
|
||||
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) \
|
||||
_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); } \
|
||||
|
Loading…
x
Reference in New Issue
Block a user