Skip to content

gh-162214: Test Py_GIL_DISABLED macro using #ifdef - #162223

Merged
vstinner merged 1 commit into
python:mainfrom
vstinner:wundef_gil
Nov 18, 2026
Merged

vstinner merged 1 commit into
python:mainfrom
vstinner:wundef_gil

Conversation

@vstinner

@vstinner vstinner commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Replace "#if Py_GIL_DISABLED" with "#ifdef Py_GIL_DISABLED" to fix compiler warnings when building Python with -Wundef.

Example of fixed warning:

Objects/unicodeobject.c:14740:5: warning: 'Py_GIL_DISABLED'
is not defined, evaluates to '0' [-Wundef]
14740 | #if Py_GIL_DISABLED
      |     ^~~~~~~~~~~~~~~

Simplify also Py_GIL_DISABLED == 0 test in PC/pyconfig.h.

Replace "#if Py_GIL_DISABLED" with "#ifdef Py_GIL_DISABLED" to fix
compiler warnings when building Python with -Wundef.

Example of fixed warning:

    Objects/unicodeobject.c:14740:5: warning: 'Py_GIL_DISABLED'
    is not defined, evaluates to '0' [-Wundef]
    14740 | #if Py_GIL_DISABLED
          |     ^~~~~~~~~~~~~~~

Simplify also Py_GIL_DISABLED == 0 test in PC/pyconfig.h.
@vstinner

Copy link
Copy Markdown
Member Author

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

  AC_DEFINE([Py_GIL_DISABLED], [1],
            [Define if you want to disable the GIL])

Corresponding code in PCbuild/pyproject.props:

    <_FreeThreadedPreprocessorDefinition Condition="$(DisableGil) == 'true'">Py_GIL_DISABLED=1;</_FreeThreadedPreprocessorDefinition>

@vstinner
vstinner merged commit 59a7a46 into python:main Nov 18, 2026
81 of 82 checks passed
@vstinner
vstinner deleted the wundef_gil branch November 18, 2026 21:01
@vstinner

Copy link
Copy Markdown
Member Author

Merged. Thanks for the review @zooba!

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.

2 participants