Skip to content
Next Next commit
gh-146636: abi3t: Test that Python.h avoids checking Py_GIL_DISABLED
Add a test that Python headers themselves don't use
Py_GIL_DISABLED in abi3t: abi3 and abi3t ought to be the
same except the _Py_OPAQUE_PYOBJECT differences.
This is done using the GCC-only poison pragma.
  • Loading branch information
encukou committed Apr 9, 2026
commit 1116e1ece97d7498c886d7a73ad4aa800d180eed
11 changes: 11 additions & 0 deletions Include/pyport.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@
// locking needed in for free-threaded interpreters builds.
# define Py_GIL_DISABLED
# endif
# if defined(_Py_IS_TESTCEXT)
// When compiling for abi3t, contents of Python.h should not depend
// on Py_GIL_DISABLED.
// We ask GCC to error if it sees the macro from this point on.
// Since users are free to the macro, and there's no way to undo the poisoning
// at the end of Python.h, we only do this in a test module.
# ifdef __GNUC__
# undef Py_GIL_DISABLED
# pragma GCC poison Py_GIL_DISABLED
# endif
# endif
#endif


Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_cext/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
# The purpose of test_cext extension is to check that building a C
# extension using the Python C API does not emit C compiler warnings.
'-Werror',
# Enable extra checks for header files, which:
# - need to be enabled somewhere inside Python headers (rather than
# before including Python.h)
# - should not be checked for user code
'-D_Py_IS_TESTCEXT',
]

# C compiler flags for GCC and clang
Expand Down