mirror of
https://github.com/python/cpython.git
synced 2025-07-19 09:15:34 +00:00
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:
parent
3597c12941
commit
4caf5c2753
5 changed files with 76 additions and 36 deletions
|
@ -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__":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue