Skip to content

Commit 58ac700

Browse files
authored
bpo-39573: Use Py_TYPE() macro in Objects directory (GH-18392)
Replace direct access to PyObject.ob_type with Py_TYPE().
1 parent a102ed7 commit 58ac700

20 files changed

+109
-109
lines changed

Objects/bytearrayobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ bytearray_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds)
856856
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
857857
PyErr_Format(PyExc_TypeError,
858858
"cannot convert '%.200s' object to bytearray",
859-
arg->ob_type->tp_name);
859+
Py_TYPE(arg)->tp_name);
860860
}
861861
return -1;
862862
}
@@ -1630,7 +1630,7 @@ bytearray_extend(PyByteArrayObject *self, PyObject *iterable_of_ints)
16301630
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
16311631
PyErr_Format(PyExc_TypeError,
16321632
"can't extend bytearray with %.100s",
1633-
iterable_of_ints->ob_type->tp_name);
1633+
Py_TYPE(iterable_of_ints)->tp_name);
16341634
}
16351635
return NULL;
16361636
}

Objects/bytesobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2762,7 +2762,7 @@ PyBytes_FromObject(PyObject *x)
27622762

27632763
PyErr_Format(PyExc_TypeError,
27642764
"cannot convert '%.200s' object to bytes",
2765-
x->ob_type->tp_name);
2765+
Py_TYPE(x)->tp_name);
27662766
return NULL;
27672767
}
27682768

Objects/call.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,11 @@ _PyObject_Call(PyThreadState *tstate, PyObject *callable,
263263
return PyVectorcall_Call(callable, args, kwargs);
264264
}
265265
else {
266-
call = callable->ob_type->tp_call;
266+
call = Py_TYPE(callable)->tp_call;
267267
if (call == NULL) {
268268
_PyErr_Format(tstate, PyExc_TypeError,
269269
"'%.200s' object is not callable",
270-
callable->ob_type->tp_name);
270+
Py_TYPE(callable)->tp_name);
271271
return NULL;
272272
}
273273

Objects/cellobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ cell_repr(PyCellObject *op)
112112
return PyUnicode_FromFormat("<cell at %p: empty>", op);
113113

114114
return PyUnicode_FromFormat("<cell at %p: %.80s object at %p>",
115-
op, op->ob_ref->ob_type->tp_name,
115+
op, Py_TYPE(op->ob_ref)->tp_name,
116116
op->ob_ref);
117117
}
118118

Objects/classobject.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static PyObject *
178178
method_getattro(PyObject *obj, PyObject *name)
179179
{
180180
PyMethodObject *im = (PyMethodObject *)obj;
181-
PyTypeObject *tp = obj->ob_type;
181+
PyTypeObject *tp = Py_TYPE(obj);
182182
PyObject *descr = NULL;
183183

184184
{
@@ -190,9 +190,9 @@ method_getattro(PyObject *obj, PyObject *name)
190190
}
191191

192192
if (descr != NULL) {
193-
descrgetfunc f = TP_DESCR_GET(descr->ob_type);
193+
descrgetfunc f = TP_DESCR_GET(Py_TYPE(descr));
194194
if (f != NULL)
195-
return f(descr, obj, (PyObject *)obj->ob_type);
195+
return f(descr, obj, (PyObject *)Py_TYPE(obj));
196196
else {
197197
Py_INCREF(descr);
198198
return descr;
@@ -425,7 +425,7 @@ static PyGetSetDef instancemethod_getset[] = {
425425
static PyObject *
426426
instancemethod_getattro(PyObject *self, PyObject *name)
427427
{
428-
PyTypeObject *tp = self->ob_type;
428+
PyTypeObject *tp = Py_TYPE(self);
429429
PyObject *descr = NULL;
430430

431431
if (tp->tp_dict == NULL) {
@@ -435,9 +435,9 @@ instancemethod_getattro(PyObject *self, PyObject *name)
435435
descr = _PyType_Lookup(tp, name);
436436

437437
if (descr != NULL) {
438-
descrgetfunc f = TP_DESCR_GET(descr->ob_type);
438+
descrgetfunc f = TP_DESCR_GET(Py_TYPE(descr));
439439
if (f != NULL)
440-
return f(descr, self, (PyObject *)self->ob_type);
440+
return f(descr, self, (PyObject *)Py_TYPE(self));
441441
else {
442442
Py_INCREF(descr);
443443
return descr;

Objects/codeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ validate_and_copy_tuple(PyObject *tup)
416416
PyExc_TypeError,
417417
"name tuples must contain only "
418418
"strings, not '%.500s'",
419-
item->ob_type->tp_name);
419+
Py_TYPE(item)->tp_name);
420420
Py_DECREF(newtuple);
421421
return NULL;
422422
}

Objects/complexobject.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ try_complex_special_method(PyObject *op)
296296
if (!PyComplex_Check(res)) {
297297
PyErr_Format(PyExc_TypeError,
298298
"__complex__ returned non-complex (type %.200s)",
299-
res->ob_type->tp_name);
299+
Py_TYPE(res)->tp_name);
300300
Py_DECREF(res);
301301
return NULL;
302302
}
@@ -305,7 +305,7 @@ try_complex_special_method(PyObject *op)
305305
"__complex__ returned non-complex (type %.200s). "
306306
"The ability to return an instance of a strict subclass of complex "
307307
"is deprecated, and may be removed in a future version of Python.",
308-
res->ob_type->tp_name)) {
308+
Py_TYPE(res)->tp_name)) {
309309
Py_DECREF(res);
310310
return NULL;
311311
}
@@ -958,7 +958,7 @@ complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i)
958958
return NULL;
959959
}
960960

