]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cleanup: add cleanup func macro that renames the function
authorLennart Poettering <lennart@poettering.net>
Tue, 23 Sep 2025 09:43:43 +0000 (11:43 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 24 Sep 2025 07:41:21 +0000 (09:41 +0200)
This is useful when having to add a "sym_" prefix to functions

src/fundamental/cleanup-fundamental.h

index 244699105a66ea804e58e7932107a6b680db6cce..8a8c40ad0646c5de67b7e1efa4cac3dac9d12b92 100644 (file)
                         *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) {                           \