mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-39573: Use Py_TYPE() macro in Objects directory (GH-18392)
Replace direct access to PyObject.ob_type with Py_TYPE().
This commit is contained in:
parent
a102ed7d2f
commit
58ac700fb0
20 changed files with 109 additions and 109 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue