From ecb0f3ec68124cb0b256eccecef4b82499b64ea2 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 11 Feb 2026 18:38:23 +0100 Subject: [PATCH 1/2] gh-141563: Enable test_cppext internal C API tests on macOS (#144711) Build the C API in C++11 mode on macOS. (cherry picked from commit c6e418d1744aed95a6f25d22565204649dde29c7) --- Lib/test/test_cppext/__init__.py | 14 +++++++++++--- Lib/test/test_cppext/extension.cpp | 7 ++----- Lib/test/test_cppext/setup.py | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Lib/test/test_cppext/__init__.py b/Lib/test/test_cppext/__init__.py index 9013503995bdce..1fd01702f64029 100644 --- a/Lib/test/test_cppext/__init__.py +++ b/Lib/test/test_cppext/__init__.py @@ -4,6 +4,7 @@ import shlex import shutil import subprocess +import sys import unittest from test import support @@ -27,9 +28,6 @@ class BaseTests: TEST_INTERNAL_C_API = False - def test_build(self): - self.check_build('_testcppext') - 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: @@ -91,6 +89,9 @@ def run_cmd(operation, cmd): class TestPublicCAPI(BaseTests, unittest.TestCase): + def test_build(self): + self.check_build('_testcppext') + @support.requires_gil_enabled('incompatible with Free Threading') def test_build_limited_cpp03(self): self.check_build('_test_limited_cpp03ext', std='c++03', limited=True) @@ -119,6 +120,13 @@ def test_build_cpp14(self): class TestInteralCAPI(BaseTests, unittest.TestCase): TEST_INTERNAL_C_API = True + def test_build(self): + kwargs = {} + if sys.platform == 'darwin': + # Old Apple clang++ default C++ std is gnu++98 + kwargs['std'] = 'c++11' + self.check_build('_testcppext_internal', **kwargs) + if __name__ == "__main__": unittest.main() diff --git a/Lib/test/test_cppext/extension.cpp b/Lib/test/test_cppext/extension.cpp index 811374c0361e70..92c4645039a03b 100644 --- a/Lib/test/test_cppext/extension.cpp +++ b/Lib/test/test_cppext/extension.cpp @@ -16,11 +16,8 @@ #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). - // mimalloc emits compiler warnings when Python is built on Windows - // and macOS. -# if !defined(Py_DEBUG) && !defined(MS_WINDOWS) && !defined(__APPLE__) + // mimalloc emits compiler warnings on Windows. +# if !defined(MS_WINDOWS) # include "internal/pycore_backoff.h" # include "internal/pycore_cell.h" # endif diff --git a/Lib/test/test_cppext/setup.py b/Lib/test/test_cppext/setup.py index a3eec1c67e1556..2d9052a6b879da 100644 --- a/Lib/test/test_cppext/setup.py +++ b/Lib/test/test_cppext/setup.py @@ -59,7 +59,7 @@ def main(): else: cppflags.append(f'-std={std}') - if limited or (std != 'c++03'): + if limited or (std != 'c++03') and not internal: # See CPPFLAGS_PEDANTIC docstring cppflags.extend(CPPFLAGS_PEDANTIC) From b868f860abbc4d7ee3a1b6f46c82f583af72462c Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 12 Feb 2026 19:40:42 +0100 Subject: [PATCH 2/2] gh-135906: Test more internal headers in test_cext/test_cppext (#144751) (cherry picked from commit b488f338cf058f46cbf0255023ca1c1669b0eb44) --- Lib/test/test_cext/extension.c | 5 ++++- Lib/test/test_cppext/extension.cpp | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_cext/extension.c b/Lib/test/test_cext/extension.c index 8a0f40d56b1ee4..56f40b354c6913 100644 --- a/Lib/test/test_cext/extension.c +++ b/Lib/test/test_cext/extension.c @@ -15,9 +15,11 @@ #ifdef TEST_INTERNAL_C_API // gh-135906: Check for compiler warnings in the internal C API. - // - Cython uses pycore_frame.h. + // - Cython uses pycore_critical_section.h, pycore_frame.h and + // pycore_template.h. // - greenlet uses pycore_frame.h, pycore_interpframe_structs.h and // pycore_interpframe.h. +# include "internal/pycore_critical_section.h" # include "internal/pycore_frame.h" # include "internal/pycore_gc.h" # include "internal/pycore_interp.h" @@ -25,6 +27,7 @@ # include "internal/pycore_interpframe_structs.h" # include "internal/pycore_object.h" # include "internal/pycore_pystate.h" +# include "internal/pycore_template.h" #endif #ifndef MODULE_NAME diff --git a/Lib/test/test_cppext/extension.cpp b/Lib/test/test_cppext/extension.cpp index 92c4645039a03b..4db63df94f5233 100644 --- a/Lib/test/test_cppext/extension.cpp +++ b/Lib/test/test_cppext/extension.cpp @@ -15,11 +15,20 @@ #ifdef TEST_INTERNAL_C_API // gh-135906: Check for compiler warnings in the internal C API + // - Cython uses pycore_critical_section.h, pycore_frame.h and + // pycore_template.h. + // - greenlet uses pycore_frame.h, pycore_interpframe_structs.h and + // pycore_interpframe.h. # include "internal/pycore_frame.h" +# include "internal/pycore_interpframe_structs.h" +# include "internal/pycore_template.h" + // mimalloc emits compiler warnings on Windows. # if !defined(MS_WINDOWS) # include "internal/pycore_backoff.h" # include "internal/pycore_cell.h" +# include "internal/pycore_critical_section.h" +# include "internal/pycore_interpframe.h" # endif #endif