BUILD: compiler: add a macro to detect if another one is set and equals 1

In order to simplify compiler-specific checks, we'll need to check if some
attributes exist. In order to ease declarations, we'll only focus on those
that exist and will set them to 1. Let's first add a macro aimed at doing
this. Passed a macro name in argument, it will return 1 if the macro is
defined and equals 1, otherwise it will return 0. This is based on the
concatenation of the macro's value with a name to form the name of a macro
which contains one comma, resulting in some other macros arguments being
shifted by one when the macro is defined. As such it's only a matter of
pushing both a 1 and a 0 and picking the correct argument to see the
desired one. It was verified to work since at least gcc-3.4 so it should
be portable enough.
This commit is contained in:
Willy Tarreau 2022-11-13 11:32:45 +01:00
parent 71de04134e
commit 08e09f0b3c

View File

@ -37,6 +37,18 @@
#endif
#endif
/* This is used to test if a macro is defined and equals 1. The principle is
* that the macro is passed as a value and its value concatenated to the word
* "comma_for_one" to form a new macro name. The macro "comma_for_one1" equals
* one comma, which, once used in an argument, will shift all of them by one,
* so that we can use this to concatenate both a 1 and a 0 and always pick the
* second one.
*/
#define comma_for_one1 ,
#define ____equals_1(x, y, ...) (y)
#define ___equals_1(x, ...) ____equals_1(x, 0)
#define __equals_1(x) ___equals_1(comma_for_one ## x 1)
#if !defined(__GNUC__)
/* Some versions of glibc irresponsibly redefine __attribute__() to empty for
* non-gcc compilers, and as such, silently break all constructors with other