gh-109723: Disable Py_BUILD_CORE in _testcapi (#109727)

Make sure that the internal C API is not tested by mistake by
_testcapi.

Undefine Py_BUILD_CORE_BUILTIN and Py_BUILD_CORE_MODULE macros in
Modules/_testcapi/parts.h: move code from _testcapimodule.c.

heaptype_relative.c and vectorcall_limited.c are using the limited C
API which is incompatible with the internal C API.

Move test_long_numbits() from _testcapi to _testinternalcapi since it
uses the internal C API "pycore_long.h".

Fix Modules/_testcapi/pyatomic.c: don't include Python.h directly,
just include _testcapi/parts.h.

Ajust "make check-c-globals" for these changes.
This commit is contained in:
Victor Stinner 2023-09-22 16:54:37 +02:00 committed by GitHub
parent c32abf1f21
commit 09a25616a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 114 additions and 101 deletions

View file

@ -3,18 +3,20 @@ import re
from . import common as _common
# The following C files define the Py_LIMITED_API macro, and so must not be
# built with the Py_BUILD_CORE macro defined.
USE_LIMITED_C_API = frozenset((
# The following C files must not built with Py_BUILD_CORE.
FILES_WITHOUT_INTERNAL_CAPI = frozenset((
# Modules/
'_testcapimodule.c',
'_testclinic_limited.c',
'xxlimited.c',
'xxlimited_35.c',
))
# C files in the fhe following directories must not be built with
# Py_BUILD_CORE.
DIRS_WITHOUT_INTERNAL_CAPI = frozenset((
# Modules/_testcapi/
'heaptype_relative.c',
'vectorcall_limited.c',
'_testcapi',
))
TOOL = 'gcc'
@ -75,7 +77,10 @@ def preprocess(filename,
filename = _normpath(filename, cwd)
postargs = POST_ARGS
if os.path.basename(filename) not in USE_LIMITED_C_API:
basename = os.path.basename(filename)
dirname = os.path.basename(os.path.dirname(filename))
if (basename not in FILES_WITHOUT_INTERNAL_CAPI
and dirname not in DIRS_WITHOUT_INTERNAL_CAPI):
postargs += ('-DPy_BUILD_CORE=1',)
text = _common.preprocess(