| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,11 +40,7 @@ | |||
| 40 | 40 | '-Wformat-nonliteral', | |
| 41 | 41 | '-Wformat-security', | |
| 42 | 42 | )) | |
| 43 | - CFLAGS = COMMON_FLAGS + [ | ||
| 44 | - # Use C99 for pythoncapi_compat.c which initializes PyModuleDef with a | ||
| 45 | - # mixture of designated and non-designated initializers | ||
| 46 | - '-std=c99', | ||
| 47 | - ] | ||
| 43 | + CFLAGS = COMMON_FLAGS | ||
| 48 | 44 | else: | |
| 49 | 45 | # C compiler flags for MSVC | |
| 50 | 46 | COMMON_FLAGS.extend(( | |
@@ -54,6 +50,27 @@ | |||
| 54 | 50 | CFLAGS = list(COMMON_FLAGS) | |
| 55 | 51 | CXXFLAGS = list(COMMON_FLAGS) | |
| 56 | 52 | ||
| 53 | + if not MSVC: | ||
| 54 | + C_VERSIONS = ('c99', 'c11') | ||
| 55 | + else: | ||
| 56 | + # MSVC doesn't support /std:c99 flag | ||
| 57 | + C_VERSIONS = ('c11',) | ||
| 58 | + | ||
| 59 | + if not MSVC: | ||
| 60 | + CXX_VERSIONS = [ | ||
| 61 | + ('test_pythoncapi_compat_cpp03ext', ['-std=c++03']), | ||
| 62 | + ('test_pythoncapi_compat_cpp11ext', ['-std=c++11']), | ||
| 63 | + ('test_pythoncapi_compat_cpp14ext', ['-std=c++14']), | ||
| 64 | + ('test_pythoncapi_compat_cpp17ext', ['-std=c++17']), | ||
| 65 | + ('test_pythoncapi_compat_cpp20ext', ['-std=c++20']), | ||
| 66 | + ] | ||
| 67 | + else: | ||
| 68 | + # MSVC doesn't support /std:c++11 | ||
| 69 | + CXX_VERSIONS = [ | ||
| 70 | + ('test_pythoncapi_compat_cppext', None), | ||
| 71 | + ('test_pythoncapi_compat_cpp14ext', ['/std:c++14', '/Zc:__cplusplus']), | ||
| 72 | + ] | ||
| 73 | + | ||
| 57 | 74 | ||
| 58 | 75 | def main(): | |
| 59 | 76 | # gh-105776: When "gcc -std=11" is used as the C++ compiler, -std=c11 | |
@@ -75,27 +92,21 @@ def main(): | |||
| 75 | 92 | os.environ['CC'] = cmd | |
| 76 | 93 | ||
| 77 | 94 | # C extension | |
| 78 | - c_ext = Extension( | ||
| 79 | - 'test_pythoncapi_compat_cext', | ||
| 80 | - sources=['test_pythoncapi_compat_cext.c'], | ||
| 81 | - extra_compile_args=CFLAGS) | ||
| 82 | - extensions = [c_ext] | ||
| 95 | + extensions = [] | ||
| 96 | + for std in C_VERSIONS: | ||
| 97 | + if not MSVC: | ||
| 98 | + cflags = CFLAGS + ['-std=%s' % std] | ||
| 99 | + else: | ||
| 100 | + cflags = CFLAGS + ['/std:%s' % std] | ||
| 101 | + c_ext = Extension( | ||
| 102 | + 'test_pythoncapi_compat_cext_%s' % std, | ||
| 103 | + sources=['test_pythoncapi_compat_cext.c'], | ||
| 104 | + extra_compile_args=cflags) | ||
| 105 | + extensions.append(c_ext) | ||
| 83 | 106 | ||
| 84 | 107 | if TEST_CXX: | |
| 85 | 108 | # C++ extension | |
| 86 | - | ||
| 87 | - # MSVC has /std flag but doesn't support /std:c++11 | ||
| 88 | - if not MSVC: | ||
| 89 | - versions = [ | ||
| 90 | - ('test_pythoncapi_compat_cpp03ext', ['-std=c++03']), | ||
| 91 | - ('test_pythoncapi_compat_cpp11ext', ['-std=c++11']), | ||
| 92 | - ] | ||
| 93 | - else: | ||
| 94 | - versions = [ | ||
| 95 | - ('test_pythoncapi_compat_cppext', None), | ||
| 96 | - ('test_pythoncapi_compat_cpp14ext', ['/std:c++14', '/Zc:__cplusplus']), | ||
| 97 | - ] | ||
| 98 | - for name, std_flags in versions: | ||
| 109 | + for name, std_flags in CXX_VERSIONS: | ||
| 99 | 110 | flags = list(CXXFLAGS) | |
| 100 | 111 | if std_flags is not None: | |
| 101 | 112 | flags.extend(std_flags) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,19 +32,29 @@ | |||
| 32 | 32 | # Windows uses MSVC compiler | |
| 33 | 33 | MSVC = (os.name == "nt") | |
| 34 | 34 | ||
| 35 | - TESTS = [ | ||
| 36 | - ("test_pythoncapi_compat_cext", "C"), | ||
| 37 | - ] | ||
| 35 | + # C++ is only supported on Python 3.6 and newer | ||
| 36 | + TEST_CXX = (sys.version_info >= (3, 6)) | ||
| 37 | + | ||
| 38 | 38 | if not MSVC: | |
| 39 | - TESTS.extend(( | ||
| 39 | + C_TESTS = [ | ||
| 40 | + ("test_pythoncapi_compat_cext_c99", "C99"), | ||
| 41 | + ("test_pythoncapi_compat_cext_c11", "C11"), | ||
| 42 | + ] | ||
| 43 | + CXX_TESTS = [ | ||
| 40 | 44 | ("test_pythoncapi_compat_cpp03ext", "C++03"), | |
| 41 | 45 | ("test_pythoncapi_compat_cpp11ext", "C++11"), | |
| 42 | - )) | ||
| 46 | + ("test_pythoncapi_compat_cpp14ext", "C++14"), | ||
| 47 | + ("test_pythoncapi_compat_cpp17ext", "C++17"), | ||
| 48 | + ("test_pythoncapi_compat_cpp20ext", "C++20"), | ||
| 49 | + ] | ||
| 43 | 50 | else: | |
| 44 | - TESTS.extend(( | ||
| 51 | + C_TESTS = [ | ||
| 52 | + ("test_pythoncapi_compat_cext_c11", "C11"), | ||
| 53 | + ] | ||
| 54 | + CXX_TESTS = [ | ||
| 45 | 55 | ("test_pythoncapi_compat_cppext", "C++"), | |
| 46 | 56 | ("test_pythoncapi_compat_cpp14ext", "C++14"), | |
| 47 | - )) | ||
| 57 | + ] | ||
| 48 | 58 | ||
| 49 | 59 | ||
| 50 | 60 | VERBOSE = False | |
@@ -84,9 +94,12 @@ def import_tests(module_name): | |||
| 84 | 94 | ||
| 85 | 95 | if not pythonpath: | |
| 86 | 96 | raise Exception("Failed to find the build directory") | |
| 87 | - sys.path.append(pythonpath) | ||
| 88 | - | ||
| 89 | - return __import__(module_name) | ||
| 97 | + old_sys_path = list(sys.path) | ||
| 98 | + try: | ||
| 99 | + sys.path.append(pythonpath) | ||
| 100 | + return __import__(module_name) | ||
| 101 | + finally: | ||
| 102 | + sys.path[:] = old_sys_path | ||
| 90 | 103 | ||
| 91 | 104 | ||
| 92 | 105 | def _run_tests(tests, verbose): | |
@@ -155,18 +168,7 @@ def run_tests(module_name, lang): | |||
| 155 | 168 | title = "Test %s (%s)" % (module_name, lang) | |
| 156 | 169 | display_title(title) | |
| 157 | 170 | ||
| 158 | - try: | ||
| 159 | - testmod = import_tests(module_name) | ||
| 160 | - except ImportError: | ||
| 161 | - # The C extension must always be available | ||
| 162 | - if lang == "C": | ||
| 163 | - raise | ||
| 164 | - | ||
| 165 | - if VERBOSE: | ||
| 166 | - print("%s: skip %s, missing %s extension" | ||
| 167 | - % (python_version(), lang, module_name)) | ||
| 168 | - print() | ||
| 169 | - return | ||
| 171 | + testmod = import_tests(module_name) | ||
| 170 | 172 | ||
| 171 | 173 | if VERBOSE: | |
| 172 | 174 | empty_line = False | |
@@ -226,7 +228,10 @@ def main(): | |||
| 226 | 228 | ||
| 227 | 229 | build_ext() | |
| 228 | 230 | ||
| 229 | - for module_name, lang in TESTS: | ||
| 231 | + tests = list(C_TESTS) | ||
| 232 | + if TEST_CXX: | ||
| 233 | + tests += CXX_TESTS | ||
| 234 | + for module_name, lang in tests: | ||
| 230 | 235 | run_tests(module_name, lang) | |
| 231 | 236 | ||
| 232 | 237 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,14 +16,24 @@ | |||
| 16 | 16 | # define PYTHON3 1 | |
| 17 | 17 | #endif | |
| 18 | 18 | ||
| 19 | - #if defined(__cplusplus) && __cplusplus >= 201402 | ||
| 19 | + #if defined(__cplusplus) && __cplusplus >= 202002L | ||
| 20 | + # define MODULE_NAME test_pythoncapi_compat_cpp20ext | ||
| 21 | + #elif defined(__cplusplus) && __cplusplus >= 201703L | ||
| 22 | + # define MODULE_NAME test_pythoncapi_compat_cpp17ext | ||
| 23 | + #elif defined(__cplusplus) && __cplusplus >= 201402L | ||
| 20 | 24 | # define MODULE_NAME test_pythoncapi_compat_cpp14ext | |
| 21 | - #elif defined(__cplusplus) && __cplusplus >= 201103 | ||
| 25 | + #elif defined(__cplusplus) && __cplusplus >= 201103L | ||
| 22 | 26 | # define MODULE_NAME test_pythoncapi_compat_cpp11ext | |
| 23 | 27 | #elif defined(__cplusplus) && !defined(_MSC_VER) | |
| 24 | 28 | # define MODULE_NAME test_pythoncapi_compat_cpp03ext | |
| 25 | 29 | #elif defined(__cplusplus) | |
| 26 | 30 | # define MODULE_NAME test_pythoncapi_compat_cppext | |
| 31 | + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 202311L | ||
| 32 | + # define MODULE_NAME test_pythoncapi_compat_cext_c23 | ||
| 33 | + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 201112L | ||
| 34 | + # define MODULE_NAME test_pythoncapi_compat_cext_c11 | ||
| 35 | + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L | ||
| 36 | + # define MODULE_NAME test_pythoncapi_compat_cext_c99 | ||
| 27 | 37 | #else | |
| 28 | 38 | # define MODULE_NAME test_pythoncapi_compat_cext | |
| 29 | 39 | #endif | |
| Back | FazBrowse Home | New Git URL |
0 commit comments