961-
nbr = r->ob_type->tp_as_number;
961+
nbr = Py_TYPE(r)->tp_as_number;
962962
if (nbr == NULL || (nbr->nb_float == NULL && nbr->nb_index == NULL)) {
963963
PyErr_Format(PyExc_TypeError,
964964
"complex() first argument must be a string or a number, "
@@ -970,7 +970,7 @@ complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i)
970970
return NULL;
971971
}
972972
if (i != NULL) {
973-
nbi = i->ob_type->tp_as_number;
973+
nbi = Py_TYPE(i)->tp_as_number;
974974
if (nbi == NULL || (nbi->nb_float == NULL && nbi->nb_index == NULL)) {
975975
PyErr_Format(PyExc_TypeError,
976976
"complex() second argument must be a number, "

Objects/descrobject.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ descr_check(PyDescrObject *descr, PyObject *obj, PyObject **pres)
8484
"doesn't apply to a '%.100s' object",
8585
descr_name((PyDescrObject *)descr), "?",
8686
descr->d_type->tp_name,
87-
obj->ob_type->tp_name);
87+
Py_TYPE(obj)->tp_name);
8888
*pres = NULL;
8989
return 1;
9090
}
@@ -97,7 +97,7 @@ classmethod_get(PyMethodDescrObject *descr, PyObject *obj, PyObject *type)
9797
/* Ensure a valid type. Class methods ignore obj. */
9898
if (type == NULL) {
9999
if (obj != NULL)
100-
type = (PyObject *)obj->ob_type;
100+
type = (PyObject *)Py_TYPE(obj);
101101
else {
102102
/* Wot - no type?! */
103103
PyErr_Format(PyExc_TypeError,
@@ -114,7 +114,7 @@ classmethod_get(PyMethodDescrObject *descr, PyObject *obj, PyObject *type)
114114
"needs a type, not a '%.100s' as arg 2",
115115
descr_name((PyDescrObject *)descr), "?",
116116
PyDescr_TYPE(descr)->tp_name,
117-
type->ob_type->tp_name);
117+
Py_TYPE(type)->tp_name);
118118
return NULL;
119119
}
120120
if (!PyType_IsSubtype((PyTypeObject *)type, PyDescr_TYPE(descr))) {
@@ -194,7 +194,7 @@ descr_setcheck(PyDescrObject *descr, PyObject *obj, PyObject *value,
194194
"doesn't apply to a '%.100s' object",
195195
descr_name(descr), "?",
196196
descr->d_type->tp_name,
197-
obj->ob_type->tp_name);
197+
Py_TYPE(obj)->tp_name);
198198
*pres = -1;
199199
return 1;
200200
}
@@ -506,7 +506,7 @@ wrapperdescr_call(PyWrapperDescrObject *descr, PyObject *args, PyObject *kwds)
506506
"but received a '%.100s'",
507507
descr_name((PyDescrObject *)descr), "?",
508508
PyDescr_TYPE(descr)->tp_name,
509-
self->ob_type->tp_name);
509+
Py_TYPE(self)->tp_name);
510510
return NULL;
511511
}
512512

@@ -1234,7 +1234,7 @@ wrapper_repr(wrapperobject *wp)
12341234
{
12351235
return PyUnicode_FromFormat("<method-wrapper '%s' of %s object at %p>",
12361236
wp->descr->d_base->name,
1237-
wp->self->ob_type->tp_name,
1237+
Py_TYPE(wp->self)->tp_name,
12381238
wp->self);
12391239
}
12401240

@@ -1476,7 +1476,7 @@ property_dealloc(PyObject *self)
14761476
Py_XDECREF(gs->prop_set);
14771477
Py_XDECREF(gs->prop_del);
14781478
Py_XDECREF(gs->prop_doc);
1479-
self->ob_type->tp_free(self);
1479+
Py_TYPE(self)->tp_free(self);
14801480
}
14811481

14821482
static PyObject *

Objects/dictobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4015,7 +4015,7 @@ _PyDictView_New(PyObject *dict, PyTypeObject *type)
40154015
/* XXX Get rid of this restriction later */
40164016
PyErr_Format(PyExc_TypeError,
40174017
"%s() requires a dict argument, not '%s'",
4018-
type->tp_name, dict->ob_type->tp_name);
4018+
type->tp_name, Py_TYPE(dict)->tp_name);
40194019
return NULL;
40204020
}
40214021
dv = PyObject_GC_New(_PyDictViewObject, type);

Objects/floatobject.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ PyFloat_AsDouble(PyObject *op)
256256
return val;
257257
}
258258
PyErr_Format(PyExc_TypeError, "must be real number, not %.50s",
259-
op->ob_type->tp_name);
259+
Py_TYPE(op)->tp_name);
260260
return -1;
261261
}
262262

@@ -268,15 +268,15 @@ PyFloat_AsDouble(PyObject *op)
268268
if (!PyFloat_Check(res)) {
269269
PyErr_Format(PyExc_TypeError,
270270
"%.50s.__float__ returned non-float (type %.50s)",
271-
op->ob_type->tp_name, res->ob_type->tp_name);
271+
Py_TYPE(op)->tp_name, Py_TYPE(res)->tp_name);
272272
Py_DECREF(res);
273273
return -1;
274274
}
275275
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
276276
"%.50s.__float__ returned non-float (type %.50s). "
277277
"The ability to return an instance of a strict subclass of float "
278278
"is deprecated, and may be removed in a future version of Python.",
279-
op->ob_type->tp_name, res->ob_type->tp_name)) {
279+
Py_TYPE(op)->tp_name, Py_TYPE(res)->tp_name)) {
280280
Py_DECREF(res);
281281
return -1;
282282
}

0 commit comments

Comments
 (0)