diff --git a/Include/cpython/pyatomic.h b/Include/cpython/pyatomic.h index b4b1a8ca87dd8b..71a76bdc82ce47 100644 --- a/Include/cpython/pyatomic.h +++ b/Include/cpython/pyatomic.h @@ -585,7 +585,7 @@ static inline void _Py_atomic_fence_release(void); # define Py_ATOMIC_GCC_H # include "pyatomic_gcc.h" # undef Py_ATOMIC_GCC_H -#elif __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__) +#elif _Py_STDC_VERSION >= 201112L && !defined(__STDC_NO_ATOMICS__) # define Py_ATOMIC_STD_H # include "pyatomic_std.h" # undef Py_ATOMIC_STD_H diff --git a/Include/pymacro.h b/Include/pymacro.h index 41dfd9155b9b24..73521be00fcd1a 100644 --- a/Include/pymacro.h +++ b/Include/pymacro.h @@ -1,6 +1,13 @@ #ifndef Py_PYMACRO_H #define Py_PYMACRO_H +// _Py_STDC_VERSION: the version of the C standard. +// gh-160208: The C++ standard allows __STDC_VERSION__ to be defined to an +// arbitrary value, which means we can't use __STDC_VERSION__ on C++. +#if !defined(__cplusplus) && defined(__STDC_VERSION__) +# define _Py_STDC_VERSION __STDC_VERSION__ +#endif + // gh-91782: On FreeBSD 12, if the _POSIX_C_SOURCE and _XOPEN_SOURCE macros are // defined, disables C11 support and does not define // the static_assert() macro. @@ -18,8 +25,8 @@ // behaviour. So only define if building as C, not C++ (if __cplusplus is // not defined), and only for C11-17. #if !defined(static_assert) && (defined(__GNUC__) || defined(__clang__)) \ - && !defined(__cplusplus) && defined(__STDC_VERSION__) \ - && __STDC_VERSION__ >= 201112L && __STDC_VERSION__ <= 201710L + && !defined(_Py_STDC_VERSION) \ + && _Py_STDC_VERSION >= 201112L && _Py_STDC_VERSION <= 201710L # define static_assert _Static_assert #endif @@ -75,9 +82,9 @@ # endif # elif defined(_MSC_VER) # define _Py_ALIGNED_DEF(N, T) __declspec(align(N)) T -# elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +# elif defined(_Py_STDC_VERSION) && _Py_STDC_VERSION >= 202311L # define _Py_ALIGNED_DEF(N, T) alignas(N) alignas(T) T -# elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +# elif defined(_Py_STDC_VERSION) && _Py_STDC_VERSION >= 201112L # define _Py_ALIGNED_DEF(N, T) _Alignas(N) _Alignas(T) T # elif (defined(__GNUC__) || defined(__clang__)) # define _Py_ALIGNED_DEF(N, T) __attribute__((aligned(N))) T @@ -100,7 +107,7 @@ // predefined value of _Py_ANONYMOUS if it exists. #ifndef _Py_ANONYMOUS # if (defined(__GNUC__) || defined(__clang__)) \ - && !(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) + && !(defined(_Py_STDC_VERSION) && _Py_STDC_VERSION >= 201112L) # define _Py_ANONYMOUS __extension__ # else # define _Py_ANONYMOUS @@ -162,7 +169,7 @@ /* Argument must be a char or an int in [-128, 127] or [0, 255]. */ #define Py_CHARMASK(c) ((unsigned char)((c) & 0xff)) -#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L \ +#if (defined(_Py_STDC_VERSION) && _Py_STDC_VERSION >= 201112L \ && !defined(__cplusplus) && !defined(_MSC_VER)) # define Py_BUILD_ASSERT_EXPR(cond) \ ((void)sizeof(struct { int dummy; _Static_assert(cond, #cond); }), \ @@ -185,7 +192,7 @@ (sizeof(char [1 - 2*!(cond)]) - 1) #endif -#if ((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) \ +#if ((defined(_Py_STDC_VERSION) && _Py_STDC_VERSION >= 201112L) \ || (defined(__cplusplus) && __cplusplus >= 201103L)) // Use static_assert() on C11 and newer # define Py_BUILD_ASSERT(cond) \ diff --git a/Include/pyport.h b/Include/pyport.h index 1af2b61eeacd28..af8c7c1cdc208a 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -50,7 +50,7 @@ // to prevent C++ compiler warnings. On C23 and newer and on C++11 and newer, // _Py_NULL is defined as nullptr. #if !defined(_MSC_VER) && \ - ((defined (__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) \ + ((defined (_Py_STDC_VERSION) && _Py_STDC_VERSION >= 202311L) \ || (defined(__cplusplus) && __cplusplus >= 201103)) # define _Py_NULL nullptr #else @@ -491,7 +491,7 @@ extern "C" { #ifdef WITH_THREAD # ifdef thread_local # define _Py_thread_local thread_local -# elif __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__) +# elif _Py_STDC_VERSION >= 201112L && !defined(__STDC_NO_THREADS__) # define _Py_thread_local _Thread_local # elif defined(_MSC_VER) /* AKA NT_THREADS */ # define _Py_thread_local __declspec(thread) @@ -543,7 +543,7 @@ extern "C" { // // gh-157649: Do not use decltype() on C++, since it produces invalid code in // Py_CLEAR()/Py_SETREF(). -#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#if defined (_Py_STDC_VERSION) && _Py_STDC_VERSION >= 202311L # define _Py_TYPEOF(expr) typeof(expr) #elif (defined(__GNUC__) || defined(__clang__) \ || (defined(_MSC_VER) && _MSC_VER >= 1939 && !defined(__cplusplus))) diff --git a/Modules/_ctypes/_ctypes_test.c b/Modules/_ctypes/_ctypes_test.c index 93c54af243242b..900dba34fc7296 100644 --- a/Modules/_ctypes/_ctypes_test.c +++ b/Modules/_ctypes/_ctypes_test.c @@ -13,16 +13,6 @@ #include -#ifdef thread_local -# define _Py_thread_local thread_local -#elif __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__) -# define _Py_thread_local _Thread_local -#elif defined(_MSC_VER) /* AKA NT_THREADS */ -# define _Py_thread_local __declspec(thread) -#elif defined(__GNUC__) /* includes clang */ -# define _Py_thread_local __thread -#endif - #if defined(_Py_FFI_SUPPORT_C_COMPLEX) # include // csqrt() # undef I // for _ctypes_test_generated.c.h diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index 5e100da7a42417..7b8348d25e5d97 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -2694,7 +2694,7 @@ static PyObject * math_issubnormal_impl(PyObject *module, double x) /*[clinic end generated code: output=4e76ac98ddcae761 input=9a20aba7107d0d95]*/ { -#if !defined(_MSC_VER) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#if !defined(_MSC_VER) && defined(_Py_STDC_VERSION) && _Py_STDC_VERSION >= 202311L return PyBool_FromLong(issubnormal(x)); #else return PyBool_FromLong(isfinite(x) && x && !isnormal(x));