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/test_cppext.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/test_cppext.py')
-rw-r--r-- | Lib/test/test_cppext.py | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/Lib/test/test_cppext.py b/Lib/test/test_cppext.py index 9ed9061..8673911 100644 --- a/Lib/test/test_cppext.py +++ b/Lib/test/test_cppext.py @@ -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__": |