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.
This commit is contained in:
Victor Stinner 2022-06-14 11:43:08 +02:00 committed by GitHub
parent 3597c12941
commit 4caf5c2753
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 76 additions and 36 deletions

View file

@ -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__":