diff --git a/Include/pymacro.h b/Include/pymacro.h index 73521be00fcd1ad..cde2a5fd05ad585 100644 --- a/Include/pymacro.h +++ b/Include/pymacro.h @@ -1,12 +1,7 @@ #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 +// _Py_STDC_VERSION is defined in pyport.h, which is included before this file. // gh-91782: On FreeBSD 12, if the _POSIX_C_SOURCE and _XOPEN_SOURCE macros are // defined, disables C11 support and does not define diff --git a/Include/pyport.h b/Include/pyport.h index 3de7fb3d317521a..821e68ee89e23f7 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -8,6 +8,15 @@ # error "Python's source code assumes C's unsigned char is an 8-bit type" #endif +// _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++. +// gh-160719: Defined here, rather than in pymacro.h, because this file uses it +// and is included before pymacro.h. +#if !defined(__cplusplus) && defined(__STDC_VERSION__) +# define _Py_STDC_VERSION __STDC_VERSION__ +#endif + // Preprocessor check for a builtin preprocessor function. Always return 0 // if __has_builtin() macro is not defined. diff --git a/Misc/NEWS.d/next/C_API/2026-10-26-19-10-00.gh-issue-160719.F9F7fw.rst b/Misc/NEWS.d/next/C_API/2026-10-26-19-10-00.gh-issue-160719.F9F7fw.rst new file mode 100644 index 000000000000000..622afb2d70cfee0 --- /dev/null +++ b/Misc/NEWS.d/next/C_API/2026-10-26-19-10-00.gh-issue-160719.F9F7fw.rst @@ -0,0 +1,5 @@ +Fix the C11 and C23 code paths in :file:`pyport.h` never being used: the +private ``_Py_STDC_VERSION`` macro was defined in :file:`pymacro.h`, which is +included after :file:`pyport.h`, so ``_Py_thread_local``, ``_Py_NULL`` and +``_Py_TYPEOF`` fell back to compiler extensions instead of ``_Thread_local``, +``nullptr`` and ``typeof``.