From 0d76d2bd28ac815dabae8b07240ed002ac8fce2d Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 7 Feb 2020 01:53:23 +0100 Subject: [PATCH] bpo-39573: Use Py_TYPE() in abstract.c (GH-18390) Replace direct access to PyObject.ob_type with Py_TYPE(). --- Objects/abstract.c | 188 ++++++++++++++++++++++----------------------- 1 file changed, 94 insertions(+), 94 deletions(-) diff --git a/Objects/abstract.c b/Objects/abstract.c index aca1a4e5189..7ab58a8bd52 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -14,7 +14,7 @@ static PyObject * type_error(const char *msg, PyObject *obj) { - PyErr_Format(PyExc_TypeError, msg, obj->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, msg, Py_TYPE(obj)->tp_name); return NULL; } @@ -38,7 +38,7 @@ PyObject_Type(PyObject *o) return null_error(); } - v = (PyObject *)o->ob_type; + v = (PyObject *)Py_TYPE(o); Py_INCREF(v); return v; } @@ -53,7 +53,7 @@ PyObject_Size(PyObject *o) return -1; } - m = o->ob_type->tp_as_sequence; + m = Py_TYPE(o)->tp_as_sequence; if (m && m->sq_length) { Py_ssize_t len = m->sq_length(o); assert(len >= 0 || PyErr_Occurred()); @@ -150,14 +150,14 @@ PyObject_GetItem(PyObject *o, PyObject *key) return null_error(); } - m = o->ob_type->tp_as_mapping; + m = Py_TYPE(o)->tp_as_mapping; if (m && m->mp_subscript) { PyObject *item = m->mp_subscript(o, key); assert((item != NULL) ^ (PyErr_Occurred() != NULL)); return item; } - ms = o->ob_type->tp_as_sequence; + ms = Py_TYPE(o)->tp_as_sequence; if (ms && ms->sq_item) { if (PyIndex_Check(key)) { Py_ssize_t key_value; @@ -197,11 +197,11 @@ PyObject_SetItem(PyObject *o, PyObject *key, PyObject *value) null_error(); return -1; } - m = o->ob_type->tp_as_mapping; + m = Py_TYPE(o)->tp_as_mapping; if (m && m->mp_ass_subscript) return m->mp_ass_subscript(o, key, value); - if (o->ob_type->tp_as_sequence) { + if (Py_TYPE(o)->tp_as_sequence) { if (PyIndex_Check(key)) { Py_ssize_t key_value; key_value = PyNumber_AsSsize_t(key, PyExc_IndexError); @@ -209,7 +209,7 @@ PyObject_SetItem(PyObject *o, PyObject *key, PyObject *value) return -1; return PySequence_SetItem(o, key_value, value); } - else if (o->ob_type->tp_as_sequence->sq_ass_item) { + else if (Py_TYPE(o)->tp_as_sequence->sq_ass_item) { type_error("sequence index must be " "integer, not '%.200s'", key); return -1; @@ -229,11 +229,11 @@ PyObject_DelItem(PyObject *o, PyObject *key) null_error(); return -1; } - m = o->ob_type->tp_as_mapping; + m = Py_TYPE(o)->tp_as_mapping; if (m && m->mp_ass_subscript) return m->mp_ass_subscript(o, key, (PyObject*)NULL); - if (o->ob_type->tp_as_sequence) { + if (Py_TYPE(o)->tp_as_sequence) { if (PyIndex_Check(key)) { Py_ssize_t key_value; key_value = PyNumber_AsSsize_t(key, PyExc_IndexError); @@ -241,7 +241,7 @@ PyObject_DelItem(PyObject *o, PyObject *key) return -1; return PySequence_DelItem(o, key_value); } - else if (o->ob_type->tp_as_sequence->sq_ass_item) { + else if (Py_TYPE(o)->tp_as_sequence->sq_ass_item) { type_error("sequence index must be " "integer, not '%.200s'", key); return -1; @@ -276,7 +276,7 @@ PyObject_DelItemString(PyObject *o, const char *key) int PyObject_CheckReadBuffer(PyObject *obj) { - PyBufferProcs *pb = obj->ob_type->tp_as_buffer; + PyBufferProcs *pb = Py_TYPE(obj)->tp_as_buffer; Py_buffer view; if (pb == NULL || @@ -334,7 +334,7 @@ int PyObject_AsWriteBuffer(PyObject *obj, null_error(); return -1; } - pb = obj->ob_type->tp_as_buffer; + pb = Py_TYPE(obj)->tp_as_buffer; if (pb == NULL || pb->bf_getbuffer == NULL || ((*pb->bf_getbuffer)(obj, &view, PyBUF_WRITABLE) != 0)) { @@ -354,7 +354,7 @@ int PyObject_AsWriteBuffer(PyObject *obj, int PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags) { - PyBufferProcs *pb = obj->ob_type->tp_as_buffer; + PyBufferProcs *pb = Py_TYPE(obj)->tp_as_buffer; if (pb == NULL || pb->bf_getbuffer == NULL) { PyErr_Format(PyExc_TypeError, @@ -801,10 +801,10 @@ done: int PyNumber_Check(PyObject *o) { - return o && o->ob_type->tp_as_number && - (o->ob_type->tp_as_number->nb_index || - o->ob_type->tp_as_number->nb_int || - o->ob_type->tp_as_number->nb_float); + return o && Py_TYPE(o)->tp_as_number && + (Py_TYPE(o)->tp_as_number->nb_index || + Py_TYPE(o)->tp_as_number->nb_int || + Py_TYPE(o)->tp_as_number->nb_float); } /* Binary operators */ @@ -821,8 +821,8 @@ PyNumber_Check(PyObject *o) Order operations are tried until either a valid result or error: w.op(v,w)[*], v.op(v,w), w.op(v,w) - [*] only when v->ob_type != w->ob_type && w->ob_type is a subclass of - v->ob_type + [*] only when Py_TYPE(v) != Py_TYPE(w) && Py_TYPE(w) is a subclass of + Py_TYPE(v) */ static PyObject * @@ -832,16 +832,16 @@ binary_op1(PyObject *v, PyObject *w, const int op_slot) binaryfunc slotv = NULL; binaryfunc slotw = NULL; - if (v->ob_type->tp_as_number != NULL) - slotv = NB_BINOP(v->ob_type->tp_as_number, op_slot); - if (w->ob_type != v->ob_type && - w->ob_type->tp_as_number != NULL) { - slotw = NB_BINOP(w->ob_type->tp_as_number, op_slot); + if (Py_TYPE(v)->tp_as_number != NULL) + slotv = NB_BINOP(Py_TYPE(v)->tp_as_number, op_slot); + if (Py_TYPE(w) != Py_TYPE(v) && + Py_TYPE(w)->tp_as_number != NULL) { + slotw = NB_BINOP(Py_TYPE(w)->tp_as_number, op_slot); if (slotw == slotv) slotw = NULL; } if (slotv) { - if (slotw && PyType_IsSubtype(w->ob_type, v->ob_type)) { + if (slotw && PyType_IsSubtype(Py_TYPE(w), Py_TYPE(v))) { x = slotw(v, w); if (x != Py_NotImplemented) return x; @@ -869,8 +869,8 @@ binop_type_error(PyObject *v, PyObject *w, const char *op_name) "unsupported operand type(s) for %.100s: " "'%.100s' and '%.100s'", op_name, - v->ob_type->tp_name, - w->ob_type->tp_name); + Py_TYPE(v)->tp_name, + Py_TYPE(w)->tp_name); return NULL; } @@ -890,8 +890,8 @@ binary_op(PyObject *v, PyObject *w, const int op_slot, const char *op_name) "'%.100s' and '%.100s'. Did you mean \"print(, " "file=)\"?", op_name, - v->ob_type->tp_name, - w->ob_type->tp_name); + Py_TYPE(v)->tp_name, + Py_TYPE(w)->tp_name); return NULL; } @@ -921,18 +921,18 @@ ternary_op(PyObject *v, ternaryfunc slotw = NULL; ternaryfunc slotz = NULL; - mv = v->ob_type->tp_as_number; - mw = w->ob_type->tp_as_number; + mv = Py_TYPE(v)->tp_as_number; + mw = Py_TYPE(w)->tp_as_number; if (mv != NULL) slotv = NB_TERNOP(mv, op_slot); - if (w->ob_type != v->ob_type && + if (Py_TYPE(w) != Py_TYPE(v) && mw != NULL) { slotw = NB_TERNOP(mw, op_slot); if (slotw == slotv) slotw = NULL; } if (slotv) { - if (slotw && PyType_IsSubtype(w->ob_type, v->ob_type)) { + if (slotw && PyType_IsSubtype(Py_TYPE(w), Py_TYPE(v))) { x = slotw(v, w, z); if (x != Py_NotImplemented) return x; @@ -950,7 +950,7 @@ ternary_op(PyObject *v, return x; Py_DECREF(x); /* can't do it */ } - mz = z->ob_type->tp_as_number; + mz = Py_TYPE(z)->tp_as_number; if (mz != NULL) { slotz = NB_TERNOP(mz, op_slot); if (slotz == slotv || slotz == slotw) @@ -968,16 +968,16 @@ ternary_op(PyObject *v, PyExc_TypeError, "unsupported operand type(s) for ** or pow(): " "'%.100s' and '%.100s'", - v->ob_type->tp_name, - w->ob_type->tp_name); + Py_TYPE(v)->tp_name, + Py_TYPE(w)->tp_name); else PyErr_Format( PyExc_TypeError, "unsupported operand type(s) for pow(): " "'%.100s', '%.100s', '%.100s'", - v->ob_type->tp_name, - w->ob_type->tp_name, - z->ob_type->tp_name); + Py_TYPE(v)->tp_name, + Py_TYPE(w)->tp_name, + Py_TYPE(z)->tp_name); return NULL; } @@ -1000,7 +1000,7 @@ PyNumber_Add(PyObject *v, PyObject *w) { PyObject *result = binary_op1(v, w, NB_SLOT(nb_add)); if (result == Py_NotImplemented) { - PySequenceMethods *m = v->ob_type->tp_as_sequence; + PySequenceMethods *m = Py_TYPE(v)->tp_as_sequence; Py_DECREF(result); if (m && m->sq_concat) { return (*m->sq_concat)(v, w); @@ -1031,8 +1031,8 @@ PyNumber_Multiply(PyObject *v, PyObject *w) { PyObject *result = binary_op1(v, w, NB_SLOT(nb_multiply)); if (result == Py_NotImplemented) { - PySequenceMethods *mv = v->ob_type->tp_as_sequence; - PySequenceMethods *mw = w->ob_type->tp_as_sequence; + PySequenceMethods *mv = Py_TYPE(v)->tp_as_sequence; + PySequenceMethods *mw = Py_TYPE(w)->tp_as_sequence; Py_DECREF(result); if (mv && mv->sq_repeat) { return sequence_repeat(mv->sq_repeat, v, w); @@ -1094,7 +1094,7 @@ PyNumber_Power(PyObject *v, PyObject *w, PyObject *z) static PyObject * binary_iop1(PyObject *v, PyObject *w, const int iop_slot, const int op_slot) { - PyNumberMethods *mv = v->ob_type->tp_as_number; + PyNumberMethods *mv = Py_TYPE(v)->tp_as_number; if (mv != NULL) { binaryfunc slot = NB_BINOP(mv, iop_slot); if (slot) { @@ -1154,7 +1154,7 @@ PyNumber_InPlaceAdd(PyObject *v, PyObject *w) PyObject *result = binary_iop1(v, w, NB_SLOT(nb_inplace_add), NB_SLOT(nb_add)); if (result == Py_NotImplemented) { - PySequenceMethods *m = v->ob_type->tp_as_sequence; + PySequenceMethods *m = Py_TYPE(v)->tp_as_sequence; Py_DECREF(result); if (m != NULL) { binaryfunc f = NULL; @@ -1176,8 +1176,8 @@ PyNumber_InPlaceMultiply(PyObject *v, PyObject *w) NB_SLOT(nb_multiply)); if (result == Py_NotImplemented) { ssizeargfunc f = NULL; - PySequenceMethods *mv = v->ob_type->tp_as_sequence; - PySequenceMethods *mw = w->ob_type->tp_as_sequence; + PySequenceMethods *mv = Py_TYPE(v)->tp_as_sequence; + PySequenceMethods *mw = Py_TYPE(w)->tp_as_sequence; Py_DECREF(result); if (mv != NULL) { f = mv->sq_inplace_repeat; @@ -1215,8 +1215,8 @@ PyNumber_InPlaceRemainder(PyObject *v, PyObject *w) PyObject * PyNumber_InPlacePower(PyObject *v, PyObject *w, PyObject *z) { - if (v->ob_type->tp_as_number && - v->ob_type->tp_as_number->nb_inplace_power != NULL) { + if (Py_TYPE(v)->tp_as_number && + Py_TYPE(v)->tp_as_number->nb_inplace_power != NULL) { return ternary_op(v, w, z, NB_SLOT(nb_inplace_power), "**="); } else { @@ -1236,7 +1236,7 @@ PyNumber_Negative(PyObject *o) return null_error(); } - m = o->ob_type->tp_as_number; + m = Py_TYPE(o)->tp_as_number; if (m && m->nb_negative) return (*m->nb_negative)(o); @@ -1252,7 +1252,7 @@ PyNumber_Positive(PyObject *o) return null_error(); } - m = o->ob_type->tp_as_number; + m = Py_TYPE(o)->tp_as_number; if (m && m->nb_positive) return (*m->nb_positive)(o); @@ -1268,7 +1268,7 @@ PyNumber_Invert(PyObject *o) return null_error(); } - m = o->ob_type->tp_as_number; + m = Py_TYPE(o)->tp_as_number; if (m && m->nb_invert) return (*m->nb_invert)(o); @@ -1284,7 +1284,7 @@ PyNumber_Absolute(PyObject *o) return null_error(); } - m = o->ob_type->tp_as_number; + m = Py_TYPE(o)->tp_as_number; if (m && m->nb_absolute) return m->nb_absolute(o); @@ -1296,8 +1296,8 @@ PyNumber_Absolute(PyObject *o) int PyIndex_Check(PyObject *obj) { - return obj->ob_type->tp_as_number != NULL && - obj->ob_type->tp_as_number->nb_index != NULL; + return Py_TYPE(obj)->tp_as_number != NULL && + Py_TYPE(obj)->tp_as_number->nb_index != NULL; } /* Return a Python int from the object item. @@ -1319,16 +1319,16 @@ PyNumber_Index(PyObject *item) if (!PyIndex_Check(item)) { PyErr_Format(PyExc_TypeError, "'%.200s' object cannot be interpreted " - "as an integer", item->ob_type->tp_name); + "as an integer", Py_TYPE(item)->tp_name); return NULL; } - result = item->ob_type->tp_as_number->nb_index(item); + result = Py_TYPE(item)->tp_as_number->nb_index(item); if (!result || PyLong_CheckExact(result)) return result; if (!PyLong_Check(result)) { PyErr_Format(PyExc_TypeError, "__index__ returned non-int (type %.200s)", - result->ob_type->tp_name); + Py_TYPE(result)->tp_name); Py_DECREF(result); return NULL; } @@ -1337,7 +1337,7 @@ PyNumber_Index(PyObject *item) "__index__ returned non-int (type %.200s). " "The ability to return an instance of a strict subclass of int " "is deprecated, and may be removed in a future version of Python.", - result->ob_type->tp_name)) { + Py_TYPE(result)->tp_name)) { Py_DECREF(result); return NULL; } @@ -1382,7 +1382,7 @@ PyNumber_AsSsize_t(PyObject *item, PyObject *err) /* Otherwise replace the error with caller's error object. */ PyErr_Format(err, "cannot fit '%.200s' into an index-sized integer", - item->ob_type->tp_name); + Py_TYPE(item)->tp_name); } finish: @@ -1408,7 +1408,7 @@ PyNumber_Long(PyObject *o) Py_INCREF(o); return o; } - m = o->ob_type->tp_as_number; + m = Py_TYPE(o)->tp_as_number; if (m && m->nb_int) { /* This should include subclasses of int */ result = _PyLong_FromNbInt(o); if (result != NULL && !PyLong_CheckExact(result)) { @@ -1436,12 +1436,12 @@ PyNumber_Long(PyObject *o) } /* __trunc__ is specified to return an Integral type, but int() needs to return an int. */ - m = result->ob_type->tp_as_number; + m = Py_TYPE(result)->tp_as_number; if (m == NULL || (m->nb_index == NULL && m->nb_int == NULL)) { PyErr_Format( PyExc_TypeError, "__trunc__ returned non-Integral (type %.200s)", - result->ob_type->tp_name); + Py_TYPE(result)->tp_name); Py_DECREF(result); return NULL; } @@ -1503,7 +1503,7 @@ PyNumber_Float(PyObject *o) Py_INCREF(o); return o; } - m = o->ob_type->tp_as_number; + m = Py_TYPE(o)->tp_as_number; if (m && m->nb_float) { /* This should include subclasses of float */ PyObject *res = m->nb_float(o); double val; @@ -1513,7 +1513,7 @@ PyNumber_Float(PyObject *o) if (!PyFloat_Check(res)) { PyErr_Format(PyExc_TypeError, "%.50s.__float__ returned non-float (type %.50s)", - o->ob_type->tp_name, res->ob_type->tp_name); + Py_TYPE(o)->tp_name, Py_TYPE(res)->tp_name); Py_DECREF(res); return NULL; } @@ -1522,7 +1522,7 @@ PyNumber_Float(PyObject *o) "%.50s.__float__ returned non-float (type %.50s). " "The ability to return an instance of a strict subclass of float " "is deprecated, and may be removed in a future version of Python.", - o->ob_type->tp_name, res->ob_type->tp_name)) { + Py_TYPE(o)->tp_name, Py_TYPE(res)->tp_name)) { Py_DECREF(res); return NULL; } @@ -1576,8 +1576,8 @@ PySequence_Check(PyObject *s) { if (PyDict_Check(s)) return 0; - return s->ob_type->tp_as_sequence && - s->ob_type->tp_as_sequence->sq_item != NULL; + return Py_TYPE(s)->tp_as_sequence && + Py_TYPE(s)->tp_as_sequence->sq_item != NULL; } Py_ssize_t @@ -1590,14 +1590,14 @@ PySequence_Size(PyObject *s) return -1; } - m = s->ob_type->tp_as_sequence; + m = Py_TYPE(s)->tp_as_sequence; if (m && m->sq_length) { Py_ssize_t len = m->sq_length(s); assert(len >= 0 || PyErr_Occurred()); return len; } - if (s->ob_type->tp_as_mapping && s->ob_type->tp_as_mapping->mp_length) { + if (Py_TYPE(s)->tp_as_mapping && Py_TYPE(s)->tp_as_mapping->mp_length) { type_error("%.200s is not a sequence", s); return -1; } @@ -1622,7 +1622,7 @@ PySequence_Concat(PyObject *s, PyObject *o) return null_error(); } - m = s->ob_type->tp_as_sequence; + m = Py_TYPE(s)->tp_as_sequence; if (m && m->sq_concat) return m->sq_concat(s, o); @@ -1647,7 +1647,7 @@ PySequence_Repeat(PyObject *o, Py_ssize_t count) return null_error(); } - m = o->ob_type->tp_as_sequence; + m = Py_TYPE(o)->tp_as_sequence; if (m && m->sq_repeat) return m->sq_repeat(o, count); @@ -1677,7 +1677,7 @@ PySequence_InPlaceConcat(PyObject *s, PyObject *o) return null_error(); } - m = s->ob_type->tp_as_sequence; + m = Py_TYPE(s)->tp_as_sequence; if (m && m->sq_inplace_concat) return m->sq_inplace_concat(s, o); if (m && m->sq_concat) @@ -1702,7 +1702,7 @@ PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count) return null_error(); } - m = o->ob_type->tp_as_sequence; + m = Py_TYPE(o)->tp_as_sequence; if (m && m->sq_inplace_repeat) return m->sq_inplace_repeat(o, count); if (m && m->sq_repeat) @@ -1732,7 +1732,7 @@ PySequence_GetItem(PyObject *s, Py_ssize_t i) return null_error(); } - m = s->ob_type->tp_as_sequence; + m = Py_TYPE(s)->tp_as_sequence; if (m && m->sq_item) { if (i < 0) { if (m->sq_length) { @@ -1747,7 +1747,7 @@ PySequence_GetItem(PyObject *s, Py_ssize_t i) return m->sq_item(s, i); } - if (s->ob_type->tp_as_mapping && s->ob_type->tp_as_mapping->mp_subscript) { + if (Py_TYPE(s)->tp_as_mapping && Py_TYPE(s)->tp_as_mapping->mp_subscript) { return type_error("%.200s is not a sequence", s); } return type_error("'%.200s' object does not support indexing", s); @@ -1762,7 +1762,7 @@ PySequence_GetSlice(PyObject *s, Py_ssize_t i1, Py_ssize_t i2) return null_error(); } - mp = s->ob_type->tp_as_mapping; + mp = Py_TYPE(s)->tp_as_mapping; if (mp && mp->mp_subscript) { PyObject *res; PyObject *slice = _PySlice_FromIndices(i1, i2); @@ -1786,7 +1786,7 @@ PySequence_SetItem(PyObject *s, Py_ssize_t i, PyObject *o) return -1; } - m = s->ob_type->tp_as_sequence; + m = Py_TYPE(s)->tp_as_sequence; if (m && m->sq_ass_item) { if (i < 0) { if (m->sq_length) { @@ -1801,7 +1801,7 @@ PySequence_SetItem(PyObject *s, Py_ssize_t i, PyObject *o) return m->sq_ass_item(s, i, o); } - if (s->ob_type->tp_as_mapping && s->ob_type->tp_as_mapping->mp_ass_subscript) { + if (Py_TYPE(s)->tp_as_mapping && Py_TYPE(s)->tp_as_mapping->mp_ass_subscript) { type_error("%.200s is not a sequence", s); return -1; } @@ -1819,7 +1819,7 @@ PySequence_DelItem(PyObject *s, Py_ssize_t i) return -1; } - m = s->ob_type->tp_as_sequence; + m = Py_TYPE(s)->tp_as_sequence; if (m && m->sq_ass_item) { if (i < 0) { if (m->sq_length) { @@ -1834,7 +1834,7 @@ PySequence_DelItem(PyObject *s, Py_ssize_t i) return m->sq_ass_item(s, i, (PyObject *)NULL); } - if (s->ob_type->tp_as_mapping && s->ob_type->tp_as_mapping->mp_ass_subscript) { + if (Py_TYPE(s)->tp_as_mapping && Py_TYPE(s)->tp_as_mapping->mp_ass_subscript) { type_error("%.200s is not a sequence", s); return -1; } @@ -1852,7 +1852,7 @@ PySequence_SetSlice(PyObject *s, Py_ssize_t i1, Py_ssize_t i2, PyObject *o) return -1; } - mp = s->ob_type->tp_as_mapping; + mp = Py_TYPE(s)->tp_as_mapping; if (mp && mp->mp_ass_subscript) { int res; PyObject *slice = _PySlice_FromIndices(i1, i2); @@ -1877,7 +1877,7 @@ PySequence_DelSlice(PyObject *s, Py_ssize_t i1, Py_ssize_t i2) return -1; } - mp = s->ob_type->tp_as_mapping; + mp = Py_TYPE(s)->tp_as_mapping; if (mp && mp->mp_ass_subscript) { int res; PyObject *slice = _PySlice_FromIndices(i1, i2); @@ -2127,7 +2127,7 @@ int PySequence_Contains(PyObject *seq, PyObject *ob) { Py_ssize_t result; - PySequenceMethods *sqm = seq->ob_type->tp_as_sequence; + PySequenceMethods *sqm = Py_TYPE(seq)->tp_as_sequence; if (sqm != NULL && sqm->sq_contains != NULL) return (*sqm->sq_contains)(seq, ob); result = _PySequence_IterSearch(seq, ob, PY_ITERSEARCH_CONTAINS); @@ -2153,8 +2153,8 @@ PySequence_Index(PyObject *s, PyObject *o) int PyMapping_Check(PyObject *o) { - return o && o->ob_type->tp_as_mapping && - o->ob_type->tp_as_mapping->mp_subscript; + return o && Py_TYPE(o)->tp_as_mapping && + Py_TYPE(o)->tp_as_mapping->mp_subscript; } Py_ssize_t @@ -2167,14 +2167,14 @@ PyMapping_Size(PyObject *o) return -1; } - m = o->ob_type->tp_as_mapping; + m = Py_TYPE(o)->tp_as_mapping; if (m && m->mp_length) { Py_ssize_t len = m->mp_length(o); assert(len >= 0 || PyErr_Occurred()); return len; } - if (o->ob_type->tp_as_sequence && o->ob_type->tp_as_sequence->sq_length) { + if (Py_TYPE(o)->tp_as_sequence && Py_TYPE(o)->tp_as_sequence->sq_length) { type_error("%.200s is not a mapping", o); return -1; } @@ -2434,7 +2434,7 @@ object_isinstance(PyObject *inst, PyObject *cls) if (retval == 0) { retval = _PyObject_LookupAttrId(inst, &PyId___class__, &icls); if (icls != NULL) { - if (icls != (PyObject *)(inst->ob_type) && PyType_Check(icls)) { + if (icls != (PyObject *)(Py_TYPE(inst)) && PyType_Check(icls)) { retval = PyType_IsSubtype( (PyTypeObject *)icls, (PyTypeObject *)cls); @@ -2630,7 +2630,7 @@ _PyObject_RealIsSubclass(PyObject *derived, PyObject *cls) PyObject * PyObject_GetIter(PyObject *o) { - PyTypeObject *t = o->ob_type; + PyTypeObject *t = Py_TYPE(o); getiterfunc f; f = t->tp_iter; @@ -2645,7 +2645,7 @@ PyObject_GetIter(PyObject *o) PyErr_Format(PyExc_TypeError, "iter() returned non-iterator " "of type '%.100s'", - res->ob_type->tp_name); + Py_TYPE(res)->tp_name); Py_DECREF(res); res = NULL; } @@ -2657,8 +2657,8 @@ PyObject_GetIter(PyObject *o) int PyIter_Check(PyObject *obj) { - return obj->ob_type->tp_iternext != NULL && - obj->ob_type->tp_iternext != &_PyObject_NextNotImplemented; + return Py_TYPE(obj)->tp_iternext != NULL && + Py_TYPE(obj)->tp_iternext != &_PyObject_NextNotImplemented; } /* Return next item. @@ -2672,7 +2672,7 @@ PyObject * PyIter_Next(PyObject *iter) { PyObject *result; - result = (*iter->ob_type->tp_iternext)(iter); + result = (*Py_TYPE(iter)->tp_iternext)(iter); if (result == NULL && PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration))