From 5f884da90371bb90498f7cc355fdd1d8d2b0cf55 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 25 Oct 2025 10:21:54 +0900 Subject: [PATCH] cleanup: introduce DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_MACRO_RENAME() macro This is similar to DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(), but for macro. --- src/fundamental/cleanup-fundamental.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/fundamental/cleanup-fundamental.h b/src/fundamental/cleanup-fundamental.h index 8a8c40ad06..86b9851fd5 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 */