mirror of
https://github.com/python/cpython.git
synced 2025-07-24 19:54:21 +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
|
@ -51,7 +51,7 @@ PyAPI_FUNC(PyObject *) _PyObject_MakeTpCall(
|
||||||
PyObject *keywords);
|
PyObject *keywords);
|
||||||
|
|
||||||
#define PY_VECTORCALL_ARGUMENTS_OFFSET \
|
#define PY_VECTORCALL_ARGUMENTS_OFFSET \
|
||||||
(_Py_static_cast(size_t, 1) << (8 * sizeof(size_t) - 1))
|
(_Py_STATIC_CAST(size_t, 1) << (8 * sizeof(size_t) - 1))
|
||||||
|
|
||||||
static inline Py_ssize_t
|
static inline Py_ssize_t
|
||||||
PyVectorcall_NARGS(size_t n)
|
PyVectorcall_NARGS(size_t n)
|
||||||
|
|
|
@ -26,7 +26,7 @@ PyAPI_FUNC(void) _PyList_DebugMallocStats(FILE *out);
|
||||||
|
|
||||||
/* Cast argument to PyListObject* type. */
|
/* Cast argument to PyListObject* type. */
|
||||||
#define _PyList_CAST(op) \
|
#define _PyList_CAST(op) \
|
||||||
(assert(PyList_Check(op)), _Py_reinterpret_cast(PyListObject*, (op)))
|
(assert(PyList_Check(op)), _Py_CAST(PyListObject*, (op)))
|
||||||
|
|
||||||
// Macros and static inline functions, trading safety for speed
|
// Macros and static inline functions, trading safety for speed
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,10 @@ PyAPI_DATA(PyTypeObject) PyCMethod_Type;
|
||||||
|
|
||||||
#define _PyCFunctionObject_CAST(func) \
|
#define _PyCFunctionObject_CAST(func) \
|
||||||
(assert(PyCFunction_Check(func)), \
|
(assert(PyCFunction_Check(func)), \
|
||||||
_Py_reinterpret_cast(PyCFunctionObject*, (func)))
|
_Py_CAST(PyCFunctionObject*, (func)))
|
||||||
#define _PyCMethodObject_CAST(func) \
|
#define _PyCMethodObject_CAST(func) \
|
||||||
(assert(PyCMethod_Check(func)), \
|
(assert(PyCMethod_Check(func)), \
|
||||||
_Py_reinterpret_cast(PyCMethodObject*, (func)))
|
_Py_CAST(PyCMethodObject*, (func)))
|
||||||
|
|
||||||
/* Macros for direct access to these values. Type checks are *not*
|
/* Macros for direct access to these values. Type checks are *not*
|
||||||
done, so use with care. */
|
done, so use with care. */
|
||||||
|
|
|
@ -15,7 +15,7 @@ PyAPI_FUNC(void) _PyTuple_MaybeUntrack(PyObject *);
|
||||||
|
|
||||||
/* Cast argument to PyTupleObject* type. */
|
/* Cast argument to PyTupleObject* type. */
|
||||||
#define _PyTuple_CAST(op) \
|
#define _PyTuple_CAST(op) \
|
||||||
(assert(PyTuple_Check(op)), _Py_reinterpret_cast(PyTupleObject*, (op)))
|
(assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
|
||||||
|
|
||||||
// Macros and static inline functions, trading safety for speed
|
// Macros and static inline functions, trading safety for speed
|
||||||
|
|
||||||
|
|
|
@ -237,13 +237,13 @@ PyAPI_FUNC(int) _PyUnicode_CheckConsistency(
|
||||||
|
|
||||||
#define _PyASCIIObject_CAST(op) \
|
#define _PyASCIIObject_CAST(op) \
|
||||||
(assert(PyUnicode_Check(op)), \
|
(assert(PyUnicode_Check(op)), \
|
||||||
_Py_reinterpret_cast(PyASCIIObject*, (op)))
|
_Py_CAST(PyASCIIObject*, (op)))
|
||||||
#define _PyCompactUnicodeObject_CAST(op) \
|
#define _PyCompactUnicodeObject_CAST(op) \
|
||||||
(assert(PyUnicode_Check(op)), \
|
(assert(PyUnicode_Check(op)), \
|
||||||
_Py_reinterpret_cast(PyCompactUnicodeObject*, (op)))
|
_Py_CAST(PyCompactUnicodeObject*, (op)))
|
||||||
#define _PyUnicodeObject_CAST(op) \
|
#define _PyUnicodeObject_CAST(op) \
|
||||||
(assert(PyUnicode_Check(op)), \
|
(assert(PyUnicode_Check(op)), \
|
||||||
_Py_reinterpret_cast(PyUnicodeObject*, (op)))
|
_Py_CAST(PyUnicodeObject*, (op)))
|
||||||
|
|
||||||
|
|
||||||
/* --- Flexible String Representation Helper Macros (PEP 393) -------------- */
|
/* --- Flexible String Representation Helper Macros (PEP 393) -------------- */
|
||||||
|
|
|
@ -43,7 +43,7 @@ typedef PyObject *(*PyCMethod)(PyObject *, PyTypeObject *, PyObject *const *,
|
||||||
// it triggers an undefined behavior when Python calls it with 2 parameters
|
// it triggers an undefined behavior when Python calls it with 2 parameters
|
||||||
// (bpo-33012).
|
// (bpo-33012).
|
||||||
#define _PyCFunction_CAST(func) \
|
#define _PyCFunction_CAST(func) \
|
||||||
_Py_reinterpret_cast(PyCFunction, _Py_reinterpret_cast(void(*)(void), (func)))
|
_Py_CAST(PyCFunction, _Py_CAST(void(*)(void), (func)))
|
||||||
|
|
||||||
PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *);
|
PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *);
|
||||||
PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *);
|
PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *);
|
||||||
|
|
|
@ -104,7 +104,7 @@ struct _object {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Cast argument to PyObject* type. */
|
/* Cast argument to PyObject* type. */
|
||||||
#define _PyObject_CAST(op) _Py_reinterpret_cast(PyObject*, (op))
|
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject ob_base;
|
PyObject ob_base;
|
||||||
|
@ -112,7 +112,7 @@ typedef struct {
|
||||||
} PyVarObject;
|
} PyVarObject;
|
||||||
|
|
||||||
/* Cast argument to PyVarObject* type. */
|
/* Cast argument to PyVarObject* type. */
|
||||||
#define _PyVarObject_CAST(op) _Py_reinterpret_cast(PyVarObject*, (op))
|
#define _PyVarObject_CAST(op) _Py_CAST(PyVarObject*, (op))
|
||||||
|
|
||||||
|
|
||||||
// Test if the 'x' object is the 'y' object, the same as "x is y" in Python.
|
// Test if the 'x' object is the 'y' object, the same as "x is y" in Python.
|
||||||
|
@ -781,7 +781,7 @@ static inline int PyType_Check(PyObject *op) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define _PyType_CAST(op) \
|
#define _PyType_CAST(op) \
|
||||||
(assert(PyType_Check(op)), _Py_reinterpret_cast(PyTypeObject*, (op)))
|
(assert(PyType_Check(op)), _Py_CAST(PyTypeObject*, (op)))
|
||||||
|
|
||||||
static inline int PyType_CheckExact(PyObject *op) {
|
static inline int PyType_CheckExact(PyObject *op) {
|
||||||
return Py_IS_TYPE(op, &PyType_Type);
|
return Py_IS_TYPE(op, &PyType_Type);
|
||||||
|
|
|
@ -182,9 +182,9 @@ PyAPI_FUNC(void) PyObject_GC_UnTrack(void *);
|
||||||
PyAPI_FUNC(void) PyObject_GC_Del(void *);
|
PyAPI_FUNC(void) PyObject_GC_Del(void *);
|
||||||
|
|
||||||
#define PyObject_GC_New(type, typeobj) \
|
#define PyObject_GC_New(type, typeobj) \
|
||||||
_Py_reinterpret_cast(type*, _PyObject_GC_New(typeobj))
|
_Py_CAST(type*, _PyObject_GC_New(typeobj))
|
||||||
#define PyObject_GC_NewVar(type, typeobj, n) \
|
#define PyObject_GC_NewVar(type, typeobj, n) \
|
||||||
_Py_reinterpret_cast(type*, _PyObject_GC_NewVar((typeobj), (n)))
|
_Py_CAST(type*, _PyObject_GC_NewVar((typeobj), (n)))
|
||||||
|
|
||||||
PyAPI_FUNC(int) PyObject_GC_IsTracked(PyObject *);
|
PyAPI_FUNC(int) PyObject_GC_IsTracked(PyObject *);
|
||||||
PyAPI_FUNC(int) PyObject_GC_IsFinalized(PyObject *);
|
PyAPI_FUNC(int) PyObject_GC_IsFinalized(PyObject *);
|
||||||
|
|
|
@ -17,20 +17,20 @@
|
||||||
// Macro to use C++ static_cast<>, reinterpret_cast<> and const_cast<>
|
// Macro to use C++ static_cast<>, reinterpret_cast<> and const_cast<>
|
||||||
// in the Python C API.
|
// 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,
|
// 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*".
|
// "PyObject*".
|
||||||
//
|
//
|
||||||
// The type argument must not be constant. For example, in C++,
|
// 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
|
#ifdef __cplusplus
|
||||||
# define _Py_static_cast(type, expr) static_cast<type>(expr)
|
# define _Py_STATIC_CAST(type, expr) static_cast<type>(expr)
|
||||||
# define _Py_reinterpret_cast(type, expr) \
|
# define _Py_CAST(type, expr) \
|
||||||
const_cast<type>(reinterpret_cast<const type>(expr))
|
const_cast<type>(reinterpret_cast<const type>(expr))
|
||||||
#else
|
#else
|
||||||
# define _Py_static_cast(type, expr) ((type)(expr))
|
# define _Py_STATIC_CAST(type, expr) ((type)(expr))
|
||||||
# define _Py_reinterpret_cast(type, expr) ((type)(expr))
|
# define _Py_CAST(type, expr) ((type)(expr))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -317,10 +317,10 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
#ifdef Py_DEBUG
|
#ifdef Py_DEBUG
|
||||||
# define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) \
|
# define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) \
|
||||||
(assert(_Py_static_cast(WIDE, _Py_static_cast(NARROW, (VALUE))) == (VALUE)), \
|
(assert(_Py_STATIC_CAST(WIDE, _Py_STATIC_CAST(NARROW, (VALUE))) == (VALUE)), \
|
||||||
_Py_static_cast(NARROW, (VALUE)))
|
_Py_STATIC_CAST(NARROW, (VALUE)))
|
||||||
#else
|
#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
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue