diff options
author | Victor Stinner <vstinner@python.org> | 2020-02-07 02:04:21 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-07 02:04:21 (GMT) |
commit | 58ac700fb09497df14d4492b6f820109490b2b88 (patch) | |
tree | d6a87b277dd133543974b1b24cf65df4c5c8eff4 | |
parent | a102ed7d2f0e7e05438f14d5fb72ca0358602249 (diff) | |
download | cpython-58ac700fb09497df14d4492b6f820109490b2b88.zip cpython-58ac700fb09497df14d4492b6f820109490b2b88.tar.gz cpython-58ac700fb09497df14d4492b6f820109490b2b88.tar.bz2 |
bpo-39573: Use Py_TYPE() macro in Objects directory (GH-18392)
Replace direct access to PyObject.ob_type with Py_TYPE().
-rw-r--r-- | Objects/bytearrayobject.c | 4 | ||||
-rw-r--r-- | Objects/bytesobject.c | 2 | ||||
-rw-r--r-- | Objects/call.c | 4 | ||||
-rw-r--r-- | Objects/cellobject.c | 2 | ||||
-rw-r--r-- | Objects/classobject.c | 12 | ||||
-rw-r--r-- | Objects/codeobject.c | 2 | ||||
-rw-r--r-- | Objects/complexobject.c | 8 | ||||
-rw-r--r-- | Objects/descrobject.c | 14 | ||||
-rw-r--r-- | Objects/dictobject.c | 2 | ||||
-rw-r--r-- | Objects/floatobject.c | 6 | ||||
-rw-r--r-- | Objects/funcobject.c | 4 | ||||
-rw-r--r-- | Objects/interpreteridobject.c | 2 | ||||
-rw-r--r-- | Objects/listobject.c | 38 | ||||
-rw-r--r-- | Objects/longobject.c | 8 | ||||
-rw-r--r-- | Objects/methodobject.c | 2 | ||||
-rw-r--r-- | Objects/namespaceobject.c | 2 | ||||
-rw-r--r-- | Objects/object.c | 68 | ||||
-rw-r--r-- | Objects/rangeobject.c | 4 | ||||
-rw-r--r-- | Objects/typeobject.c | 26 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 8 |
20 files changed, 109 insertions, 109 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index c9bf11b..a019b49 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -856,7 +856,7 @@ bytearray_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds) if (PyErr_ExceptionMatches(PyExc_TypeError)) { PyErr_Format(PyExc_TypeError, "cannot convert '%.200s' object to bytearray", - arg->ob_type->tp_name); + Py_TYPE(arg)->tp_name); } return -1; } @@ -1630,7 +1630,7 @@ bytearray_extend(PyByteArrayObject *self, PyObject *iterable_of_ints) if (PyErr_ExceptionMatches(PyExc_TypeError)) { PyErr_Format(PyExc_TypeError, "can't extend bytearray with %.100s", - iterable_of_ints->ob_type->tp_name); + Py_TYPE(iterable_of_ints)->tp_name); } return NULL; } diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index 5334eca..4edd93d 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -2762,7 +2762,7 @@ PyBytes_FromObject(PyObject *x) PyErr_Format(PyExc_TypeError, "cannot convert '%.200s' object to bytes", - x->ob_type->tp_name); + Py_TYPE(x)->tp_name); return NULL; } diff --git a/Objects/call.c b/Objects/call.c index 0f8cb5a..d1d50b6 100644 --- a/Objects/call.c +++ b/Objects/call.c @@ -263,11 +263,11 @@ _PyObject_Call(PyThreadState *tstate, PyObject *callable, return PyVectorcall_Call(callable, args, kwargs); } else { - call = callable->ob_type->tp_call; + call = Py_TYPE(callable)->tp_call; if (call == NULL) { _PyErr_Format(tstate, PyExc_TypeError, "'%.200s' object is not callable", - callable->ob_type->tp_name); + Py_TYPE(callable)->tp_name); return NULL; } diff --git a/Objects/cellobject.c b/Objects/cellobject.c index 911cf52..e97feef 100644 --- a/Objects/cellobject.c +++ b/Objects/cellobject.c @@ -112,7 +112,7 @@ cell_repr(PyCellObject *op) return PyUnicode_FromFormat("<cell at %p: empty>", op); return PyUnicode_FromFormat("<cell at %p: %.80s object at %p>", - op, op->ob_ref->ob_type->tp_name, + op, Py_TYPE(op->ob_ref)->tp_name, op->ob_ref); } diff --git a/Objects/classobject.c b/Objects/classobject.c index db53f04..fb89b8a 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -178,7 +178,7 @@ static PyObject * method_getattro(PyObject *obj, PyObject *name) { PyMethodObject *im = (PyMethodObject *)obj; - PyTypeObject *tp = obj->ob_type; + PyTypeObject *tp = Py_TYPE(obj); PyObject *descr = NULL; { @@ -190,9 +190,9 @@ method_getattro(PyObject *obj, PyObject *name) } if (descr != NULL) { - descrgetfunc f = TP_DESCR_GET(descr->ob_type); + descrgetfunc f = TP_DESCR_GET(Py_TYPE(descr)); if (f != NULL) - return f(descr, obj, (PyObject *)obj->ob_type); + return f(descr, obj, (PyObject *)Py_TYPE(obj)); else { Py_INCREF(descr); return descr; @@ -425,7 +425,7 @@ static PyGetSetDef instancemethod_getset[] = { static PyObject * instancemethod_getattro(PyObject *self, PyObject *name) { - PyTypeObject *tp = self->ob_type; + PyTypeObject *tp = Py_TYPE(self); PyObject *descr = NULL; if (tp->tp_dict == NULL) { @@ -435,9 +435,9 @@ instancemethod_getattro(PyObject *self, PyObject *name) descr = _PyType_Lookup(tp, name); if (descr != NULL) { - descrgetfunc f = TP_DESCR_GET(descr->ob_type); + descrgetfunc f = TP_DESCR_GET(Py_TYPE(descr)); if (f != NULL) - return f(descr, self, (PyObject *)self->ob_type); + return f(descr, self, (PyObject *)Py_TYPE(self)); else { Py_INCREF(descr); return descr; diff --git a/Objects/codeobject.c b/Objects/codeobject.c index c6759c9..fd64393 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -416,7 +416,7 @@ validate_and_copy_tuple(PyObject *tup) PyExc_TypeError, "name tuples must contain only " "strings, not '%.500s'", - item->ob_type->tp_name); + Py_TYPE(item)->tp_name); Py_DECREF(newtuple); return NULL; } diff --git a/Objects/complexobject.c b/Objects/complexobject.c index f1b7667..8d1461b 100644 --- a/Objects/complexobject.c +++ b/Objects/complexobject.c @@ -296,7 +296,7 @@ try_complex_special_method(PyObject *op) if (!PyComplex_Check(res)) { PyErr_Format(PyExc_TypeError, "__complex__ returned non-complex (type %.200s)", - res->ob_type->tp_name); + Py_TYPE(res)->tp_name); Py_DECREF(res); return NULL; } @@ -305,7 +305,7 @@ try_complex_special_method(PyObject *op) "__complex__ returned non-complex (type %.200s). " "The ability to return an instance of a strict subclass of complex " "is deprecated, and may be removed in a future version of Python.", - res->ob_type->tp_name)) { + Py_TYPE(res)->tp_name)) { Py_DECREF(res); return NULL; } @@ -958,7 +958,7 @@ complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i) return NULL; } - nbr = r->ob_type->tp_as_number; + nbr = Py_TYPE(r)->tp_as_number; if (nbr == NULL || (nbr->nb_float == NULL && nbr->nb_index == NULL)) { PyErr_Format(PyExc_TypeError, "complex() first argument must be a string or a number, " @@ -970,7 +970,7 @@ complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i) return NULL; } if (i != NULL) { - nbi = i->ob_type->tp_as_number; + nbi = Py_TYPE(i)->tp_as_number; if (nbi == NULL || (nbi->nb_float == NULL && nbi->nb_index == NULL)) { PyErr_Format(PyExc_TypeError, "complex() second argument must be a number, " diff --git a/Objects/descrobject.c b/Objects/descrobject.c index b9b16d6d..49c26eb 100644 --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -84,7 +84,7 @@ descr_check(PyDescrObject *descr, PyObject *obj, PyObject **pres) "doesn't apply to a '%.100s' object", descr_name((PyDescrObject *)descr), "?", descr->d_type->tp_name, - obj->ob_type->tp_name); + Py_TYPE(obj)->tp_name); *pres = NULL; return 1; } @@ -97,7 +97,7 @@ classmethod_get(PyMethodDescrObject *descr, PyObject *obj, PyObject *type) /* Ensure a valid type. Class methods ignore obj. */ if (type == NULL) { if (obj != NULL) - type = (PyObject *)obj->ob_type; + type = (PyObject *)Py_TYPE(obj); else { /* Wot - no type?! */ PyErr_Format(PyExc_TypeError, @@ -114,7 +114,7 @@ classmethod_get(PyMethodDescrObject *descr, PyObject *obj, PyObject *type) "needs a type, not a '%.100s' as arg 2", descr_name((PyDescrObject *)descr), "?", PyDescr_TYPE(descr)->tp_name, - type->ob_type->tp_name); + Py_TYPE(type)->tp_name); return NULL; } if (!PyType_IsSubtype((PyTypeObject *)type, PyDescr_TYPE(descr))) { @@ -194,7 +194,7 @@ descr_setcheck(PyDescrObject *descr, PyObject *obj, PyObject *value, "doesn't apply to a '%.100s' object", descr_name(descr), "?", descr->d_type->tp_name, - obj->ob_type->tp_name); + Py_TYPE(obj)->tp_name); *pres = -1; return 1; } @@ -506,7 +506,7 @@ wrapperdescr_call(PyWrapperDescrObject *descr, PyObject *args, PyObject *kwds) "but received a '%.100s'", descr_name((PyDescrObject *)descr), "?", PyDescr_TYPE(descr)->tp_name, - self->ob_type->tp_name); + Py_TYPE(self)->tp_name); return NULL; } @@ -1234,7 +1234,7 @@ wrapper_repr(wrapperobject *wp) { return PyUnicode_FromFormat("<method-wrapper '%s' of %s object at %p>", wp->descr->d_base->name, - wp->self->ob_type->tp_name, + Py_TYPE(wp->self)->tp_name, wp->self); } @@ -1476,7 +1476,7 @@ property_dealloc(PyObject *self) Py_XDECREF(gs->prop_set); Py_XDECREF(gs->prop_del); Py_XDECREF(gs->prop_doc); - self->ob_type->tp_free(self); + Py_TYPE(self)->tp_free(self); } static PyObject * diff --git a/Objects/dictobject.c b/Objects/dictobject.c index ae6b50f..164104e 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -4015,7 +4015,7 @@ _PyDictView_New(PyObject *dict, PyTypeObject *type) /* XXX Get rid of this restriction later */ PyErr_Format(PyExc_TypeError, "%s() requires a dict argument, not '%s'", - type->tp_name, dict->ob_type->tp_name); + type->tp_name, Py_TYPE(dict)->tp_name); return NULL; } dv = PyObject_GC_New(_PyDictViewObject, type); diff --git a/Objects/floatobject.c b/Objects/floatobject.c index ab486d4..26e238c 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -256,7 +256,7 @@ PyFloat_AsDouble(PyObject *op) return val; } PyErr_Format(PyExc_TypeError, "must be real number, not %.50s", - op->ob_type->tp_name); + Py_TYPE(op)->tp_name); return -1; } @@ -268,7 +268,7 @@ PyFloat_AsDouble(PyObject *op) if (!PyFloat_Check(res)) { PyErr_Format(PyExc_TypeError, "%.50s.__float__ returned non-float (type %.50s)", - op->ob_type->tp_name, res->ob_type->tp_name); + Py_TYPE(op)->tp_name, Py_TYPE(res)->tp_name); Py_DECREF(res); return -1; } @@ -276,7 +276,7 @@ PyFloat_AsDouble(PyObject *op) "%.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.", - op->ob_type->tp_name, res->ob_type->tp_name)) { + Py_TYPE(op)->tp_name, Py_TYPE(res)->tp_name)) { Py_DECREF(res); return -1; } diff --git a/Objects/funcobject.c b/Objects/funcobject.c index b6ffc2a..ebe68ad 100644 --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -196,7 +196,7 @@ PyFunction_SetClosure(PyObject *op, PyObject *closure) else { PyErr_Format(PyExc_SystemError, "expected tuple for closure, got '%.100s'", - closure->ob_type->tp_name); + Py_TYPE(closure)->tp_name); return -1; } Py_XSETREF(((PyFunctionObject *)op)->func_closure, closure); @@ -541,7 +541,7 @@ func_new_impl(PyTypeObject *type, PyCodeObject *code, PyObject *globals, if (!PyCell_Check(o)) { return PyErr_Format(PyExc_TypeError, "arg 5 (closure) expected cell, found %s", - o->ob_type->tp_name); + Py_TYPE(o)->tp_name); } } } diff --git a/Objects/interpreteridobject.c b/Objects/interpreteridobject.c index 94f5dd7..57748e8 100644 --- a/Objects/interpreteridobject.c +++ b/Objects/interpreteridobject.c @@ -56,7 +56,7 @@ interp_id_converter(PyObject *arg, void *ptr) else { PyErr_Format(PyExc_TypeError, "interpreter ID must be an int, got %.100s", - arg->ob_type->tp_name); + Py_TYPE(arg)->tp_name); return 0; } *(int64_t *)ptr = id; diff --git a/Objects/listobject.c b/Objects/listobject.c index c93a0fe..d83e3cf 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -493,7 +493,7 @@ list_concat(PyListObject *a, PyObject *bb) if (!PyList_Check(bb)) { PyErr_Format(PyExc_TypeError, "can only concatenate list (not \"%.200s\") to list", - bb->ob_type->tp_name); + Py_TYPE(bb)->tp_name); return NULL; } #define b ((PyListObject *)bb) @@ -892,7 +892,7 @@ list_extend(PyListObject *self, PyObject *iterable) it = PyObject_GetIter(iterable); if (it == NULL) return NULL; - iternext = *it->ob_type->tp_iternext; + iternext = *Py_TYPE(it)->tp_iternext; /* Guess a result list size. */ n = PyObject_LengthHint(iterable, 8); @@ -1179,7 +1179,7 @@ struct s_MergeState { /* This function is used by unsafe_object_compare to optimize comparisons * when we know our list is type-homogeneous but we can't assume anything else. - * In the pre-sort check it is set equal to key->ob_type->tp_richcompare */ + * In the pre-sort check it is set equal to Py_TYPE(key)->tp_richcompare */ PyObject *(*key_richcompare)(PyObject *, PyObject *, int); /* This function is used by unsafe_tuple_compare to compare the first elements @@ -2015,7 +2015,7 @@ unsafe_object_compare(PyObject *v, PyObject *w, MergeState *ms) PyObject *res_obj; int res; /* No assumptions, because we check first: */ - if (v->ob_type->tp_richcompare != ms->key_richcompare) + if (Py_TYPE(v)->tp_richcompare != ms->key_richcompare) return PyObject_RichCompareBool(v, w, Py_LT); assert(ms->key_richcompare != NULL); @@ -2052,8 +2052,8 @@ unsafe_latin_compare(PyObject *v, PyObject *w, MergeState *ms) int res; /* Modified from Objects/unicodeobject.c:unicode_compare, assuming: */ - assert(v->ob_type == w->ob_type); - assert(v->ob_type == &PyUnicode_Type); + assert(Py_TYPE(v) == Py_TYPE(w)); + assert(Py_TYPE(v) == &PyUnicode_Type); assert(PyUnicode_KIND(v) == PyUnicode_KIND(w)); assert(PyUnicode_KIND(v) == PyUnicode_1BYTE_KIND); @@ -2075,8 +2075,8 @@ unsafe_long_compare(PyObject *v, PyObject *w, MergeState *ms) PyLongObject *vl, *wl; sdigit v0, w0; int res; /* Modified from Objects/longobject.c:long_compare, assuming: */ - assert(v->ob_type == w->ob_type); - assert(v->ob_type == &PyLong_Type); + assert(Py_TYPE(v) == Py_TYPE(w)); + assert(Py_TYPE(v) == &PyLong_Type); assert(Py_ABS(Py_SIZE(v)) <= 1); assert(Py_ABS(Py_SIZE(w)) <= 1); @@ -2103,8 +2103,8 @@ unsafe_float_compare(PyObject *v, PyObject *w, MergeState *ms) int res; /* Modified from Objects/floatobject.c:float_richcompare, assuming: */ - assert(v->ob_type == w->ob_type); - assert(v->ob_type == &PyFloat_Type); + assert(Py_TYPE(v) == Py_TYPE(w)); + assert(Py_TYPE(v) == &PyFloat_Type); res = PyFloat_AS_DOUBLE(v) < PyFloat_AS_DOUBLE(w); assert(res == PyObject_RichCompareBool(v, w, Py_LT)); @@ -2125,8 +2125,8 @@ unsafe_tuple_compare(PyObject *v, PyObject *w, MergeState *ms) int k; /* Modified from Objects/tupleobject.c:tuplerichcompare, assuming: */ - assert(v->ob_type == w->ob_type); - assert(v->ob_type == &PyTuple_Type); + assert(Py_TYPE(v) == Py_TYPE(w)); + assert(Py_TYPE(v) == &PyTuple_Type); assert(Py_SIZE(v) > 0); assert(Py_SIZE(w) > 0); @@ -2247,12 +2247,12 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse) * set ms appropriately. */ if (saved_ob_size > 1) { /* Assume the first element is representative of the whole list. */ - int keys_are_in_tuples = (lo.keys[0]->ob_type == &PyTuple_Type && + int keys_are_in_tuples = (Py_TYPE(lo.keys[0]) == &PyTuple_Type && Py_SIZE(lo.keys[0]) > 0); PyTypeObject* key_type = (keys_are_in_tuples ? - PyTuple_GET_ITEM(lo.keys[0], 0)->ob_type : - lo.keys[0]->ob_type); + Py_TYPE(PyTuple_GET_ITEM(lo.keys[0], 0)) : + Py_TYPE(lo.keys[0])); int keys_are_all_same_type = 1; int strings_are_latin = 1; @@ -2262,7 +2262,7 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse) for (i=0; i < saved_ob_size; i++) { if (keys_are_in_tuples && - !(lo.keys[i]->ob_type == &PyTuple_Type && Py_SIZE(lo.keys[i]) != 0)) { + !(Py_TYPE(lo.keys[i]) == &PyTuple_Type && Py_SIZE(lo.keys[i]) != 0)) { keys_are_in_tuples = 0; keys_are_all_same_type = 0; break; @@ -2275,7 +2275,7 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse) PyTuple_GET_ITEM(lo.keys[i], 0) : lo.keys[i]); - if (key->ob_type != key_type) { + if (Py_TYPE(key) != key_type) { keys_are_all_same_type = 0; /* If keys are in tuple we must loop over the whole list to make sure all items are tuples */ @@ -2818,7 +2818,7 @@ list_subscript(PyListObject* self, PyObject* item) else { PyErr_Format(PyExc_TypeError, "list indices must be integers or slices, not %.200s", - item->ob_type->tp_name); + Py_TYPE(item)->tp_name); return NULL; } } @@ -2981,7 +2981,7 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value) else { PyErr_Format(PyExc_TypeError, "list indices must be integers or slices, not %.200s", - item->ob_type->tp_name); + Py_TYPE(item)->tp_name); return -1; } } diff --git a/Objects/longobject.c b/Objects/longobject.c index 9115fa1..67cbc7b 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -150,7 +150,7 @@ _PyLong_FromNbInt(PyObject *integral) if (!PyLong_Check(result)) { PyErr_Format(PyExc_TypeError, "__int__ returned non-int (type %.200s)", - result->ob_type->tp_name); + Py_TYPE(result)->tp_name); Py_DECREF(result); return NULL; } @@ -159,7 +159,7 @@ _PyLong_FromNbInt(PyObject *integral) "__int__ 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; } @@ -203,7 +203,7 @@ _PyLong_FromNbIndexOrNbInt(PyObject *integral) 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; } @@ -212,7 +212,7 @@ _PyLong_FromNbIndexOrNbInt(PyObject *integral) "__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; diff --git a/Objects/methodobject.c b/Objects/methodobject.c index 6a37238..2a8111f 100644 --- a/Objects/methodobject.c +++ b/Objects/methodobject.c @@ -234,7 +234,7 @@ meth_repr(PyCFunctionObject *m) m->m_ml->ml_name); return PyUnicode_FromFormat("<built-in method %s of %s object at %p>", m->m_ml->ml_name, - m->m_self->ob_type->tp_name, + Py_TYPE(m->m_self)->tp_name, m->m_self); } diff --git a/Objects/namespaceobject.c b/Objects/namespaceobject.c index ddad39a..5c7163f 100644 --- a/Objects/namespaceobject.c +++ b/Objects/namespaceobject.c @@ -73,7 +73,7 @@ namespace_repr(PyObject *ns) const char * name; name = (Py_TYPE(ns) == &_PyNamespace_Type) ? "namespace" - : ns->ob_type->tp_name; + : Py_TYPE(ns)->tp_name; i = Py_ReprEnter(ns); if (i != 0) { diff --git a/Objects/object.c b/Objects/object.c index aca20e8..5806542 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -33,8 +33,8 @@ _PyObject_CheckConsistency(PyObject *op, int check_content) CHECK(!_PyObject_IsFreed(op)); CHECK(Py_REFCNT(op) >= 1); - CHECK(op->ob_type != NULL); - _PyType_CheckConsistency(op->ob_type); + CHECK(Py_TYPE(op) != NULL); + _PyType_CheckConsistency(Py_TYPE(op)); if (PyUnicode_Check(op)) { _PyUnicode_CheckConsistency(op, check_content); @@ -299,7 +299,7 @@ PyObject_Print(PyObject *op, FILE *fp, int flags) else { PyErr_Format(PyExc_TypeError, "str() or repr() returned '%.100s'", - s->ob_type->tp_name); + Py_TYPE(s)->tp_name); ret = -1; } Py_XDECREF(s); @@ -331,7 +331,7 @@ _Py_BreakPoint(void) int _PyObject_IsFreed(PyObject *op) { - if (_PyMem_IsPtrFreed(op) || _PyMem_IsPtrFreed(op->ob_type)) { + if (_PyMem_IsPtrFreed(op) || _PyMem_IsPtrFreed(Py_TYPE(op))) { return 1; } /* ignore op->ob_ref: its value can have be modified @@ -406,7 +406,7 @@ PyObject_Repr(PyObject *v) return PyUnicode_FromString("<NULL>"); if (Py_TYPE(v)->tp_repr == NULL) return PyUnicode_FromFormat("<%s object at %p>", - v->ob_type->tp_name, v); + Py_TYPE(v)->tp_name, v); PyThreadState *tstate = _PyThreadState_GET(); #ifdef Py_DEBUG @@ -422,7 +422,7 @@ PyObject_Repr(PyObject *v) " while getting the repr of an object")) { return NULL; } - res = (*v->ob_type->tp_repr)(v); + res = (*Py_TYPE(v)->tp_repr)(v); _Py_LeaveRecursiveCall(tstate); if (res == NULL) { @@ -431,7 +431,7 @@ PyObject_Repr(PyObject *v) if (!PyUnicode_Check(res)) { _PyErr_Format(tstate, PyExc_TypeError, "__repr__ returned non-string (type %.200s)", - res->ob_type->tp_name); + Py_TYPE(res)->tp_name); Py_DECREF(res); return NULL; } @@ -665,22 +665,22 @@ do_richcompare(PyThreadState *tstate, PyObject *v, PyObject *w, int op) PyObject *res; int checked_reverse_op = 0; - if (v->ob_type != w->ob_type && - PyType_IsSubtype(w->ob_type, v->ob_type) && - (f = w->ob_type->tp_richcompare) != NULL) { + if (Py_TYPE(v) != Py_TYPE(w) && + PyType_IsSubtype(Py_TYPE(w), Py_TYPE(v)) && + (f = Py_TYPE(w)->tp_richcompare) != NULL) { checked_reverse_op = 1; res = (*f)(w, v, _Py_SwappedOp[op]); if (res != Py_NotImplemented) return res; Py_DECREF(res); } - if ((f = v->ob_type->tp_richcompare) != NULL) { + if ((f = Py_TYPE(v)->tp_richcompare) != NULL) { res = (*f)(v, w, op); if (res != Py_NotImplemented) return res; Py_DECREF(res); } - if (!checked_reverse_op && (f = w->ob_type->tp_richcompare) != NULL) { + if (!checked_reverse_op && (f = Py_TYPE(w)->tp_richcompare) != NULL) { res = (*f)(w, v, _Py_SwappedOp[op]); if (res != Py_NotImplemented) return res; @@ -699,8 +699,8 @@ do_richcompare(PyThreadState *tstate, PyObject *v, PyObject *w, int op) _PyErr_Format(tstate, PyExc_TypeError, "'%s' not supported between instances of '%.100s' and '%.100s'", opstrings[op], - v->ob_type->tp_name, - w->ob_type->tp_name); + Py_TYPE(v)->tp_name, + Py_TYPE(w)->tp_name); return NULL; } Py_INCREF(res); @@ -888,7 +888,7 @@ PyObject_GetAttr(PyObject *v, PyObject *name) if (!PyUnicode_Check(name)) { PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", - name->ob_type->tp_name); + Py_TYPE(name)->tp_name); return NULL; } if (tp->tp_getattro != NULL) @@ -913,7 +913,7 @@ _PyObject_LookupAttr(PyObject *v, PyObject *name, PyObject **result) if (!PyUnicode_Check(name)) { PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", - name->ob_type->tp_name); + Py_TYPE(name)->tp_name); *result = NULL; return -1; } @@ -989,7 +989,7 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value) if (!PyUnicode_Check(name)) { PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", - name->ob_type->tp_name); + Py_TYPE(name)->tp_name); return -1; } Py_INCREF(name); @@ -1115,9 +1115,9 @@ _PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) if (PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_METHOD_DESCRIPTOR)) { meth_found = 1; } else { - f = descr->ob_type->tp_descr_get; + f = Py_TYPE(descr)->tp_descr_get; if (f != NULL && PyDescr_IsData(descr)) { - *method = f(descr, obj, (PyObject *)obj->ob_type); + *method = f(descr, obj, (PyObject *)Py_TYPE(obj)); Py_DECREF(descr); return 0; } @@ -1188,7 +1188,7 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name, if (!PyUnicode_Check(name)){ PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", - name->ob_type->tp_name); + Py_TYPE(name)->tp_name); return NULL; } Py_INCREF(name); @@ -1203,9 +1203,9 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name, f = NULL; if (descr != NULL) { Py_INCREF(descr); - f = descr->ob_type->tp_descr_get; + f = Py_TYPE(descr)->tp_descr_get; if (f != NULL && PyDescr_IsData(descr)) { - res = f(descr, obj, (PyObject *)obj->ob_type); + res = f(descr, obj, (PyObject *)Py_TYPE(obj)); if (res == NULL && suppress && PyErr_ExceptionMatches(PyExc_AttributeError)) { PyErr_Clear(); @@ -1302,7 +1302,7 @@ _PyObject_GenericSetAttrWithDict(PyObject *obj, PyObject *name, if (!PyUnicode_Check(name)){ PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", - name->ob_type->tp_name); + Py_TYPE(name)->tp_name); return -1; } @@ -1315,7 +1315,7 @@ _PyObject_GenericSetAttrWithDict(PyObject *obj, PyObject *name, if (descr != NULL) { Py_INCREF(descr); - f = descr->ob_type->tp_descr_set; + f = Py_TYPE(descr)->tp_descr_set; if (f != NULL) { res = f(descr, obj, value); goto done; @@ -1408,15 +1408,15 @@ PyObject_IsTrue(PyObject *v) return 0; if (v == Py_None) return 0; - else if (v->ob_type->tp_as_number != NULL && - v->ob_type->tp_as_number->nb_bool != NULL) - res = (*v->ob_type->tp_as_number->nb_bool)(v); - else if (v->ob_type->tp_as_mapping != NULL && - v->ob_type->tp_as_mapping->mp_length != NULL) - res = (*v->ob_type->tp_as_mapping->mp_length)(v); - else if (v->ob_type->tp_as_sequence != NULL && - v->ob_type->tp_as_sequence->sq_length != NULL) - res = (*v->ob_type->tp_as_sequence->sq_length)(v); + else if (Py_TYPE(v)->tp_as_number != NULL && + Py_TYPE(v)->tp_as_number->nb_bool != NULL) + res = (*Py_TYPE(v)->tp_as_number->nb_bool)(v); + else if (Py_TYPE(v)->tp_as_mapping != NULL && + Py_TYPE(v)->tp_as_mapping->mp_length != NULL) + res = (*Py_TYPE(v)->tp_as_mapping->mp_length)(v); + else if (Py_TYPE(v)->tp_as_sequence != NULL && + Py_TYPE(v)->tp_as_sequence->sq_length != NULL) + res = (*Py_TYPE(v)->tp_as_sequence->sq_length)(v); else return 1; /* if it is negative, it should be either -1 or -2 */ @@ -1443,7 +1443,7 @@ PyCallable_Check(PyObject *x) { if (x == NULL) return 0; - return x->ob_type->tp_call != NULL; + return Py_TYPE(x)->tp_call != NULL; } diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index e716820..343a80c 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -121,7 +121,7 @@ range_new(PyTypeObject *type, PyObject *args, PyObject *kw) "range expected at least 1 argument, got 0"); return NULL; default: - PyErr_Format(PyExc_TypeError, + PyErr_Format(PyExc_TypeError, "range expected at most 3 arguments, got %zd", num_args); return NULL; @@ -631,7 +631,7 @@ range_subscript(rangeobject* self, PyObject* item) } PyErr_Format(PyExc_TypeError, "range indices must be integers or slices, not %.200s", - item->ob_type->tp_name); + Py_TYPE(item)->tp_name); return NULL; } diff --git a/Objects/typeobject.c b/Objects/typeobject.c index d85ff3c..5b8d5a2 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -2345,7 +2345,7 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) assert(args != NULL && PyTuple_Check(args)); assert(kwds == NULL || PyDict_Check(kwds)); - /* Special case: type(x) should return x->ob_type */ + /* Special case: type(x) should return Py_TYPE(x) */ /* We only want type itself to accept the one-argument form (#27157) Note: We don't call PyType_CheckExact as that also allows subclasses */ if (metatype == &PyType_Type) { @@ -3230,7 +3230,7 @@ type_getattro(PyTypeObject *type, PyObject *name) if (!PyUnicode_Check(name)) { PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", - name->ob_type->tp_name); + Py_TYPE(name)->tp_name); return NULL; } @@ -3888,12 +3888,12 @@ object_richcompare(PyObject *self, PyObject *other, int op) case Py_NE: /* By default, __ne__() delegates to __eq__() and inverts the result, unless the latter returns NotImplemented. */ - if (self->ob_type->tp_richcompare == NULL) { + if (Py_TYPE(self)->tp_richcompare == NULL) { res = Py_NotImplemented; Py_INCREF(res); break; } - res = (*self->ob_type->tp_richcompare)(self, other, Py_EQ); + res = (*Py_TYPE(self)->tp_richcompare)(self, other, Py_EQ); if (res != NULL && res != Py_NotImplemented) { int ok = PyObject_IsTrue(res); Py_DECREF(res); @@ -4215,7 +4215,7 @@ _PyObject_GetState(PyObject *obj, int required) if (getstate == NULL) { PyObject *slotnames; - if (required && obj->ob_type->tp_itemsize) { + if (required && Py_TYPE(obj)->tp_itemsize) { PyErr_Format(PyExc_TypeError, "cannot pickle '%.200s' object", Py_TYPE(obj)->tp_name); @@ -4248,13 +4248,13 @@ _PyObject_GetState(PyObject *obj, int required) assert(slotnames == Py_None || PyList_Check(slotnames)); if (required) { Py_ssize_t basicsize = PyBaseObject_Type.tp_basicsize; - if (obj->ob_type->tp_dictoffset) + if (Py_TYPE(obj)->tp_dictoffset) basicsize += sizeof(PyObject *); - if (obj->ob_type->tp_weaklistoffset) + if (Py_TYPE(obj)->tp_weaklistoffset) basicsize += sizeof(PyObject *); if (slotnames != Py_None) basicsize += sizeof(PyObject *) * PyList_GET_SIZE(slotnames); - if (obj->ob_type->tp_basicsize > basicsize) { + if (Py_TYPE(obj)->tp_basicsize > basicsize) { Py_DECREF(slotnames); Py_DECREF(state); PyErr_Format(PyExc_TypeError, @@ -4725,7 +4725,7 @@ object___format___impl(PyObject *self, PyObject *format_spec) if (PyUnicode_GET_LENGTH(format_spec) > 0) { PyErr_Format(PyExc_TypeError, "unsupported format string passed to %.200s.__format__", - self->ob_type->tp_name); + Py_TYPE(self)->tp_name); return NULL; } return PyObject_Str(self); @@ -4744,10 +4744,10 @@ object___sizeof___impl(PyObject *self) Py_ssize_t res, isize; res = 0; - isize = self->ob_type->tp_itemsize; + isize = Py_TYPE(self)->tp_itemsize; if (isize > 0) res = Py_SIZE(self) * isize; - res += self->ob_type->tp_basicsize; + res += Py_TYPE(self)->tp_basicsize; return PyLong_FromSsize_t(res); } @@ -4794,7 +4794,7 @@ object___dir___impl(PyObject *self) if (_PyObject_LookupAttrId(self, &PyId___class__, &itsclass) < 0) { goto error; } - /* XXX(tomer): Perhaps fall back to obj->ob_type if no + /* XXX(tomer): Perhaps fall back to Py_TYPE(obj) if no __class__ exists? */ if (itsclass != NULL && merge_class_dict(dict, itsclass) < 0) goto error; @@ -7537,7 +7537,7 @@ set_names(PyTypeObject *type) _PyErr_FormatFromCause(PyExc_RuntimeError, "Error calling __set_name__ on '%.100s' instance %R " "in '%.100s'", - value->ob_type->tp_name, key, type->tp_name); + Py_TYPE(value)->tp_name, key, type->tp_name); Py_DECREF(names_to_set); return -1; } diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index fa48ee1..fd08ddb 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -8401,7 +8401,7 @@ charmapencode_lookup(Py_UCS4 c, PyObject *mapping) /* wrong return value */ PyErr_Format(PyExc_TypeError, "character mapping must return integer, bytes or None, not %.400s", - x->ob_type->tp_name); + Py_TYPE(x)->tp_name); Py_DECREF(x); return NULL; } @@ -11082,8 +11082,8 @@ PyUnicode_Compare(PyObject *left, PyObject *right) } PyErr_Format(PyExc_TypeError, "Can't compare %.100s and %.100s", - left->ob_type->tp_name, - right->ob_type->tp_name); + Py_TYPE(left)->tp_name, + Py_TYPE(right)->tp_name); return -1; } @@ -11353,7 +11353,7 @@ PyUnicode_Concat(PyObject *left, PyObject *right) if (!PyUnicode_Check(right)) { PyErr_Format(PyExc_TypeError, "can only concatenate str (not \"%.200s\") to str", - right->ob_type->tp_name); + Py_TYPE(right)->tp_name); return NULL; } if (PyUnicode_READY(right) < 0) |