Skip to content

Commit fbd5539

Browse files
authored
gh-92135: Rename _Py_reinterpret_cast() to _Py_CAST() (#92230)
Rename also _Py_static_cast() to _Py_STATIC_CAST().
1 parent f6f36cc commit fbd5539

File tree

9 files changed

+24
-24
lines changed

9 files changed

+24
-24
lines changed

Include/cpython/abstract.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ PyAPI_FUNC(PyObject *) _PyObject_MakeTpCall(
5151
PyObject *keywords);
5252

5353
#define PY_VECTORCALL_ARGUMENTS_OFFSET \
54-
(_Py_static_cast(size_t, 1) << (8 * sizeof(size_t) - 1))
54+
(_Py_STATIC_CAST(size_t, 1) << (8 * sizeof(size_t) - 1))
5555

5656
static inline Py_ssize_t
5757
PyVectorcall_NARGS(size_t n)

Include/cpython/listobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ PyAPI_FUNC(void) _PyList_DebugMallocStats(FILE *out);
2626

2727
/* Cast argument to PyListObject* type. */
2828
#define _PyList_CAST(op) \
29-
(assert(PyList_Check(op)), _Py_reinterpret_cast(PyListObject*, (op)))
29+
(assert(PyList_Check(op)), _Py_CAST(PyListObject*, (op)))
3030

3131
// Macros and static inline functions, trading safety for speed
3232

Include/cpython/methodobject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ PyAPI_DATA(PyTypeObject) PyCMethod_Type;
99

1010
#define _PyCFunctionObject_CAST(func) \
1111
(assert(PyCFunction_Check(func)), \
12-
_Py_reinterpret_cast(PyCFunctionObject*, (func)))
12+
_Py_CAST(PyCFunctionObject*, (func)))
1313
#define _PyCMethodObject_CAST(func) \
1414
(assert(PyCMethod_Check(func)), \
15-
_Py_reinterpret_cast(PyCMethodObject*, (func)))
15+
_Py_CAST(PyCMethodObject*, (func)))
1616

1717
/* Macros for direct access to these values. Type checks are *not*
1818
done, so use with care. */

Include/cpython/tupleobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ PyAPI_FUNC(void) _PyTuple_MaybeUntrack(PyObject *);
1515

1616
/* Cast argument to PyTupleObject* type. */
1717
#define _PyTuple_CAST(op) \
18-
(assert(PyTuple_Check(op)), _Py_reinterpret_cast(PyTupleObject*, (op)))
18+
(assert(PyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
1919

2020
// Macros and static inline functions, trading safety for speed
2121

Include/cpython/unicodeobject.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,13 @@ PyAPI_FUNC(int) _PyUnicode_CheckConsistency(
237237

238238
#define _PyASCIIObject_CAST(op) \
239239
(assert(PyUnicode_Check(op)), \
240-
_Py_reinterpret_cast(PyASCIIObject*, (op)))
240+
_Py_CAST(PyASCIIObject*, (op)))
241241
#define _PyCompactUnicodeObject_CAST(op) \
242242
(assert(PyUnicode_Check(op)), \
243-
_Py_reinterpret_cast(PyCompactUnicodeObject*, (op)))
243+
_Py_CAST(PyCompactUnicodeObject*, (op)))
244244
#define _PyUnicodeObject_CAST(op) \
245245
(assert(PyUnicode_Check(op)), \
246-
_Py_reinterpret_cast(PyUnicodeObject*, (op)))
246+
_Py_CAST(PyUnicodeObject*, (op)))
247247

248248

249249
/* --- Flexible String Representation Helper Macros (PEP 393) -------------- */

Include/methodobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ typedef PyObject *(*PyCMethod)(PyObject *, PyTypeObject *, PyObject *const *,
4343
// it triggers an undefined behavior when Python calls it with 2 parameters
4444
// (bpo-33012).
4545
#define _PyCFunction_CAST(func) \
46-
_Py_reinterpret_cast(PyCFunction, _Py_reinterpret_cast(void(*)(void), (func)))
46+
_Py_CAST(PyCFunction, _Py_CAST(void(*)(void), (func)))
4747

4848
PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *);
4949
PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *);

Include/object.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ struct _object {
104104
};
105105

