mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-92135: Rename _Py_reinterpret_cast() to _Py_CAST() (#92230)
Rename also _Py_static_cast() to _Py_STATIC_CAST().
This commit is contained in:
parent
f6f36cc269
commit
fbd5539a54
9 changed files with 24 additions and 24 deletions
|
@ -17,20 +17,20 @@
|
|||
// Macro to use C++ static_cast<>, reinterpret_cast<> and const_cast<>
|
||||
// in the Python C API.
|
||||
//
|
||||
// In C++, _Py_reinterpret_cast(type, expr) converts a constant expression to a
|
||||
// In C++, _Py_CAST(type, expr) converts a constant expression to a
|
||||
// non constant type using const_cast<type>. For example,
|
||||
// _Py_reinterpret_cast(PyObject*, op) can convert a "const PyObject*" to
|
||||
// _Py_CAST(PyObject*, op) can convert a "const PyObject*" to
|
||||
// "PyObject*".
|
||||
//
|
||||
// The type argument must not be constant. For example, in C++,
|
||||
// _Py_reinterpret_cast(const PyObject*, expr) fails with a compiler error.
|
||||
// _Py_CAST(const PyObject*, expr) fails with a compiler error.
|
||||
#ifdef __cplusplus
|
||||
# define _Py_static_cast(type, expr) static_cast<type>(expr)
|
||||
# define _Py_reinterpret_cast(type, expr) \
|
||||
# define _Py_STATIC_CAST(type, expr) static_cast<type>(expr)
|
||||
# define _Py_CAST(type, expr) \
|
||||
const_cast<type>(reinterpret_cast<const type>(expr))
|
||||
#else
|
||||
# define _Py_static_cast(type, expr) ((type)(expr))
|
||||
# define _Py_reinterpret_cast(type, expr) ((type)(expr))
|
||||
# define _Py_STATIC_CAST(type, expr) ((type)(expr))
|
||||
# define _Py_CAST(type, expr) ((type)(expr))
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -317,10 +317,10 @@ extern "C" {
|
|||
*/
|
||||
#ifdef Py_DEBUG
|
||||
# define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) \
|
||||
(assert(_Py_static_cast(WIDE, _Py_static_cast(NARROW, (VALUE))) == (VALUE)), \
|
||||
_Py_static_cast(NARROW, (VALUE)))
|
||||
(assert(_Py_STATIC_CAST(WIDE, _Py_STATIC_CAST(NARROW, (VALUE))) == (VALUE)), \
|
||||
_Py_STATIC_CAST(NARROW, (VALUE)))
|
||||
#else
|
||||
# define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) _Py_static_cast(NARROW, (VALUE))
|
||||
# define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) _Py_STATIC_CAST(NARROW, (VALUE))
|
||||
#endif
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue