Skip to content

Commit 8767ce9

Browse files
authored
bpo-39573: Make Py_IS_TYPE() take constant parameters (GH-18799)
Add _PyObject_CAST_CONST() macro: cast a pointer to (const PyObject *).
1 parent 8bae219 commit 8767ce9

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Include/object.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ typedef struct _object {
110110

111111
/* Cast argument to PyObject* type. */
112112
#define _PyObject_CAST(op) ((PyObject*)(op))
113+
#define _PyObject_CAST_CONST(op) ((const PyObject*)(op))
113114

114115
typedef struct {
115116
PyObject ob_base;
@@ -123,10 +124,10 @@ typedef struct {
123124
#define Py_TYPE(ob) (_PyObject_CAST(ob)->ob_type)
124125
#define Py_SIZE(ob) (_PyVarObject_CAST(ob)->ob_size)
125126

126-
static inline int _Py_IS_TYPE(PyObject *ob, PyTypeObject *type) {
127+
static inline int _Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type) {
127128
return ob->ob_type == type;
128129
}
129-
#define Py_IS_TYPE(ob, type) _Py_IS_TYPE(_PyObject_CAST(ob), type)
130+
#define Py_IS_TYPE(ob, type) _Py_IS_TYPE(_PyObject_CAST_CONST(ob), type)
130131

131132
static inline void _Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) {
132133
ob->ob_refcnt = refcnt;

0 commit comments

Comments
 (0)