|
1 | 1 | #ifndef Py_PYMACRO_H |
2 | 2 | #define Py_PYMACRO_H |
3 | 3 |
|
| 4 | +// _Py_STDC_VERSION: the version of the C standard. |
| 5 | +// gh-160208: The C++ standard allows __STDC_VERSION__ to be defined to an |
| 6 | +// arbitrary value, which means we can't use __STDC_VERSION__ on C++. |
| 7 | +#if !defined(__cplusplus) && defined(__STDC_VERSION__) |
| 8 | +# define _Py_STDC_VERSION __STDC_VERSION__ |
| 9 | +#endif |
| 10 | + |
4 | 11 | // gh-91782: On FreeBSD 12, if the _POSIX_C_SOURCE and _XOPEN_SOURCE macros are |
5 | 12 | // defined, <sys/cdefs.h> disables C11 support and <assert.h> does not define |
6 | 13 | // the static_assert() macro. |
|
18 | 25 | // behaviour. So only define if building as C, not C++ (if __cplusplus is |
19 | 26 | // not defined), and only for C11-17. |
20 | 27 | #if !defined(static_assert) && (defined(__GNUC__) || defined(__clang__)) \ |
21 | | - && !defined(__cplusplus) && defined(__STDC_VERSION__) \ |
22 | | - && __STDC_VERSION__ >= 201112L && __STDC_VERSION__ <= 201710L |
| 28 | + && !defined(_Py_STDC_VERSION) \ |
| 29 | + && _Py_STDC_VERSION >= 201112L && _Py_STDC_VERSION <= 201710L |
23 | 30 | # define static_assert _Static_assert |
24 | 31 | #endif |
25 | 32 |
|
|
75 | 82 | # endif |
76 | 83 | # elif defined(_MSC_VER) |
77 | 84 | # define _Py_ALIGNED_DEF(N, T) __declspec(align(N)) T |
78 | | -# elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L |
| 85 | +# elif defined(_Py_STDC_VERSION) && _Py_STDC_VERSION >= 202311L |
79 | 86 | # define _Py_ALIGNED_DEF(N, T) alignas(N) alignas(T) T |
80 | | -# elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L |
| 87 | +# elif defined(_Py_STDC_VERSION) && _Py_STDC_VERSION >= 201112L |
81 | 88 | # define _Py_ALIGNED_DEF(N, T) _Alignas(N) _Alignas(T) T |
82 | 89 | # elif (defined(__GNUC__) || defined(__clang__)) |
83 | 90 | # define _Py_ALIGNED_DEF(N, T) __attribute__((aligned(N))) T |
|
100 | 107 | // predefined value of _Py_ANONYMOUS if it exists. |
101 | 108 | #ifndef _Py_ANONYMOUS |
102 | 109 | # if (defined(__GNUC__) || defined(__clang__)) \ |
103 | | - && !(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) |
| 110 | + && !(defined(_Py_STDC_VERSION) && _Py_STDC_VERSION >= 201112L) |
104 | 111 | # define _Py_ANONYMOUS __extension__ |
105 | 112 | # else |
106 | 113 | # define _Py_ANONYMOUS |
|
137 | 144 | /* Argument must be a char or an int in [-128, 127] or [0, 255]. */ |
138 | 145 | #define Py_CHARMASK(c) ((unsigned char)((c) & 0xff)) |
139 | 146 |
|
140 | | -#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L \ |
| 147 | +#if (defined(_Py_STDC_VERSION) && _Py_STDC_VERSION >= 201112L \ |
141 | 148 | && !defined(__cplusplus) && !defined(_MSC_VER)) |
142 | 149 | # define Py_BUILD_ASSERT_EXPR(cond) \ |
143 | 150 | ((void)sizeof(struct { int dummy; _Static_assert(cond, #cond); }), \ |
|
160 | 167 | (sizeof(char [1 - 2*!(cond)]) - 1) |
161 | 168 | #endif |
162 | 169 |
|
163 | | -#if ((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) \ |
| 170 | +#if ((defined(_Py_STDC_VERSION) && _Py_STDC_VERSION >= 201112L) \ |
164 | 171 | || (defined(__cplusplus) && __cplusplus >= 201103L)) |
165 | 172 | // Use static_assert() on C11 and newer |
166 | 173 | # define Py_BUILD_ASSERT(cond) \ |
|
0 commit comments