Skip to content

bpo-39573: Use Py_TYPE() macro in Objects directory #18392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Objects/bytearrayobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion Objects/bytesobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions Objects/call.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion Objects/cellobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
12 changes: 6 additions & 6 deletions Objects/classobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

{
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Objects/codeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions Objects/complexobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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, "
Expand All @@ -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, "
Expand Down
14 changes: 7 additions & 7 deletions Objects/descrobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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,
Expand All @@ -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))) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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 *
Expand Down
2 changes: 1 addition & 1 deletion Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions Objects/floatobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -268,15 +268,15 @@ 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;
}
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
"%.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;
}
Expand Down
4 changes: 2 additions & 2 deletions Objects/funcobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Objects/interpreteridobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
38 changes: 19 additions & 19 deletions Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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));
Expand All @@ -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);

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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 */
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
Loading