Skip to content

Commit 1116e1e

Browse files
committed
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.
1 parent 8000a9d commit 1116e1e

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Include/pyport.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@
8383
// locking needed in for free-threaded interpreters builds.
8484
# define Py_GIL_DISABLED
8585
# endif
86+
# if defined(_Py_IS_TESTCEXT)
87+
// When compiling for abi3t, contents of Python.h should not depend
88+
// on Py_GIL_DISABLED.
89+
// We ask GCC to error if it sees the macro from this point on.
90+
// Since users are free to the macro, and there's no way to undo the poisoning
91+
// at the end of Python.h, we only do this in a test module.
92+
# ifdef __GNUC__
93+
# undef Py_GIL_DISABLED
94+
# pragma GCC poison Py_GIL_DISABLED
95+
# endif
96+
# endif
8697
#endif
8798

8899

Lib/test/test_cext/setup.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
# The purpose of test_cext extension is to check that building a C
1919
# extension using the Python C API does not emit C compiler warnings.
2020
'-Werror',
21+
# Enable extra checks for header files, which:
22+
# - need to be enabled somewhere inside Python headers (rather than
23+
# before including Python.h)
24+
# - should not be checked for user code
25+
'-D_Py_IS_TESTCEXT',
2126
]
2227

2328
# C compiler flags for GCC and clang

0 commit comments

Comments
 (0)