Skip to content

Commit 69588da

Browse files
committed
Test also the internal C API in test_cppext
1 parent 87eb7e1 commit 69588da

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

Lib/test/test_cppext/__init__.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
@support.requires_venv_with_pip()
2525
@support.requires_subprocess()
2626
@support.requires_resource('cpu')
27-
class TestCPPExt(unittest.TestCase):
27+
class BaseTests:
2828
def test_build(self):
2929
self.check_build('_testcppext')
3030

@@ -34,10 +34,6 @@ def test_build_cpp03(self):
3434
# Please ask the C API WG before adding a new C++11-only feature.
3535
self.check_build('_testcpp03ext', std='c++03')
3636

37-
@support.requires_gil_enabled('incompatible with Free Threading')
38-
def test_build_limited_cpp03(self):
39-
self.check_build('_test_limited_cpp03ext', std='c++03', limited=True)
40-
4137
@unittest.skipIf(support.MS_WINDOWS, "MSVC doesn't support /std:c++11")
4238
def test_build_cpp11(self):
4339
self.check_build('_testcpp11ext', std='c++11')
@@ -48,10 +44,6 @@ def test_build_cpp11(self):
4844
def test_build_cpp14(self):
4945
self.check_build('_testcpp14ext', std='c++14')
5046

51-
@support.requires_gil_enabled('incompatible with Free Threading')
52-
def test_build_limited(self):
53-
self.check_build('_testcppext_limited', limited=True)
54-
5547
def check_build(self, extension_name, std=None, limited=False):
5648
venv_dir = 'env'
5749
with support.setup_venv_with_pip_setuptools(venv_dir) as python_exe:
@@ -111,5 +103,19 @@ def run_cmd(operation, cmd):
111103
run_cmd('Import', cmd)
112104

113105

106+
class TestPublicCAPI(BaseTests, unittest.TestCase):
107+
@support.requires_gil_enabled('incompatible with Free Threading')
108+
def test_build_limited_cpp03(self):
109+
self.check_build('_test_limited_cpp03ext', std='c++03', limited=True)
110+
111+
@support.requires_gil_enabled('incompatible with Free Threading')
112+
def test_build_limited(self):
113+
self.check_build('_testcppext_limited', limited=True)
114+
115+
116+
class TestInteralCAPI(BaseTests, unittest.TestCase):
117+
TEST_INTERNAL_C_API = True
118+
119+
114120
if __name__ == "__main__":
115121
unittest.main()

Lib/test/test_cppext/extension.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,17 @@
66
// Always enable assertions
77
#undef NDEBUG
88

9+
#ifdef TEST_INTERNAL_C_API
10+
# define Py_BUILD_CORE 1
11+
#endif
12+
913
#include "Python.h"
1014

15+
#ifdef TEST_INTERNAL_C_API
16+
// gh-135906: Check for compiler warnings in the internal C API
17+
# include "internal/pycore_frame.h"
18+
#endif
19+
1120
#ifndef MODULE_NAME
1221
# error "MODULE_NAME macro must be defined"
1322
#endif

Lib/test/test_cppext/setup.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def main():
4747
std = os.environ.get("CPYTHON_TEST_CPP_STD", "")
4848
module_name = os.environ["CPYTHON_TEST_EXT_NAME"]
4949
limited = bool(os.environ.get("CPYTHON_TEST_LIMITED", ""))
50+
internal = bool(int(os.environ.get("TEST_INTERNAL_C_API", "0")))
5051

5152
cppflags = list(CPPFLAGS)
5253
cppflags.append(f'-DMODULE_NAME={module_name}')
@@ -82,6 +83,9 @@ def main():
8283
version = sys.hexversion
8384
cppflags.append(f'-DPy_LIMITED_API={version:#x}')
8485

86+
if internal:
87+
cppflags.append('-DTEST_INTERNAL_C_API=1')
88+
8589
# On Windows, add PCbuild\amd64\ to include and library directories
8690
include_dirs = []
8791
library_dirs = []

0 commit comments

Comments
 (0)