gh-92135: Rename _Py_reinterpret_cast() to _Py_CAST() (#92230)

Rename also _Py_static_cast() to _Py_STATIC_CAST().
This commit is contained in:
Victor Stinner 2022-05-03 16:37:06 +02:00 committed by GitHub
parent f6f36cc269
commit fbd5539a54
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 24 additions and 24 deletions

View file

@ -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