Skip to content

Commit ae44ccb

Browse files
skdas20claude
andcommitted
gh-160719: Define _Py_STDC_VERSION in pyport.h
pyport.h uses _Py_STDC_VERSION to select _Py_thread_local, _Py_NULL and _Py_TYPEOF, but the macro was defined in pymacro.h, which Python.h includes after pyport.h. The C11 and C23 branches were therefore never taken. Move the definition to pyport.h. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 3acc941 commit ae44ccb

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

‎Include/pymacro.h‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
#ifndef Py_PYMACRO_H
22
#define Py_PYMACRO_H
33

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
4+
// _Py_STDC_VERSION is defined in pyport.h, which is included before this file.
105

116
// gh-91782: On FreeBSD 12, if the _POSIX_C_SOURCE and _XOPEN_SOURCE macros are
127
// defined, <sys/cdefs.h> disables C11 support and <assert.h> does not define

‎Include/pyport.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
# error "Python's source code assumes C's unsigned char is an 8-bit type"
99
#endif
1010

11+
// _Py_STDC_VERSION: the version of the C standard.
12+
// gh-160208: The C++ standard allows __STDC_VERSION__ to be defined to an
13+
// arbitrary value, which means we can't use __STDC_VERSION__ on C++.
14+
// gh-160719: Defined here, rather than in pymacro.h, because this file uses it
15+
// and is included before pymacro.h.
16+
#if !defined(__cplusplus) && defined(__STDC_VERSION__)
17+
# define _Py_STDC_VERSION __STDC_VERSION__
18+
#endif
19+
1120

1221
// Preprocessor check for a builtin preprocessor function. Always return 0
1322
// if __has_builtin() macro is not defined.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Fix the C11 and C23 code paths in :file:`pyport.h` never being used: the
2+
private ``_Py_STDC_VERSION`` macro was defined in :file:`pymacro.h`, which is
3+
included after :file:`pyport.h`, so ``_Py_thread_local``, ``_Py_NULL`` and
4+
``_Py_TYPEOF`` fell back to compiler extensions instead of ``_Thread_local``,
5+
``nullptr`` and ``typeof``.

0 commit comments

Comments
 (0)