From: Zbigniew Jędrzejewski-Szmek Date: Tue, 24 Mar 2026 22:33:49 +0000 (+0100) Subject: shared/verbs: allow multiple verbs to be handled by a single function X-Git-Tag: v261-rc1~744^2~3 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=7be9bb1845a8a521d16492213110eb043a7bb0c6;p=thirdparty%2Fsystemd.git shared/verbs: allow multiple verbs to be handled by a single function 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. --- diff --git a/src/fundamental/macro-fundamental.h b/src/fundamental/macro-fundamental.h index 39004183d90..1941e88d376 100644 --- a/src/fundamental/macro-fundamental.h +++ b/src/fundamental/macro-fundamental.h @@ -143,6 +143,7 @@ #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) diff --git a/src/shared/verbs.h b/src/shared/verbs.h index 062e49466f9..b7bc66fc195 100644 --- a/src/shared/verbs.h +++ b/src/shared/verbs.h @@ -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, \