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

@ -5,19 +5,13 @@
* standard Python regression test, via Lib/test/test_capi.py.
*/
/* This module tests the public (Include/ and Include/cpython/) C API.
The internal C API must not be used here: use _testinternalcapi for that.
// Include parts.h first since it takes care of NDEBUG and Py_BUILD_CORE macros
// and including Python.h.
//
// Several parts of this module are broken out into files in _testcapi/.
// Include definitions from there.
#include "_testcapi/parts.h"
The Visual Studio projects builds _testcapi with Py_BUILD_CORE_MODULE
macro defined, but only the public C API must be tested here. */
#undef Py_BUILD_CORE_MODULE
#undef Py_BUILD_CORE_BUILTIN
/* Always enable assertions */
#undef NDEBUG
#include "Python.h"
#include "frameobject.h" // PyFrame_New()
#include "marshal.h" // PyMarshal_WriteLongToFile()
@ -29,17 +23,10 @@
# include <sys/wait.h> // W_STOPCODE
#endif
#ifdef Py_BUILD_CORE
# error "_testcapi must test the public Python C API, not CPython internal C API"
#endif
#ifdef bool
# error "The public headers should not include <stdbool.h>, see gh-48924"
#endif
// Several parts of this module are broken out into files in _testcapi/.
// Include definitions from there.
#include "_testcapi/parts.h"
#include "_testcapi/util.h"