From: Zbigniew Jędrzejewski-Szmek Date: Fri, 10 Apr 2026 14:41:54 +0000 (+0200) Subject: shared/verbs: add _SCOPE variants of the verb macros X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4f6fdbcf7a1c3b7c6ad18a9f7ec717c6ed2ce4af;p=thirdparty%2Fsystemd.git shared/verbs: add _SCOPE variants of the verb macros In some of the large programs, verbs are defined as non-static functions. To support this cases, add variants of the VERB macros that take an explicit scope parameter. The existing macros then call those new macros with scope=static. The variant without static is the exception, so the macros are "optimized" toward the static helpers. I also considered allowing VERB macros to be used in different files, i.e. in different compilation units. This would actually work without too many changes, except for one caveat: the order in the array would be unspecified, so we'd need to somehow order the verbs appropriately. This most likely means that the verbs would need to be annotated with a number. But that doesn't seem attractive at all: we'd need to coordinate changes in different files. So just listing the verbs in one file seems like least bad option. --- diff --git a/src/shared/verbs.h b/src/shared/verbs.h index 51a9e3a5253..4fb0486f756 100644 --- a/src/shared/verbs.h +++ b/src/shared/verbs.h @@ -39,19 +39,27 @@ typedef struct { .help = h, \ } -#define VERB_FULL(d, v, a, amin, amax, f, dat, h) \ +/* Forward-define function d. scope specifies the scope, e.g. static. */ +#define VERB_SCOPE_FULL(scope, d, v, a, amin, amax, f, dat, h) \ DISABLE_WARNING_REDUNDANT_DECLS \ - static int d(int, char**, uintptr_t, void*); \ + scope int d(int, char**, uintptr_t, void*); \ REENABLE_WARNING \ _VERB_DATA(d, v, a, amin, amax, f, dat, h) +/* The same as VERB_SCOPE_FULL with scope hardwired to 'static'. */ +#define VERB_FULL(d, v, a, amin, amax, f, dat, h) \ + VERB_SCOPE_FULL(static, d, v, a, amin, amax, f, dat, h) -/* The same as VERB_FULL, but without the data argument */ +/* The same as VERB_SCOPE_FULL/VERB_FULL, but without the data argument. */ +#define VERB_SCOPE(scope, d, v, a, amin, amax, f, h) \ + VERB_SCOPE_FULL(scope, d, v, a, amin, amax, f, /* dat= */ 0, h) #define VERB(d, v, a, amin, amax, f, h) \ - VERB_FULL(d, v, a, amin, amax, f, /* dat= */ 0, h) + VERB_SCOPE(static, d, v, a, amin, amax, f, h) -/* Simplified VERB for parameters that take no argument */ +/* Simplified VERB_SCOPE/VERB for verbs that take no argument. */ +#define VERB_SCOPE_NOARG(scope, d, v, h) \ + VERB_SCOPE(scope, d, v, /* a= */ NULL, /* amin= */ VERB_ANY, /* amax= */ 1, /* f= */ 0, h) #define VERB_NOARG(d, v, h) \ - VERB(d, v, /* a= */ NULL, /* amin= */ VERB_ANY, /* amax= */ 1, /* f= */ 0, h) + VERB_SCOPE_NOARG(static, d, v, h) /* Magic entry in the table (which will not be returned) that designates the start of the group . * The macro works as a separator between groups and must be between other VERB* stanzas. */