From c1efd831245f81ed49b00f1a34d3c73eed7c2190 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 6 Feb 2026 10:04:25 +0100 Subject: [PATCH 1/4] gh-144490: Fix test_cppext: test the internal C API Add missing TEST_INTERNAL_C_API env var. --- Lib/test/test_cppext/__init__.py | 3 +++ Lib/test/test_cppext/extension.cpp | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_cppext/__init__.py b/Lib/test/test_cppext/__init__.py index 2f54b3ccb35cc4..f9aa2c148c5c1a 100644 --- a/Lib/test/test_cppext/__init__.py +++ b/Lib/test/test_cppext/__init__.py @@ -25,6 +25,8 @@ @support.requires_subprocess() @support.requires_resource('cpu') class BaseTests: + TEST_INTERNAL_C_API = False + def test_build(self): self.check_build('_testcppext') @@ -63,6 +65,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) diff --git a/Lib/test/test_cppext/extension.cpp b/Lib/test/test_cppext/extension.cpp index f95655eccded61..1affa176088d57 100644 --- a/Lib/test/test_cppext/extension.cpp +++ b/Lib/test/test_cppext/extension.cpp @@ -14,7 +14,6 @@ #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" #endif From b8f3f39b2089223019cf354d3e5517f5a761ec9e Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 6 Feb 2026 10:28:42 +0100 Subject: [PATCH 2/4] Test pycore_backoff.h in release mode --- Lib/test/test_cppext/__init__.py | 32 +++++++++++++++--------------- Lib/test/test_cppext/extension.cpp | 5 +++++ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/Lib/test/test_cppext/__init__.py b/Lib/test/test_cppext/__init__.py index f9aa2c148c5c1a..9013503995bdce 100644 --- a/Lib/test/test_cppext/__init__.py +++ b/Lib/test/test_cppext/__init__.py @@ -30,22 +30,6 @@ class BaseTests: 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: @@ -115,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 1affa176088d57..b1aca20e480a57 100644 --- a/Lib/test/test_cppext/extension.cpp +++ b/Lib/test/test_cppext/extension.cpp @@ -15,6 +15,11 @@ #ifdef TEST_INTERNAL_C_API // gh-135906: Check for compiler warnings in the internal C API # include "internal/pycore_frame.h" + // mimalloc emits many compiler warnings when Python is built in debug + // mode (when MI_DEBUG is not zero) +# ifndef Py_DEBUG +# include "internal/pycore_backoff.h" +# endif #endif #ifndef MODULE_NAME From 82237550c3d555b02cf1c5025e2deaf48d95f20b Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 6 Feb 2026 15:12:32 +0100 Subject: [PATCH 3/4] Fix test_cppext on Windows --- Lib/test/test_cppext/extension.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_cppext/extension.cpp b/Lib/test/test_cppext/extension.cpp index b1aca20e480a57..40f3b56d652b16 100644 --- a/Lib/test/test_cppext/extension.cpp +++ b/Lib/test/test_cppext/extension.cpp @@ -7,7 +7,7 @@ #undef NDEBUG #ifdef TEST_INTERNAL_C_API -# define Py_BUILD_CORE 1 +# define Py_BUILD_CORE_MODULE 1 #endif #include "Python.h" @@ -17,7 +17,9 @@ # include "internal/pycore_frame.h" // mimalloc emits many compiler warnings when Python is built in debug // mode (when MI_DEBUG is not zero) -# ifndef Py_DEBUG + // 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" # endif #endif From 37db34b50b973b6a330128cbe71372437e5f206b Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 6 Feb 2026 15:13:46 +0100 Subject: [PATCH 4/4] Test pycore_cell.h --- Lib/test/test_cppext/extension.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_cppext/extension.cpp b/Lib/test/test_cppext/extension.cpp index 40f3b56d652b16..038f67bbbe3f74 100644 --- a/Lib/test/test_cppext/extension.cpp +++ b/Lib/test/test_cppext/extension.cpp @@ -21,6 +21,7 @@ // 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