diff options
author | Victor Stinner <vstinner@python.org> | 2022-06-14 14:05:14 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-14 14:05:14 (GMT) |
commit | ef591cf8e3725e74489f4c19ca85b87cf6886852 (patch) | |
tree | 7e476e00cb4b866dc2e4ec0ccf69c779a506abbe /Include | |
parent | 871b1dc469b3daccb7c3e7fcaddd245137edd719 (diff) | |
download | cpython-ef591cf8e3725e74489f4c19ca85b87cf6886852.zip cpython-ef591cf8e3725e74489f4c19ca85b87cf6886852.tar.gz cpython-ef591cf8e3725e74489f4c19ca85b87cf6886852.tar.bz2 |
gh-91321: Fix compatibility with C++ older than C++11 (#93784) (#93802)
* 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.
(cherry picked from commit 4caf5c2753f1aa28d6f4bc1aa377975fd2a62331)
* test_cppext now builds the C++ extension with setuptools.
* Add @test.support.requires_venv_with_pip.
(cherry picked from commit ca0cc9c433830e14714a5cc93fb4e7254da3dd76)
Diffstat (limited to 'Include')
-rw-r--r-- | Include/pyport.h | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Include/pyport.h b/Include/pyport.h index a78e290..59f225f 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -36,10 +36,12 @@ extern "C++" { inline type _Py_CAST_impl(int ptr) { return reinterpret_cast<type>(ptr); } +#if __cplusplus >= 201103 template <typename type> inline type _Py_CAST_impl(std::nullptr_t) { return static_cast<type>(nullptr); } +#endif template <typename type, typename expr_type> inline type _Py_CAST_impl(expr_type *expr) { @@ -70,8 +72,9 @@ extern "C++" { #endif // Static inline functions should use _Py_NULL rather than using directly NULL -// to prevent C++ compiler warnings. In C++, _Py_NULL uses nullptr. -#ifdef __cplusplus +// to prevent C++ compiler warnings. On C++11 and newer, _Py_NULL is defined as +// nullptr. +#if defined(__cplusplus) && __cplusplus >= 201103 # define _Py_NULL nullptr #else # define _Py_NULL NULL |