mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +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
|
@ -16,22 +16,29 @@ SETUP_TESTCPPEXT = support.findfile('setup_testcppext.py')
|
|||
|
||||
@support.requires_subprocess()
|
||||
class TestCPPExt(unittest.TestCase):
|
||||
def test_build_cpp11(self):
|
||||
self.check_build(False)
|
||||
|
||||
def test_build_cpp03(self):
|
||||
self.check_build(True)
|
||||
|
||||
# With MSVC, the linker fails with: cannot open file 'python311.lib'
|
||||
# https://github.com/python/cpython/pull/32175#issuecomment-1111175897
|
||||
@unittest.skipIf(MS_WINDOWS, 'test fails on Windows')
|
||||
# the test uses venv+pip: skip if it's not available
|
||||
@support.requires_venv_with_pip()
|
||||
def test_build(self):
|
||||
def check_build(self, std_cpp03):
|
||||
# Build in a temporary directory
|
||||
with os_helper.temp_cwd():
|
||||
self._test_build()
|
||||
self._check_build(std_cpp03)
|
||||
|
||||
def _test_build(self):
|
||||
def _check_build(self, std_cpp03):
|
||||
venv_dir = 'env'
|
||||
verbose = support.verbose
|
||||
|
||||
# Create virtual environment to get setuptools
|
||||
cmd = [sys.executable, '-X', 'dev', '-m', 'venv', venv_dir]
|
||||
if support.verbose:
|
||||
if verbose:
|
||||
print()
|
||||
print('Run:', ' '.join(cmd))
|
||||
subprocess.run(cmd, check=True)
|
||||
|
@ -46,16 +53,21 @@ class TestCPPExt(unittest.TestCase):
|
|||
python = os.path.join(venv_dir, 'bin', python_exe)
|
||||
|
||||
# Build the C++ extension
|
||||
cmd = [python, '-X', 'dev', SETUP_TESTCPPEXT, 'build_ext', '--verbose']
|
||||
if support.verbose:
|
||||
cmd = [python, '-X', 'dev',
|
||||
SETUP_TESTCPPEXT, 'build_ext', '--verbose']
|
||||
if std_cpp03:
|
||||
cmd.append('-std=c++03')
|
||||
if verbose:
|
||||
print('Run:', ' '.join(cmd))
|
||||
proc = subprocess.run(cmd,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
text=True)
|
||||
if proc.returncode:
|
||||
print(proc.stdout, end='')
|
||||
self.fail(f"Build failed with exit code {proc.returncode}")
|
||||
subprocess.run(cmd, check=True)
|
||||
else:
|
||||
proc = subprocess.run(cmd,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
text=True)
|
||||
if proc.returncode:
|
||||
print(proc.stdout, end='')
|
||||
self.fail(f"Build failed with exit code {proc.returncode}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue