From 7be9bb1845a8a521d16492213110eb043a7bb0c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 24 Mar 2026 23:33:49 +0100 Subject: [PATCH] shared/verbs: allow multiple verbs to be handled by a single function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 | 1 + src/shared/verbs.h | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) 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, \