From d8e37a72538badfd5228baea266c64eeb3532f7c Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 18 Nov 2026 17:29:46 +0100 Subject: [PATCH 1/2] gh-162214: Test Py_STATS macro using #ifdef 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 | ^~~~~~~~ --- Python/pystate.c | 2 +- Python/specialize.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Python/pystate.c b/Python/pystate.c index ce7197c4e05428..4c95669f9fa1b0 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 067bae59f6073b..b5cf4ebc31142a 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) From 009f9bf48a952696225d38af9b5b7b7ae17dbf0b Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 18 Nov 2026 17:32:53 +0100 Subject: [PATCH 2/2] On Windows, define Py_STATS macro to 1 when it's defined --- PCbuild/pyproject.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PCbuild/pyproject.props b/PCbuild/pyproject.props index ca8330c004ccce..67296c22806c3e 100644 --- a/PCbuild/pyproject.props +++ b/PCbuild/pyproject.props @@ -52,7 +52,7 @@ <_DebugPreprocessorDefinition>NDEBUG; <_DebugPreprocessorDefinition Condition="$(Configuration) == 'Debug'">_DEBUG; <_PyStatsPreprocessorDefinition>PyStats; - <_PyStatsPreprocessorDefinition Condition="$(PySTATS) != ''">Py_STATS; + <_PyStatsPreprocessorDefinition Condition="$(PySTATS) != ''">Py_STATS=1; <_PlatformPreprocessorDefinition>_WIN32; <_PlatformPreprocessorDefinition Condition="$(Platform) == 'x64'">_WIN64; <_PlatformPreprocessorDefinition Condition="$(Platform) == 'x64' and $(PlatformToolset) != 'ClangCL'">_M_X64;$(_PlatformPreprocessorDefinition)