diff options
author | Victor Stinner <vstinner@python.org> | 2022-06-14 09:43:08 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-14 09:43:08 (GMT) |
commit | 4caf5c2753f1aa28d6f4bc1aa377975fd2a62331 (patch) | |
tree | f04937769184fe84dfeda70dcfc58202c39cf693 /Lib/test/setup_testcppext.py | |
parent | 3597c129413a86f805beca78b7c72a20b5bf801c (diff) | |
download | cpython-4caf5c2753f1aa28d6f4bc1aa377975fd2a62331.zip cpython-4caf5c2753f1aa28d6f4bc1aa377975fd2a62331.tar.gz cpython-4caf5c2753f1aa28d6f4bc1aa377975fd2a62331.tar.bz2 |
gh-91321: Fix compatibility with C++ older than C++11 (#93784)
Fix the compatibility of the Python C API with C++ older than C++11.
_Py_NULL is only defined as nullptr on C++11 and newer.
Diffstat (limited to 'Lib/test/setup_testcppext.py')
-rw-r--r-- | Lib/test/setup_testcppext.py | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/Lib/test/setup_testcppext.py b/Lib/test/setup_testcppext.py index 780cb7b..a288dbd 100644 --- a/Lib/test/setup_testcppext.py +++ b/Lib/test/setup_testcppext.py @@ -13,8 +13,6 @@ SOURCE = support.findfile('_testcppext.cpp') if not MS_WINDOWS: # C++ compiler flags for GCC and clang CPPFLAGS = [ - # Python currently targets C++11 - '-std=c++11', # gh-91321: The purpose of _testcppext extension is to check that building # a C++ extension using the Python C API does not emit C++ compiler # warnings @@ -30,12 +28,23 @@ else: def main(): + cppflags = list(CPPFLAGS) + if '-std=c++03' in sys.argv: + sys.argv.remove('-std=c++03') + std = 'c++03' + name = '_testcpp03ext' + else: + # Python currently targets C++11 + std = 'c++11' + name = '_testcpp11ext' + + cppflags = [*CPPFLAGS, f'-std={std}'] cpp_ext = Extension( - '_testcppext', + name, sources=[SOURCE], language='c++', - extra_compile_args=CPPFLAGS) - setup(name="_testcppext", ext_modules=[cpp_ext]) + extra_compile_args=cppflags) + setup(name=name, ext_modules=[cpp_ext]) if __name__ == "__main__": |