]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/verbs: allow multiple verbs to be handled by a single function
authorZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Tue, 24 Mar 2026 22:33:49 +0000 (23:33 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Wed, 25 Mar 2026 01:02:25 +0000 (02:02 +0100)
With the uintptr_t data parameter, it is actually quite nice to have
VERB(do_impl, "name-a", …)
VERB(do_impl, "name-b", …)
int do_impl(…) { … }

To make this work, the do_impl_data struct needs to have a unique name and
we also need to suppress the warning about the forward declaration for
do_impl being repeated. I think it's fine to suppress the warning, it's
not needed for anything. If somebody declares the function with the same
name by mistake, the implementations are going to conflict too.

src/fundamental/macro-fundamental.h
src/shared/verbs.h

index 39004183d90f286dd6f45e13738055ff95fad7a2..1941e88d3760e5782efecffcbcf45827f03f9336 100644 (file)
 
 #define XCONCATENATE(x, y) x ## y
 #define CONCATENATE(x, y) XCONCATENATE(x, y)
+#define CONCATENATE3(x, y, z) CONCATENATE(x, CONCATENATE(y, z))
 
 #define assert_cc(expr) _Static_assert(expr, #expr)
 
index 062e49466f9ea966d88bed0486ba2fd1ec913d2f..b7bc66fc19515f7ecfa02e2fd744116e009f6589 100644 (file)
@@ -21,13 +21,15 @@ typedef struct {
 } Verb;
 
 #define VERB_FULL(d, v, a, amin, amax, f, dat, h)                       \
+        DISABLE_WARNING_REDUNDANT_DECLS                                 \
         static int d(int, char**, uintptr_t, void*);                    \
+        REENABLE_WARNING                                                \
         _section_("SYSTEMD_VERBS")                                      \
         _alignptr_                                                      \
         _used_                                                          \
         _retain_                                                        \
         _variable_no_sanitize_address_                                  \
-        static const Verb CONCATENATE(d, _data) = {                     \
+        static const Verb CONCATENATE3(d, _data_, __COUNTER__) = {      \
                 .verb = v,                                              \
                 .min_args = amin,                                       \
                 .max_args = amax,                                       \