Skip to content

gh-162214: Test Py_STATS macro using #ifdef - #162225

Merged
vstinner merged 2 commits into
python:mainfrom
vstinner:wundef_stats
Nov 18, 2026
Merged

vstinner merged 2 commits into
python:mainfrom
vstinner:wundef_stats

Conversation

@vstinner

@vstinner vstinner commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

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 macro is now defined to 1 when it's defined.

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
          |     ^~~~~~~~
@vstinner

Copy link
Copy Markdown
Member Author

The macro is only defined to 1 by configure.ac using:

AS_VAR_IF([enable_pystats], [yes], [
  AC_DEFINE([Py_STATS], [1], [Define if you want to enable internal statistics gathering.])
])

Corresponding code in PCbuild/pyproject.props:

    <_PyStatsPreprocessorDefinition Condition="$(PySTATS) != ''">Py_STATS;</_PyStatsPreprocessorDefinition>

@vstinner
vstinner requested a review from a team as a code owner November 18, 2026 16:33
@vstinner
vstinner merged commit fce90ca into python:main Nov 18, 2026
54 checks passed
@vstinner
vstinner deleted the wundef_stats branch November 18, 2026 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant