https://github.com/python/cpython/commit/fce90ca6d1a90b40c94694991bb200fb26355bdd
commit: fce90ca6d1a90b40c94694991bb200fb26355bdd
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2026-11-18T22:08:34+01:00
summary:
gh-162214: Test Py_STATS macro using #ifdef (#162225)
Replace "#if Py_STATS" with "#ifdef Py_STATS".
All other C files already check for "#ifdef Py_STATS".
Example of fixed compiler warning when building Python with -Wundef:
Python/specialize.c:33:5: warning: 'Py_STATS' is not defined,
evaluates to '0' [-Wundef]
33 | #if Py_STATS
| ^~~~~~~~
On Windows, the Py_STATS macro is now defined to 1 when it's defined.
files:
M PCbuild/pyproject.props
M Python/pystate.c
M Python/specialize.c
diff --git a/PCbuild/pyproject.props b/PCbuild/pyproject.props
index ca8330c004cccea..67296c22806c3e4 100644
--- a/PCbuild/pyproject.props
+++ b/PCbuild/pyproject.props
@@ -52,7 +52,7 @@
<_DebugPreprocessorDefinition>NDEBUG;</_DebugPreprocessorDefinition>
<_DebugPreprocessorDefinition Condition="$(Configuration) ==
'Debug'">_DEBUG;</_DebugPreprocessorDefinition>
<_PyStatsPreprocessorDefinition>PyStats;</_PyStatsPreprocessorDefinition>
- <_PyStatsPreprocessorDefinition Condition="$(PySTATS) !=
''">Py_STATS;</_PyStatsPreprocessorDefinition>
+ <_PyStatsPreprocessorDefinition Condition="$(PySTATS) !=
''">Py_STATS=1;</_PyStatsPreprocessorDefinition>
<_PlatformPreprocessorDefinition>_WIN32;</_PlatformPreprocessorDefinition>
<_PlatformPreprocessorDefinition Condition="$(Platform) ==
'x64'">_WIN64;</_PlatformPreprocessorDefinition>
<_PlatformPreprocessorDefinition Condition="$(Platform) == 'x64' and
$(PlatformToolset) !=
'ClangCL'">_M_X64;$(_PlatformPreprocessorDefinition)</_PlatformPreprocessorDefinition>
diff --git a/Python/pystate.c b/Python/pystate.c
index ce7197c4e054283..4c95669f9fa1b09 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -2294,7 +2294,7 @@ tstate_deactivate(PyThreadState *tstate)
assert(tstate_is_bound(tstate));
assert(tstate->_status.active);
-#if Py_STATS
+#ifdef Py_STATS
_PyStats_Detach((_PyThreadStateImpl *)tstate);
#endif
diff --git a/Python/specialize.c b/Python/specialize.c
index 067bae59f6073b7..b5cf4ebc31142ab 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -30,7 +30,7 @@
* InternalDocs/interpreter.md `Specialization` section.
*/
-#if Py_STATS
+#ifdef Py_STATS
#define SPECIALIZATION_FAIL(opcode, kind) \
do { \
PyStats *s = _PyStats_GET(); \
@@ -42,7 +42,7 @@ do { \
} while (0)
#else
# define SPECIALIZATION_FAIL(opcode, kind) ((void)0)
-#endif // Py_STATS
+#endif // !Py_STATS
static void
fixup_getiter(_Py_CODEUNIT *instruction, int flags)
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]