106106
/* Cast argument to PyObject* type. */
107-
#define _PyObject_CAST(op) _Py_reinterpret_cast(PyObject*, (op))
107+
#define _PyObject_CAST(op) _Py_CAST(PyObject*, (op))
108108

109109
typedef struct {
110110
PyObject ob_base;
111111
Py_ssize_t ob_size; /* Number of items in variable part */
112112
} PyVarObject;
113113

114114
/* Cast argument to PyVarObject* type. */
115-
#define _PyVarObject_CAST(op) _Py_reinterpret_cast(PyVarObject*, (op))
115+
#define _PyVarObject_CAST(op) _Py_CAST(PyVarObject*, (op))
116116

117117

118118
// 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) {
781781
#endif
782782

783783
#define _PyType_CAST(op) \
784-
(assert(PyType_Check(op)), _Py_reinterpret_cast(PyTypeObject*, (op)))
784+
(assert(PyType_Check(op)), _Py_CAST(PyTypeObject*, (op)))
785785

786786
static inline int PyType_CheckExact(PyObject *op) {
787787
return Py_IS_TYPE(op, &PyType_Type);

Include/objimpl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ PyAPI_FUNC(void) PyObject_GC_UnTrack(void *);
182182
PyAPI_FUNC(void) PyObject_GC_Del(void *);
183183

184184
#define PyObject_GC_New(type, typeobj) \
185-
_Py_reinterpret_cast(type*, _PyObject_GC_New(typeobj))
185+
_Py_CAST(type*, _PyObject_GC_New(typeobj))
186186
#define PyObject_GC_NewVar(type, typeobj, n) \
187-
_Py_reinterpret_cast(type*, _PyObject_GC_NewVar((typeobj), (n)))
187+
_Py_CAST(type*, _PyObject_GC_NewVar((typeobj), (n)))
188188

189189
PyAPI_FUNC(int) PyObject_GC_IsTracked(PyObject *);
190190
PyAPI_FUNC(int) PyObject_GC_IsFinalized(PyObject *);

Include/pyport.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@
1717
// Macro to use C++ static_cast<>, reinterpret_cast<> and const_cast<>
1818
// in the Python C API.
1919
//
20-
// In C++, _Py_reinterpret_cast(type, expr) converts a constant expression to a
20+
// In C++, _Py_CAST(type, expr) converts a constant expression to a
2121
// non constant type using const_cast<type>. For example,
22-
// _Py_reinterpret_cast(PyObject*, op) can convert a "const PyObject*" to
22+
// _Py_CAST(PyObject*, op) can convert a "const PyObject*" to
2323
// "PyObject*".
2424
//
2525
// The type argument must not be constant. For example, in C++,
26-
// _Py_reinterpret_cast(const PyObject*, expr) fails with a compiler error.
26+
// _Py_CAST(const PyObject*, expr) fails with a compiler error.
2727
#ifdef __cplusplus
28-
# define _Py_static_cast(type, expr) static_cast<type>(expr)
29-
# define _Py_reinterpret_cast(type, expr) \
28+
# define _Py_STATIC_CAST(type, expr) static_cast<type>(expr)
29+
# define _Py_CAST(type, expr) \
3030
const_cast<type>(reinterpret_cast<const type>(expr))
3131
#else
32-
# define _Py_static_cast(type, expr) ((type)(expr))
33-
# define _Py_reinterpret_cast(type, expr) ((type)(expr))
32+
# define _Py_STATIC_CAST(type, expr) ((type)(expr))
33+
# define _Py_CAST(type, expr) ((type)(expr))
3434
#endif
3535

3636

@@ -317,10 +317,10 @@ extern "C" {
317317
*/
318318
#ifdef Py_DEBUG
319319
# define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) \
320-
(assert(_Py_static_cast(WIDE, _Py_static_cast(NARROW, (VALUE))) == (VALUE)), \
321-
_Py_static_cast(NARROW, (VALUE)))
320+
(assert(_Py_STATIC_CAST(WIDE, _Py_STATIC_CAST(NARROW, (VALUE))) == (VALUE)), \
321+
_Py_STATIC_CAST(NARROW, (VALUE)))
322322
#else
323-
# define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) _Py_static_cast(NARROW, (VALUE))
323+
# define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) _Py_STATIC_CAST(NARROW, (VALUE))
324324
#endif
325325

326326

0 commit comments

Comments
 (0)