From: Yu Watanabe Date: Sat, 25 Oct 2025 01:21:54 +0000 (+0900) Subject: cleanup: introduce DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_MACRO_RENAME() macro X-Git-Tag: v259-rc1~246^2~17 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5f884da90371bb90498f7cc355fdd1d8d2b0cf55;p=thirdparty%2Fsystemd.git cleanup: introduce DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_MACRO_RENAME() macro This is similar to DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(), but for macro. --- diff --git a/src/fundamental/cleanup-fundamental.h b/src/fundamental/cleanup-fundamental.h index 8a8c40ad064..86b9851fd54 100644 --- a/src/fundamental/cleanup-fundamental.h +++ b/src/fundamental/cleanup-fundamental.h @@ -34,14 +34,17 @@ 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) { \ +#define DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_MACRO_RENAME(type, macro, name, empty) \ + static inline void name(type *p) { \ if (*p != (empty)) { \ - func(*p); \ + macro(*p); \ *p = (empty); \ } \ } +#define DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_MACRO(type, macro, empty) \ + DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_MACRO_RENAME(type, macro, macro##p, empty) + typedef void (*free_array_func_t)(void *p, size_t n); /* An automatic _cleanup_-like logic for destroy arrays (i.e. pointers + size) when leaving scope */