From 31a66a11260dc8f46510df59880a256cf161c78f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 23 Sep 2025 11:43:43 +0200 Subject: [PATCH] cleanup: add cleanup func macro that renames the function This is useful when having to add a "sym_" prefix to functions --- src/fundamental/cleanup-fundamental.h | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/fundamental/cleanup-fundamental.h b/src/fundamental/cleanup-fundamental.h index 244699105a6..8a8c40ad064 100644 --- a/src/fundamental/cleanup-fundamental.h +++ b/src/fundamental/cleanup-fundamental.h @@ -17,19 +17,22 @@ *p = func(*p); \ } -/* When func() doesn't return the appropriate type, set variable to empty afterwards. - * The func() may be provided by a dynamically loaded shared library, hence add an assertion. */ -#define DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(type, func, empty) \ - static inline void func##p(type *p) { \ - if (*p != (empty)) { \ - DISABLE_WARNING_ADDRESS; \ - assert(func); \ - REENABLE_WARNING; \ - func(*p); \ - *p = (empty); \ - } \ +/* When func() doesn't return the appropriate type, set variable to empty afterwards. The func() may be + * provided by a dynamically loaded (dlopen()) shared library, hence add an assertion. */ +#define DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(type, func, name, empty) \ + static inline void name(type *p) { \ + if (*p != (empty)) { \ + DISABLE_WARNING_ADDRESS; \ + assert(func); \ + REENABLE_WARNING; \ + func(*p); \ + *p = (empty); \ + } \ } +#define DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(type, func, empty) \ + DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(type, func, func##p, empty) + /* When func() doesn't return the appropriate type, and is also a macro, set variable to empty afterwards. */ #define DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_MACRO(type, func, empty) \ static inline void func##p(type *p) { \ -- 2.47.3