Skip to content

Commit 172135c

Browse files
authored
gh-144490: Fix test_cppext: test the internal C API (#144536)
Add missing TEST_INTERNAL_C_API env var.
1 parent 0fdf6a9 commit 172135c

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

Lib/test/test_cppext/__init__.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,11 @@
2525
@support.requires_subprocess()
2626
@support.requires_resource('cpu')
2727
class BaseTests:
28+
TEST_INTERNAL_C_API = False
29+
2830
def test_build(self):
2931
self.check_build('_testcppext')
3032

31-
def test_build_cpp03(self):
32-
# In public docs, we say C API is compatible with C++11. However,
33-
# in practice we do maintain C++03 compatibility in public headers.
34-
# Please ask the C API WG before adding a new C++11-only feature.
35-
self.check_build('_testcpp03ext', std='c++03')
36-
37-
@unittest.skipIf(support.MS_WINDOWS, "MSVC doesn't support /std:c++11")
38-
def test_build_cpp11(self):
39-
self.check_build('_testcpp11ext', std='c++11')
40-
41-
# Only test C++14 on MSVC.
42-
# On s390x RHEL7, GCC 4.8.5 doesn't support C++14.
43-
@unittest.skipIf(not support.MS_WINDOWS, "need Windows")
44-
def test_build_cpp14(self):
45-
self.check_build('_testcpp14ext', std='c++14')
46-
4733
def check_build(self, extension_name, std=None, limited=False):
4834
venv_dir = 'env'
4935
with support.setup_venv_with_pip_setuptools(venv_dir) as python_exe:
@@ -63,6 +49,7 @@ def run_cmd(operation, cmd):
6349
if limited:
6450
env['CPYTHON_TEST_LIMITED'] = '1'
6551
env['CPYTHON_TEST_EXT_NAME'] = extension_name
52+
env['TEST_INTERNAL_C_API'] = str(int(self.TEST_INTERNAL_C_API))
6653
if support.verbose:
6754
print('Run:', ' '.join(map(shlex.quote, cmd)))
6855
subprocess.run(cmd, check=True, env=env)
@@ -112,6 +99,22 @@ def test_build_limited_cpp03(self):
11299
def test_build_limited(self):
113100
self.check_build('_testcppext_limited', limited=True)
114101

102+
def test_build_cpp03(self):
103+
# In public docs, we say C API is compatible with C++11. However,
104+
# in practice we do maintain C++03 compatibility in public headers.
105+
# Please ask the C API WG before adding a new C++11-only feature.
106+
self.check_build('_testcpp03ext', std='c++03')
107+
108+
@unittest.skipIf(support.MS_WINDOWS, "MSVC doesn't support /std:c++11")
109+
def test_build_cpp11(self):
110+
self.check_build('_testcpp11ext', std='c++11')
111+
112+
# Only test C++14 on MSVC.
113+
# On s390x RHEL7, GCC 4.8.5 doesn't support C++14.
114+
@unittest.skipIf(not support.MS_WINDOWS, "need Windows")
115+
def test_build_cpp14(self):
116+
self.check_build('_testcpp14ext', std='c++14')
117+
115118

116119
class TestInteralCAPI(BaseTests, unittest.TestCase):
117120
TEST_INTERNAL_C_API = True

Lib/test/test_cppext/extension.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,22 @@
77
#undef NDEBUG
88

99
#ifdef TEST_INTERNAL_C_API
10-
# define Py_BUILD_CORE 1
10+
# define Py_BUILD_CORE_MODULE 1
1111
#endif
1212

1313
#include "Python.h"
1414

1515
#ifdef TEST_INTERNAL_C_API
1616
// gh-135906: Check for compiler warnings in the internal C API
17-
# include "internal/pycore_backoff.h"
1817
# include "internal/pycore_frame.h"
18+
// mimalloc emits many compiler warnings when Python is built in debug
19+
// mode (when MI_DEBUG is not zero)
20+
// mimalloc emits compiler warnings when Python is built on Windows
21+
// in free-threaded mode.
22+
# if !defined(Py_DEBUG) && !(defined(MS_WINDOWS) && defined(Py_GIL_DISABLED))
23+
# include "internal/pycore_backoff.h"
24+
# include "internal/pycore_cell.h"
25+
# endif
1926
#endif
2027

2128
#ifndef MODULE_NAME

0 commit comments

Comments
 (0)