mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-23 06:41:32 +02:00
The "flags" utility is useful but painful to maintain up to date. This commit aims at providing a low-maintenance solution to keep flags up to date, by proposing some macros that build a string from a set of flags in a way that requires the least possible verbosity. The idea will be to add an inline function dedicated to this just after the flags declaration, and enumerate the flags one is interested in, and that function will fill a string based on them. Placing this inside the type files allows both haproxy and external tools like "flags" to use it, but comes with a few constraints. First, the files will be slightly less readable if these functions are huge, so they need to stay as compact as possible. Second, the function will need anprintf() and we don't want to include stdio.h in type files as it proved to be particularly heavy and to cause definition headaches in the past. As such the file here only contains a macro enclosed in #ifdef EOF (that is defined in stdio), and provides an alternate empty one when no stdio is defined. This way it's the caller that has to include stdio first or it won't get anything back, and in practice the locations relying on this always have it. The macro has to be used in 3 steps: - prologue: dumps 0 and exits if the value is zero - flags: the macro can be recursively called and it will push the flag from bottom to top so that they appear in the same order as today without requiring to be declared the other way around - epilogue: dump remaining flags that were not identified The macro was arranged so that a single character can be used with no other argument to declare all flags at once. Example: #define _(n, ...) __APPEND_FLAG(buf, len, del, flg, n, #n, __VA_ARGS__) _(0); _(X_FLAG1, _(X_FLAG2, _(X_FLAG3, _(X_FLAG4)))); _(~0); #undef _ Existing files will have to be updated to rely on it, and more files could come soon.