Skip to content

Commit c11e70a

Browse files
authored
[3.14] gh-135906: Test more internal headers in test_cext/test_cppext (#144758)
* 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 c6e418d) * gh-135906: Test more internal headers in test_cext/test_cppext (#144751) (cherry picked from commit b488f33)
1 parent fdbdd9f commit c11e70a

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

Lib/test/test_cext/extension.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,19 @@
1515

1616
#ifdef TEST_INTERNAL_C_API
1717
// gh-135906: Check for compiler warnings in the internal C API.
18-
// - Cython uses pycore_frame.h.
18+
// - Cython uses pycore_critical_section.h, pycore_frame.h and
19+
// pycore_template.h.
1920
// - greenlet uses pycore_frame.h, pycore_interpframe_structs.h and
2021
// pycore_interpframe.h.
22+
# include "internal/pycore_critical_section.h"
2123
# include "internal/pycore_frame.h"
2224
# include "internal/pycore_gc.h"
2325
# include "internal/pycore_interp.h"
2426
# include "internal/pycore_interpframe.h"
2527
# include "internal/pycore_interpframe_structs.h"
2628
# include "internal/pycore_object.h"
2729
# include "internal/pycore_pystate.h"
30+
# include "internal/pycore_template.h"
2831
#endif
2932

3033
#ifndef MODULE_NAME

Lib/test/test_cppext/__init__.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import shlex
55
import shutil
66
import subprocess
7+
import sys
78
import unittest
89
from test import support
910

@@ -27,9 +28,6 @@
2728
class BaseTests:
2829
TEST_INTERNAL_C_API = False
2930

30-
def test_build(self):
31-
self.check_build('_testcppext')
32-
3331
def check_build(self, extension_name, std=None, limited=False):
3432
venv_dir = 'env'
3533
with support.setup_venv_with_pip_setuptools(venv_dir) as python_exe:
@@ -91,6 +89,9 @@ def run_cmd(operation, cmd):
9189

9290

9391
class TestPublicCAPI(BaseTests, unittest.TestCase):
92+
def test_build(self):
93+
self.check_build('_testcppext')
94+
9495
@support.requires_gil_enabled('incompatible with Free Threading')
9596
def test_build_limited_cpp03(self):
9697
self.check_build('_test_limited_cpp03ext', std='c++03', limited=True)
@@ -119,6 +120,13 @@ def test_build_cpp14(self):
119120
class TestInteralCAPI(BaseTests, unittest.TestCase):
120121
TEST_INTERNAL_C_API = True
121122

123+
def test_build(self):
124+
kwargs = {}
125+
if sys.platform == 'darwin':
126+
# Old Apple clang++ default C++ std is gnu++98
127+
kwargs['std'] = 'c++11'
128+
self.check_build('_testcppext_internal', **kwargs)
129+
122130

123131
if __name__ == "__main__":
124132
unittest.main()

Lib/test/test_cppext/extension.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,20 @@
1515

1616
#ifdef TEST_INTERNAL_C_API
1717
// gh-135906: Check for compiler warnings in the internal C API
18+
// - Cython uses pycore_critical_section.h, pycore_frame.h and
19+
// pycore_template.h.
20+
// - greenlet uses pycore_frame.h, pycore_interpframe_structs.h and
21+
// pycore_interpframe.h.
1822
# include "internal/pycore_frame.h"
19-
// mimalloc emits many compiler warnings when Python is built in debug
20-
// mode (when MI_DEBUG is not zero).
21-
// mimalloc emits compiler warnings when Python is built on Windows
22-
// and macOS.
23-
# if !defined(Py_DEBUG) && !defined(MS_WINDOWS) && !defined(__APPLE__)
23+
# include "internal/pycore_interpframe_structs.h"
24+
# include "internal/pycore_template.h"
25+
26+
// mimalloc emits compiler warnings on Windows.
27+
# if !defined(MS_WINDOWS)
2428
# include "internal/pycore_backoff.h"
2529
# include "internal/pycore_cell.h"
30+
# include "internal/pycore_critical_section.h"
31+
# include "internal/pycore_interpframe.h"
2632
# endif
2733
#endif
2834

Lib/test/test_cppext/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def main():
5959
else:
6060
cppflags.append(f'-std={std}')
6161

62-
if limited or (std != 'c++03'):
62+
if limited or (std != 'c++03') and not internal:
6363
# See CPPFLAGS_PEDANTIC docstring
6464
cppflags.extend(CPPFLAGS_PEDANTIC)
6565

0 commit comments

Comments
 (0)