@@ -26,6 +26,9 @@ extern "C" {
2626#ifndef _PyObject_CAST
2727# define _PyObject_CAST (op ) ((PyObject*)(op))
2828#endif
29+ #ifndef _PyObject_CAST_CONST
30+ # define _PyObject_CAST_CONST (op ) ((const PyObject*)(op))
31+ #endif
2932
3033
3134// bpo-42262 added Py_NewRef() to Python 3.10.0a3
@@ -56,7 +59,7 @@ static inline void _Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt)
5659{
5760 ob -> ob_refcnt = refcnt ;
5861}
59- #define Py_SET_REFCNT (ob , refcnt ) _Py_SET_REFCNT((PyObject*) (ob), refcnt)
62+ #define Py_SET_REFCNT (ob , refcnt ) _Py_SET_REFCNT(_PyObject_CAST (ob), refcnt)
6063#endif
6164
6265
@@ -67,7 +70,7 @@ _Py_SET_TYPE(PyObject *ob, PyTypeObject *type)
6770{
6871 ob -> ob_type = type ;
6972}
70- #define Py_SET_TYPE (ob , type ) _Py_SET_TYPE((PyObject*) (ob), type)
73+ #define Py_SET_TYPE (ob , type ) _Py_SET_TYPE(_PyObject_CAST (ob), type)
7174#endif
7275
7376
@@ -270,7 +273,7 @@ static inline int
270273_Py_IS_TYPE (const PyObject * ob , const PyTypeObject * type ) {
271274 return ob -> ob_type == type ;
272275}
273- #define Py_IS_TYPE (ob , type ) _Py_IS_TYPE((const PyObject*) (ob), type)
276+ #define Py_IS_TYPE (ob , type ) _Py_IS_TYPE(_PyObject_CAST_CONST (ob), type)
274277#endif
275278
276279
0 commit comments