diff --git a/Lib/test/test_cppext/__init__.py b/Lib/test/test_cppext/__init__.py index 2f54b3ccb35cc4..9013503995bdce 100644 --- a/Lib/test/test_cppext/__init__.py +++ b/Lib/test/test_cppext/__init__.py @@ -25,25 +25,11 @@ @support.requires_subprocess() @support.requires_resource('cpu') class BaseTests: + TEST_INTERNAL_C_API = False + def test_build(self): self.check_build('_testcppext') - def test_build_cpp03(self): - # In public docs, we say C API is compatible with C++11. However, - # in practice we do maintain C++03 compatibility in public headers. - # Please ask the C API WG before adding a new C++11-only feature. - self.check_build('_testcpp03ext', std='c++03') - - @unittest.skipIf(support.MS_WINDOWS, "MSVC doesn't support /std:c++11") - def test_build_cpp11(self): - self.check_build('_testcpp11ext', std='c++11') - - # Only test C++14 on MSVC. - # On s390x RHEL7, GCC 4.8.5 doesn't support C++14. - @unittest.skipIf(not support.MS_WINDOWS, "need Windows") - def test_build_cpp14(self): - self.check_build('_testcpp14ext', std='c++14') - def check_build(self, extension_name, std=None, limited=False): venv_dir = 'env' with support.setup_venv_with_pip_setuptools(venv_dir) as python_exe: @@ -63,6 +49,7 @@ def run_cmd(operation, cmd): if limited: env['CPYTHON_TEST_LIMITED'] = '1' env['CPYTHON_TEST_EXT_NAME'] = extension_name + env['TEST_INTERNAL_C_API'] = str(int(self.TEST_INTERNAL_C_API)) if support.verbose: print('Run:', ' '.join(map(shlex.quote, cmd))) subprocess.run(cmd, check=True, env=env) @@ -112,6 +99,22 @@ def test_build_limited_cpp03(self): def test_build_limited(self): self.check_build('_testcppext_limited', limited=True) + def test_build_cpp03(self): + # In public docs, we say C API is compatible with C++11. However, + # in practice we do maintain C++03 compatibility in public headers. + # Please ask the C API WG before adding a new C++11-only feature. + self.check_build('_testcpp03ext', std='c++03') + + @unittest.skipIf(support.MS_WINDOWS, "MSVC doesn't support /std:c++11") + def test_build_cpp11(self): + self.check_build('_testcpp11ext', std='c++11') + + # Only test C++14 on MSVC. + # On s390x RHEL7, GCC 4.8.5 doesn't support C++14. + @unittest.skipIf(not support.MS_WINDOWS, "need Windows") + def test_build_cpp14(self): + self.check_build('_testcpp14ext', std='c++14') + class TestInteralCAPI(BaseTests, unittest.TestCase): TEST_INTERNAL_C_API = True diff --git a/Lib/test/test_cppext/extension.cpp b/Lib/test/test_cppext/extension.cpp index f95655eccded61..038f67bbbe3f74 100644 --- a/Lib/test/test_cppext/extension.cpp +++ b/Lib/test/test_cppext/extension.cpp @@ -7,15 +7,22 @@ #undef NDEBUG #ifdef TEST_INTERNAL_C_API -# define Py_BUILD_CORE 1 +# define Py_BUILD_CORE_MODULE 1 #endif #include "Python.h" #ifdef TEST_INTERNAL_C_API // gh-135906: Check for compiler warnings in the internal C API -# include "internal/pycore_backoff.h" # include "internal/pycore_frame.h" + // mimalloc emits many compiler warnings when Python is built in debug + // mode (when MI_DEBUG is not zero) + // mimalloc emits compiler warnings when Python is built on Windows + // in free-threaded mode. +# if !defined(Py_DEBUG) && !(defined(MS_WINDOWS) && defined(Py_GIL_DISABLED)) +# include "internal/pycore_backoff.h" +# include "internal/pycore_cell.h" +# endif #endif #ifndef MODULE_NAME