diff options
Diffstat (limited to 'Include/pymacro.h')
-rw-r--r-- | Include/pymacro.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/Include/pymacro.h b/Include/pymacro.h index a82f347866e..218987a80b0 100644 --- a/Include/pymacro.h +++ b/Include/pymacro.h @@ -23,6 +23,47 @@ # define static_assert _Static_assert #endif + +// _Py_ALIGN_AS: this compiler's spelling of `alignas` keyword, +// We currently use alignas for free-threaded builds only; additional compat +// checking would be great before we add it to the default build. +// Standards/compiler support: +// - `alignas` is a keyword in C23 and C++11. +// - `_Alignas` is a keyword in C11 +// - GCC & clang has __attribute__((aligned)) +// (use that for older standards in pedantic mode) +// - MSVC has __declspec(align) +// - `_Alignas` is common C compiler extension +// Older compilers may name it differently; to allow compilation on such +// unsupported platforms, we don't redefine _Py_ALIGN_AS if it's already +// defined. Note that defining it wrong (including defining it to nothing) will +// cause ABI incompatibilities. +#ifdef Py_GIL_DISABLED +# ifndef _Py_ALIGN_AS +# ifdef __cplusplus +# if __cplusplus >= 201103L +# define _Py_ALIGN_AS(V) alignas(V) +# elif defined(__GNUC__) || defined(__clang__) +# define _Py_ALIGN_AS(V) __attribute__((aligned(V))) +# elif defined(_MSC_VER) +# define _Py_ALIGN_AS(V) __declspec(align(V)) +# else +# define _Py_ALIGN_AS(V) alignas(V) +# endif +# elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +# define _Py_ALIGN_AS(V) alignas(V) +# elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +# define _Py_ALIGN_AS(V) _Alignas(V) +# elif (defined(__GNUC__) || defined(__clang__)) +# define _Py_ALIGN_AS(V) __attribute__((aligned(V))) +# elif defined(_MSC_VER) +# define _Py_ALIGN_AS(V) __declspec(align(V)) +# else +# define _Py_ALIGN_AS(V) _Alignas(V) +# endif +# endif +#endif + /* Minimum value between x and y */ #define Py_MIN(x, y) (((x) > (y)) ? (y) : (x)) |