mirror of https://github.com/python/cpython
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
|
@ -856,7 +856,7 @@ bytearray_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds)
|
||||||
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
|
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"cannot convert '%.200s' object to bytearray",
|
"cannot convert '%.200s' object to bytearray",
|
||||||
arg->ob_type->tp_name);
|
Py_TYPE(arg)->tp_name);
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1630,7 +1630,7 @@ bytearray_extend(PyByteArrayObject *self, PyObject *iterable_of_ints)
|
||||||
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
|
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"can't extend bytearray with %.100s",
|
"can't extend bytearray with %.100s",
|
||||||
iterable_of_ints->ob_type->tp_name);
|
Py_TYPE(iterable_of_ints)->tp_name);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2762,7 +2762,7 @@ PyBytes_FromObject(PyObject *x)
|
||||||
|
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"cannot convert '%.200s' object to bytes",
|
"cannot convert '%.200s' object to bytes",
|
||||||
x->ob_type->tp_name);
|
Py_TYPE(x)->tp_name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -263,11 +263,11 @@ _PyObject_Call(PyThreadState *tstate, PyObject *callable,
|
||||||
return PyVectorcall_Call(callable, args, kwargs);
|
return PyVectorcall_Call(callable, args, kwargs);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
call = callable->ob_type->tp_call;
|
call = Py_TYPE(callable)->tp_call;
|
||||||
if (call == NULL) {
|
if (call == NULL) {
|
||||||
_PyErr_Format(tstate, PyExc_TypeError,
|
_PyErr_Format(tstate, PyExc_TypeError,
|
||||||
"'%.200s' object is not callable",
|
"'%.200s' object is not callable",
|
||||||
callable->ob_type->tp_name);
|
Py_TYPE(callable)->tp_name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@ cell_repr(PyCellObject *op)
|
||||||
return PyUnicode_FromFormat("<cell at %p: empty>", op);
|
return PyUnicode_FromFormat("<cell at %p: empty>", op);
|
||||||
|
|
||||||
return PyUnicode_FromFormat("<cell at %p: %.80s object at %p>",
|
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);
|
op->ob_ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -178,7 +178,7 @@ static PyObject *
|
||||||
method_getattro(PyObject *obj, PyObject *name)
|
method_getattro(PyObject *obj, PyObject *name)
|
||||||
{
|
{
|
||||||
PyMethodObject *im = (PyMethodObject *)obj;
|
PyMethodObject *im = (PyMethodObject *)obj;
|
||||||
PyTypeObject *tp = obj->ob_type;
|
PyTypeObject *tp = Py_TYPE(obj);
|
||||||
PyObject *descr = NULL;
|
PyObject *descr = NULL;
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -190,9 +190,9 @@ method_getattro(PyObject *obj, PyObject *name)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (descr != NULL) {
|
if (descr != NULL) {
|
||||||
descrgetfunc f = TP_DESCR_GET(descr->ob_type);
|
descrgetfunc f = TP_DESCR_GET(Py_TYPE(descr));
|
||||||
if (f != NULL)
|
if (f != NULL)
|
||||||
return f(descr, obj, (PyObject *)obj->ob_type);
|
return f(descr, obj, (PyObject *)Py_TYPE(obj));
|
||||||
else {
|
else {
|
||||||
Py_INCREF(descr);
|
Py_INCREF(descr);
|
||||||
return descr;
|
return descr;
|
||||||
|
@ -425,7 +425,7 @@ static PyGetSetDef instancemethod_getset[] = {
|
||||||
static PyObject *
|
static PyObject *
|
||||||
instancemethod_getattro(PyObject *self, PyObject *name)
|
instancemethod_getattro(PyObject *self, PyObject *name)
|
||||||
{
|
{
|
||||||
PyTypeObject *tp = self->ob_type;
|
PyTypeObject *tp = Py_TYPE(self);
|
||||||
PyObject *descr = NULL;
|
PyObject *descr = NULL;
|
||||||
|
|
||||||
if (tp->tp_dict == NULL) {
|
if (tp->tp_dict == NULL) {
|
||||||
|
@ -435,9 +435,9 @@ instancemethod_getattro(PyObject *self, PyObject *name)
|
||||||
descr = _PyType_Lookup(tp, name);
|
descr = _PyType_Lookup(tp, name);
|
||||||
|
|
||||||
if (descr != NULL) {
|
if (descr != NULL) {
|
||||||
descrgetfunc f = TP_DESCR_GET(descr->ob_type);
|
descrgetfunc f = TP_DESCR_GET(Py_TYPE(descr));
|
||||||
if (f != NULL)
|
if (f != NULL)
|
||||||
return f(descr, self, (PyObject *)self->ob_type);
|
return f(descr, self, (PyObject *)Py_TYPE(self));
|
||||||
else {
|
else {
|
||||||
Py_INCREF(descr);
|
Py_INCREF(descr);
|
||||||
return descr;
|
return descr;
|
||||||
|
|
|
@ -416,7 +416,7 @@ validate_and_copy_tuple(PyObject *tup)
|
||||||
PyExc_TypeError,
|
PyExc_TypeError,
|
||||||
"name tuples must contain only "
|
"name tuples must contain only "
|
||||||
"strings, not '%.500s'",
|
"strings, not '%.500s'",
|
||||||
item->ob_type->tp_name);
|
Py_TYPE(item)->tp_name);
|
||||||
Py_DECREF(newtuple);
|
Py_DECREF(newtuple);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -296,7 +296,7 @@ try_complex_special_method(PyObject *op)
|
||||||
if (!PyComplex_Check(res)) {
|
if (!PyComplex_Check(res)) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"__complex__ returned non-complex (type %.200s)",
|
"__complex__ returned non-complex (type %.200s)",
|
||||||
res->ob_type->tp_name);
|
Py_TYPE(res)->tp_name);
|
||||||
Py_DECREF(res);
|
Py_DECREF(res);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -305,7 +305,7 @@ try_complex_special_method(PyObject *op)
|
||||||
"__complex__ returned non-complex (type %.200s). "
|
"__complex__ returned non-complex (type %.200s). "
|
||||||
"The ability to return an instance of a strict subclass of complex "
|
"The ability to return an instance of a strict subclass of complex "
|
||||||
"is deprecated, and may be removed in a future version of Python.",
|
"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);
|
Py_DECREF(res);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -958,7 +958,7 @@ complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i)
|
||||||
return NULL;
|
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)) {
|
if (nbr == NULL || (nbr->nb_float == NULL && nbr->nb_index == NULL)) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"complex() first argument must be a string or a number, "
|
"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;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (i != 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)) {
|
if (nbi == NULL || (nbi->nb_float == NULL && nbi->nb_index == NULL)) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"complex() second argument must be a number, "
|
"complex() second argument must be a number, "
|
||||||
|
|
|
@ -84,7 +84,7 @@ descr_check(PyDescrObject *descr, PyObject *obj, PyObject **pres)
|
||||||
"doesn't apply to a '%.100s' object",
|
"doesn't apply to a '%.100s' object",
|
||||||
descr_name((PyDescrObject *)descr), "?",
|
descr_name((PyDescrObject *)descr), "?",
|
||||||
descr->d_type->tp_name,
|
descr->d_type->tp_name,
|
||||||
obj->ob_type->tp_name);
|
Py_TYPE(obj)->tp_name);
|
||||||
*pres = NULL;
|
*pres = NULL;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ classmethod_get(PyMethodDescrObject *descr, PyObject *obj, PyObject *type)
|
||||||
/* Ensure a valid type. Class methods ignore obj. */
|
/* Ensure a valid type. Class methods ignore obj. */
|
||||||
if (type == NULL) {
|
if (type == NULL) {
|
||||||
if (obj != NULL)
|
if (obj != NULL)
|
||||||
type = (PyObject *)obj->ob_type;
|
type = (PyObject *)Py_TYPE(obj);
|
||||||
else {
|
else {
|
||||||
/* Wot - no type?! */
|
/* Wot - no type?! */
|
||||||
PyErr_Format(PyExc_TypeError,
|
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",
|
"needs a type, not a '%.100s' as arg 2",
|
||||||
descr_name((PyDescrObject *)descr), "?",
|
descr_name((PyDescrObject *)descr), "?",
|
||||||
PyDescr_TYPE(descr)->tp_name,
|
PyDescr_TYPE(descr)->tp_name,
|
||||||
type->ob_type->tp_name);
|
Py_TYPE(type)->tp_name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (!PyType_IsSubtype((PyTypeObject *)type, PyDescr_TYPE(descr))) {
|
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",
|
"doesn't apply to a '%.100s' object",
|
||||||
descr_name(descr), "?",
|
descr_name(descr), "?",
|
||||||
descr->d_type->tp_name,
|
descr->d_type->tp_name,
|
||||||
obj->ob_type->tp_name);
|
Py_TYPE(obj)->tp_name);
|
||||||
*pres = -1;
|
*pres = -1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -506,7 +506,7 @@ wrapperdescr_call(PyWrapperDescrObject *descr, PyObject *args, PyObject *kwds)
|
||||||
"but received a '%.100s'",
|
"but received a '%.100s'",
|
||||||
descr_name((PyDescrObject *)descr), "?",
|
descr_name((PyDescrObject *)descr), "?",
|
||||||
PyDescr_TYPE(descr)->tp_name,
|
PyDescr_TYPE(descr)->tp_name,
|
||||||
self->ob_type->tp_name);
|
Py_TYPE(self)->tp_name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1234,7 +1234,7 @@ wrapper_repr(wrapperobject *wp)
|
||||||
{
|
{
|
||||||
return PyUnicode_FromFormat("<method-wrapper '%s' of %s object at %p>",
|
return PyUnicode_FromFormat("<method-wrapper '%s' of %s object at %p>",
|
||||||
wp->descr->d_base->name,
|
wp->descr->d_base->name,
|
||||||
wp->self->ob_type->tp_name,
|
Py_TYPE(wp->self)->tp_name,
|
||||||
wp->self);
|
wp->self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1476,7 +1476,7 @@ property_dealloc(PyObject *self)
|
||||||
Py_XDECREF(gs->prop_set);
|
Py_XDECREF(gs->prop_set);
|
||||||
Py_XDECREF(gs->prop_del);
|
Py_XDECREF(gs->prop_del);
|
||||||
Py_XDECREF(gs->prop_doc);
|
Py_XDECREF(gs->prop_doc);
|
||||||
self->ob_type->tp_free(self);
|
Py_TYPE(self)->tp_free(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
|
@ -4015,7 +4015,7 @@ _PyDictView_New(PyObject *dict, PyTypeObject *type)
|
||||||
/* XXX Get rid of this restriction later */
|
/* XXX Get rid of this restriction later */
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"%s() requires a dict argument, not '%s'",
|
"%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;
|
return NULL;
|
||||||
}
|
}
|
||||||
dv = PyObject_GC_New(_PyDictViewObject, type);
|
dv = PyObject_GC_New(_PyDictViewObject, type);
|
||||||
|
|
|
@ -256,7 +256,7 @@ PyFloat_AsDouble(PyObject *op)
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
PyErr_Format(PyExc_TypeError, "must be real number, not %.50s",
|
PyErr_Format(PyExc_TypeError, "must be real number, not %.50s",
|
||||||
op->ob_type->tp_name);
|
Py_TYPE(op)->tp_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,7 +268,7 @@ PyFloat_AsDouble(PyObject *op)
|
||||||
if (!PyFloat_Check(res)) {
|
if (!PyFloat_Check(res)) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"%.50s.__float__ returned non-float (type %.50s)",
|
"%.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);
|
Py_DECREF(res);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -276,7 +276,7 @@ PyFloat_AsDouble(PyObject *op)
|
||||||
"%.50s.__float__ returned non-float (type %.50s). "
|
"%.50s.__float__ returned non-float (type %.50s). "
|
||||||
"The ability to return an instance of a strict subclass of float "
|
"The ability to return an instance of a strict subclass of float "
|
||||||
"is deprecated, and may be removed in a future version of Python.",
|
"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);
|
Py_DECREF(res);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -196,7 +196,7 @@ PyFunction_SetClosure(PyObject *op, PyObject *closure)
|
||||||
else {
|
else {
|
||||||
PyErr_Format(PyExc_SystemError,
|
PyErr_Format(PyExc_SystemError,
|
||||||
"expected tuple for closure, got '%.100s'",
|
"expected tuple for closure, got '%.100s'",
|
||||||
closure->ob_type->tp_name);
|
Py_TYPE(closure)->tp_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
Py_XSETREF(((PyFunctionObject *)op)->func_closure, closure);
|
Py_XSETREF(((PyFunctionObject *)op)->func_closure, closure);
|
||||||
|
@ -541,7 +541,7 @@ func_new_impl(PyTypeObject *type, PyCodeObject *code, PyObject *globals,
|
||||||
if (!PyCell_Check(o)) {
|
if (!PyCell_Check(o)) {
|
||||||
return PyErr_Format(PyExc_TypeError,
|
return PyErr_Format(PyExc_TypeError,
|
||||||
"arg 5 (closure) expected cell, found %s",
|
"arg 5 (closure) expected cell, found %s",
|
||||||
o->ob_type->tp_name);
|
Py_TYPE(o)->tp_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ interp_id_converter(PyObject *arg, void *ptr)
|
||||||
else {
|
else {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"interpreter ID must be an int, got %.100s",
|
"interpreter ID must be an int, got %.100s",
|
||||||
arg->ob_type->tp_name);
|
Py_TYPE(arg)->tp_name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
*(int64_t *)ptr = id;
|
*(int64_t *)ptr = id;
|
||||||
|
|
|
@ -493,7 +493,7 @@ list_concat(PyListObject *a, PyObject *bb)
|
||||||
if (!PyList_Check(bb)) {
|
if (!PyList_Check(bb)) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"can only concatenate list (not \"%.200s\") to list",
|
"can only concatenate list (not \"%.200s\") to list",
|
||||||
bb->ob_type->tp_name);
|
Py_TYPE(bb)->tp_name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#define b ((PyListObject *)bb)
|
#define b ((PyListObject *)bb)
|
||||||
|
@ -892,7 +892,7 @@ list_extend(PyListObject *self, PyObject *iterable)
|
||||||
it = PyObject_GetIter(iterable);
|
it = PyObject_GetIter(iterable);
|
||||||
if (it == NULL)
|
if (it == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
iternext = *it->ob_type->tp_iternext;
|
iternext = *Py_TYPE(it)->tp_iternext;
|
||||||
|
|
||||||
/* Guess a result list size. */
|
/* Guess a result list size. */
|
||||||
n = PyObject_LengthHint(iterable, 8);
|
n = PyObject_LengthHint(iterable, 8);
|
||||||
|
@ -1179,7 +1179,7 @@ struct s_MergeState {
|
||||||
|
|
||||||
/* This function is used by unsafe_object_compare to optimize comparisons
|
/* 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.
|
* 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);
|
PyObject *(*key_richcompare)(PyObject *, PyObject *, int);
|
||||||
|
|
||||||
/* This function is used by unsafe_tuple_compare to compare the first elements
|
/* 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;
|
PyObject *res_obj; int res;
|
||||||
|
|
||||||
/* No assumptions, because we check first: */
|
/* 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);
|
return PyObject_RichCompareBool(v, w, Py_LT);
|
||||||
|
|
||||||
assert(ms->key_richcompare != NULL);
|
assert(ms->key_richcompare != NULL);
|
||||||
|
@ -2052,8 +2052,8 @@ unsafe_latin_compare(PyObject *v, PyObject *w, MergeState *ms)
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
/* Modified from Objects/unicodeobject.c:unicode_compare, assuming: */
|
/* Modified from Objects/unicodeobject.c:unicode_compare, assuming: */
|
||||||
assert(v->ob_type == w->ob_type);
|
assert(Py_TYPE(v) == Py_TYPE(w));
|
||||||
assert(v->ob_type == &PyUnicode_Type);
|
assert(Py_TYPE(v) == &PyUnicode_Type);
|
||||||
assert(PyUnicode_KIND(v) == PyUnicode_KIND(w));
|
assert(PyUnicode_KIND(v) == PyUnicode_KIND(w));
|
||||||
assert(PyUnicode_KIND(v) == PyUnicode_1BYTE_KIND);
|
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;
|
PyLongObject *vl, *wl; sdigit v0, w0; int res;
|
||||||
|
|
||||||
/* Modified from Objects/longobject.c:long_compare, assuming: */
|
/* Modified from Objects/longobject.c:long_compare, assuming: */
|
||||||
assert(v->ob_type == w->ob_type);
|
assert(Py_TYPE(v) == Py_TYPE(w));
|
||||||
assert(v->ob_type == &PyLong_Type);
|
assert(Py_TYPE(v) == &PyLong_Type);
|
||||||
assert(Py_ABS(Py_SIZE(v)) <= 1);
|
assert(Py_ABS(Py_SIZE(v)) <= 1);
|
||||||
assert(Py_ABS(Py_SIZE(w)) <= 1);
|
assert(Py_ABS(Py_SIZE(w)) <= 1);
|
||||||
|
|
||||||
|
@ -2103,8 +2103,8 @@ unsafe_float_compare(PyObject *v, PyObject *w, MergeState *ms)
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
/* Modified from Objects/floatobject.c:float_richcompare, assuming: */
|
/* Modified from Objects/floatobject.c:float_richcompare, assuming: */
|
||||||
assert(v->ob_type == w->ob_type);
|
assert(Py_TYPE(v) == Py_TYPE(w));
|
||||||
assert(v->ob_type == &PyFloat_Type);
|
assert(Py_TYPE(v) == &PyFloat_Type);
|
||||||
|
|
||||||
res = PyFloat_AS_DOUBLE(v) < PyFloat_AS_DOUBLE(w);
|
res = PyFloat_AS_DOUBLE(v) < PyFloat_AS_DOUBLE(w);
|
||||||
assert(res == PyObject_RichCompareBool(v, w, Py_LT));
|
assert(res == PyObject_RichCompareBool(v, w, Py_LT));
|
||||||
|
@ -2125,8 +2125,8 @@ unsafe_tuple_compare(PyObject *v, PyObject *w, MergeState *ms)
|
||||||
int k;
|
int k;
|
||||||
|
|
||||||
/* Modified from Objects/tupleobject.c:tuplerichcompare, assuming: */
|
/* Modified from Objects/tupleobject.c:tuplerichcompare, assuming: */
|
||||||
assert(v->ob_type == w->ob_type);
|
assert(Py_TYPE(v) == Py_TYPE(w));
|
||||||
assert(v->ob_type == &PyTuple_Type);
|
assert(Py_TYPE(v) == &PyTuple_Type);
|
||||||
assert(Py_SIZE(v) > 0);
|
assert(Py_SIZE(v) > 0);
|
||||||
assert(Py_SIZE(w) > 0);
|
assert(Py_SIZE(w) > 0);
|
||||||
|
|
||||||
|
@ -2247,12 +2247,12 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse)
|
||||||
* set ms appropriately. */
|
* set ms appropriately. */
|
||||||
if (saved_ob_size > 1) {
|
if (saved_ob_size > 1) {
|
||||||
/* Assume the first element is representative of the whole list. */
|
/* 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);
|
Py_SIZE(lo.keys[0]) > 0);
|
||||||
|
|
||||||
PyTypeObject* key_type = (keys_are_in_tuples ?
|
PyTypeObject* key_type = (keys_are_in_tuples ?
|
||||||
PyTuple_GET_ITEM(lo.keys[0], 0)->ob_type :
|
Py_TYPE(PyTuple_GET_ITEM(lo.keys[0], 0)) :
|
||||||
lo.keys[0]->ob_type);
|
Py_TYPE(lo.keys[0]));
|
||||||
|
|
||||||
int keys_are_all_same_type = 1;
|
int keys_are_all_same_type = 1;
|
||||||
int strings_are_latin = 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++) {
|
for (i=0; i < saved_ob_size; i++) {
|
||||||
|
|
||||||
if (keys_are_in_tuples &&
|
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_in_tuples = 0;
|
||||||
keys_are_all_same_type = 0;
|
keys_are_all_same_type = 0;
|
||||||
break;
|
break;
|
||||||
|
@ -2275,7 +2275,7 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse)
|
||||||
PyTuple_GET_ITEM(lo.keys[i], 0) :
|
PyTuple_GET_ITEM(lo.keys[i], 0) :
|
||||||
lo.keys[i]);
|
lo.keys[i]);
|
||||||
|
|
||||||
if (key->ob_type != key_type) {
|
if (Py_TYPE(key) != key_type) {
|
||||||
keys_are_all_same_type = 0;
|
keys_are_all_same_type = 0;
|
||||||
/* If keys are in tuple we must loop over the whole list to make
|
/* If keys are in tuple we must loop over the whole list to make
|
||||||
sure all items are tuples */
|
sure all items are tuples */
|
||||||
|
@ -2818,7 +2818,7 @@ list_subscript(PyListObject* self, PyObject* item)
|
||||||
else {
|
else {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"list indices must be integers or slices, not %.200s",
|
"list indices must be integers or slices, not %.200s",
|
||||||
item->ob_type->tp_name);
|
Py_TYPE(item)->tp_name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2981,7 +2981,7 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
|
||||||
else {
|
else {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"list indices must be integers or slices, not %.200s",
|
"list indices must be integers or slices, not %.200s",
|
||||||
item->ob_type->tp_name);
|
Py_TYPE(item)->tp_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,7 +150,7 @@ _PyLong_FromNbInt(PyObject *integral)
|
||||||
if (!PyLong_Check(result)) {
|
if (!PyLong_Check(result)) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"__int__ returned non-int (type %.200s)",
|
"__int__ returned non-int (type %.200s)",
|
||||||
result->ob_type->tp_name);
|
Py_TYPE(result)->tp_name);
|
||||||
Py_DECREF(result);
|
Py_DECREF(result);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -159,7 +159,7 @@ _PyLong_FromNbInt(PyObject *integral)
|
||||||
"__int__ returned non-int (type %.200s). "
|
"__int__ returned non-int (type %.200s). "
|
||||||
"The ability to return an instance of a strict subclass of int "
|
"The ability to return an instance of a strict subclass of int "
|
||||||
"is deprecated, and may be removed in a future version of Python.",
|
"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);
|
Py_DECREF(result);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -203,7 +203,7 @@ _PyLong_FromNbIndexOrNbInt(PyObject *integral)
|
||||||
if (!PyLong_Check(result)) {
|
if (!PyLong_Check(result)) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"__index__ returned non-int (type %.200s)",
|
"__index__ returned non-int (type %.200s)",
|
||||||
result->ob_type->tp_name);
|
Py_TYPE(result)->tp_name);
|
||||||
Py_DECREF(result);
|
Py_DECREF(result);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -212,7 +212,7 @@ _PyLong_FromNbIndexOrNbInt(PyObject *integral)
|
||||||
"__index__ returned non-int (type %.200s). "
|
"__index__ returned non-int (type %.200s). "
|
||||||
"The ability to return an instance of a strict subclass of int "
|
"The ability to return an instance of a strict subclass of int "
|
||||||
"is deprecated, and may be removed in a future version of Python.",
|
"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);
|
Py_DECREF(result);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -234,7 +234,7 @@ meth_repr(PyCFunctionObject *m)
|
||||||
m->m_ml->ml_name);
|
m->m_ml->ml_name);
|
||||||
return PyUnicode_FromFormat("<built-in method %s of %s object at %p>",
|
return PyUnicode_FromFormat("<built-in method %s of %s object at %p>",
|
||||||
m->m_ml->ml_name,
|
m->m_ml->ml_name,
|
||||||
m->m_self->ob_type->tp_name,
|
Py_TYPE(m->m_self)->tp_name,
|
||||||
m->m_self);
|
m->m_self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ namespace_repr(PyObject *ns)
|
||||||
const char * name;
|
const char * name;
|
||||||
|
|
||||||
name = (Py_TYPE(ns) == &_PyNamespace_Type) ? "namespace"
|
name = (Py_TYPE(ns) == &_PyNamespace_Type) ? "namespace"
|
||||||
: ns->ob_type->tp_name;
|
: Py_TYPE(ns)->tp_name;
|
||||||
|
|
||||||
i = Py_ReprEnter(ns);
|
i = Py_ReprEnter(ns);
|
||||||
if (i != 0) {
|
if (i != 0) {
|
||||||
|
|
|
@ -33,8 +33,8 @@ _PyObject_CheckConsistency(PyObject *op, int check_content)
|
||||||
CHECK(!_PyObject_IsFreed(op));
|
CHECK(!_PyObject_IsFreed(op));
|
||||||
CHECK(Py_REFCNT(op) >= 1);
|
CHECK(Py_REFCNT(op) >= 1);
|
||||||
|
|
||||||
CHECK(op->ob_type != NULL);
|
CHECK(Py_TYPE(op) != NULL);
|
||||||
_PyType_CheckConsistency(op->ob_type);
|
_PyType_CheckConsistency(Py_TYPE(op));
|
||||||
|
|
||||||
if (PyUnicode_Check(op)) {
|
if (PyUnicode_Check(op)) {
|
||||||
_PyUnicode_CheckConsistency(op, check_content);
|
_PyUnicode_CheckConsistency(op, check_content);
|
||||||
|
@ -299,7 +299,7 @@ PyObject_Print(PyObject *op, FILE *fp, int flags)
|
||||||
else {
|
else {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"str() or repr() returned '%.100s'",
|
"str() or repr() returned '%.100s'",
|
||||||
s->ob_type->tp_name);
|
Py_TYPE(s)->tp_name);
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
Py_XDECREF(s);
|
Py_XDECREF(s);
|
||||||
|
@ -331,7 +331,7 @@ _Py_BreakPoint(void)
|
||||||
int
|
int
|
||||||
_PyObject_IsFreed(PyObject *op)
|
_PyObject_IsFreed(PyObject *op)
|
||||||
{
|
{
|
||||||
if (_PyMem_IsPtrFreed(op) || _PyMem_IsPtrFreed(op->ob_type)) {
|
if (_PyMem_IsPtrFreed(op) || _PyMem_IsPtrFreed(Py_TYPE(op))) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/* ignore op->ob_ref: its value can have be modified
|
/* ignore op->ob_ref: its value can have be modified
|
||||||
|
@ -406,7 +406,7 @@ PyObject_Repr(PyObject *v)
|
||||||
return PyUnicode_FromString("<NULL>");
|
return PyUnicode_FromString("<NULL>");
|
||||||
if (Py_TYPE(v)->tp_repr == NULL)
|
if (Py_TYPE(v)->tp_repr == NULL)
|
||||||
return PyUnicode_FromFormat("<%s object at %p>",
|
return PyUnicode_FromFormat("<%s object at %p>",
|
||||||
v->ob_type->tp_name, v);
|
Py_TYPE(v)->tp_name, v);
|
||||||
|
|
||||||
PyThreadState *tstate = _PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
#ifdef Py_DEBUG
|
#ifdef Py_DEBUG
|
||||||
|
@ -422,7 +422,7 @@ PyObject_Repr(PyObject *v)
|
||||||
" while getting the repr of an object")) {
|
" while getting the repr of an object")) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
res = (*v->ob_type->tp_repr)(v);
|
res = (*Py_TYPE(v)->tp_repr)(v);
|
||||||
_Py_LeaveRecursiveCall(tstate);
|
_Py_LeaveRecursiveCall(tstate);
|
||||||
|
|
||||||
if (res == NULL) {
|
if (res == NULL) {
|
||||||
|
@ -431,7 +431,7 @@ PyObject_Repr(PyObject *v)
|
||||||
if (!PyUnicode_Check(res)) {
|
if (!PyUnicode_Check(res)) {
|
||||||
_PyErr_Format(tstate, PyExc_TypeError,
|
_PyErr_Format(tstate, PyExc_TypeError,
|
||||||
"__repr__ returned non-string (type %.200s)",
|
"__repr__ returned non-string (type %.200s)",
|
||||||
res->ob_type->tp_name);
|
Py_TYPE(res)->tp_name);
|
||||||
Py_DECREF(res);
|
Py_DECREF(res);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -665,22 +665,22 @@ do_richcompare(PyThreadState *tstate, PyObject *v, PyObject *w, int op)
|
||||||
PyObject *res;
|
PyObject *res;
|
||||||
int checked_reverse_op = 0;
|
int checked_reverse_op = 0;
|
||||||
|
|
||||||
if (v->ob_type != w->ob_type &&
|
if (Py_TYPE(v) != Py_TYPE(w) &&
|
||||||
PyType_IsSubtype(w->ob_type, v->ob_type) &&
|
PyType_IsSubtype(Py_TYPE(w), Py_TYPE(v)) &&
|
||||||
(f = w->ob_type->tp_richcompare) != NULL) {
|
(f = Py_TYPE(w)->tp_richcompare) != NULL) {
|
||||||
checked_reverse_op = 1;
|
checked_reverse_op = 1;
|
||||||
res = (*f)(w, v, _Py_SwappedOp[op]);
|
res = (*f)(w, v, _Py_SwappedOp[op]);
|
||||||
if (res != Py_NotImplemented)
|
if (res != Py_NotImplemented)
|
||||||
return res;
|
return res;
|
||||||
Py_DECREF(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);
|
res = (*f)(v, w, op);
|
||||||
if (res != Py_NotImplemented)
|
if (res != Py_NotImplemented)
|
||||||
return res;
|
return res;
|
||||||
Py_DECREF(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]);
|
res = (*f)(w, v, _Py_SwappedOp[op]);
|
||||||
if (res != Py_NotImplemented)
|
if (res != Py_NotImplemented)
|
||||||
return res;
|
return res;
|
||||||
|
@ -699,8 +699,8 @@ do_richcompare(PyThreadState *tstate, PyObject *v, PyObject *w, int op)
|
||||||
_PyErr_Format(tstate, PyExc_TypeError,
|
_PyErr_Format(tstate, PyExc_TypeError,
|
||||||
"'%s' not supported between instances of '%.100s' and '%.100s'",
|
"'%s' not supported between instances of '%.100s' and '%.100s'",
|
||||||
opstrings[op],
|
opstrings[op],
|
||||||
v->ob_type->tp_name,
|
Py_TYPE(v)->tp_name,
|
||||||
w->ob_type->tp_name);
|
Py_TYPE(w)->tp_name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
Py_INCREF(res);
|
Py_INCREF(res);
|
||||||
|
@ -888,7 +888,7 @@ PyObject_GetAttr(PyObject *v, PyObject *name)
|
||||||
if (!PyUnicode_Check(name)) {
|
if (!PyUnicode_Check(name)) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"attribute name must be string, not '%.200s'",
|
"attribute name must be string, not '%.200s'",
|
||||||
name->ob_type->tp_name);
|
Py_TYPE(name)->tp_name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (tp->tp_getattro != NULL)
|
if (tp->tp_getattro != NULL)
|
||||||
|
@ -913,7 +913,7 @@ _PyObject_LookupAttr(PyObject *v, PyObject *name, PyObject **result)
|
||||||
if (!PyUnicode_Check(name)) {
|
if (!PyUnicode_Check(name)) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"attribute name must be string, not '%.200s'",
|
"attribute name must be string, not '%.200s'",
|
||||||
name->ob_type->tp_name);
|
Py_TYPE(name)->tp_name);
|
||||||
*result = NULL;
|
*result = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -989,7 +989,7 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
|
||||||
if (!PyUnicode_Check(name)) {
|
if (!PyUnicode_Check(name)) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"attribute name must be string, not '%.200s'",
|
"attribute name must be string, not '%.200s'",
|
||||||
name->ob_type->tp_name);
|
Py_TYPE(name)->tp_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
Py_INCREF(name);
|
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)) {
|
if (PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_METHOD_DESCRIPTOR)) {
|
||||||
meth_found = 1;
|
meth_found = 1;
|
||||||
} else {
|
} else {
|
||||||
f = descr->ob_type->tp_descr_get;
|
f = Py_TYPE(descr)->tp_descr_get;
|
||||||
if (f != NULL && PyDescr_IsData(descr)) {
|
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);
|
Py_DECREF(descr);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1188,7 +1188,7 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name,
|
||||||
if (!PyUnicode_Check(name)){
|
if (!PyUnicode_Check(name)){
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"attribute name must be string, not '%.200s'",
|
"attribute name must be string, not '%.200s'",
|
||||||
name->ob_type->tp_name);
|
Py_TYPE(name)->tp_name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
Py_INCREF(name);
|
Py_INCREF(name);
|
||||||
|
@ -1203,9 +1203,9 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name,
|
||||||
f = NULL;
|
f = NULL;
|
||||||
if (descr != NULL) {
|
if (descr != NULL) {
|
||||||
Py_INCREF(descr);
|
Py_INCREF(descr);
|
||||||
f = descr->ob_type->tp_descr_get;
|
f = Py_TYPE(descr)->tp_descr_get;
|
||||||
if (f != NULL && PyDescr_IsData(descr)) {
|
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 &&
|
if (res == NULL && suppress &&
|
||||||
PyErr_ExceptionMatches(PyExc_AttributeError)) {
|
PyErr_ExceptionMatches(PyExc_AttributeError)) {
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
|
@ -1302,7 +1302,7 @@ _PyObject_GenericSetAttrWithDict(PyObject *obj, PyObject *name,
|
||||||
if (!PyUnicode_Check(name)){
|
if (!PyUnicode_Check(name)){
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"attribute name must be string, not '%.200s'",
|
"attribute name must be string, not '%.200s'",
|
||||||
name->ob_type->tp_name);
|
Py_TYPE(name)->tp_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1315,7 +1315,7 @@ _PyObject_GenericSetAttrWithDict(PyObject *obj, PyObject *name,
|
||||||
|
|
||||||
if (descr != NULL) {
|
if (descr != NULL) {
|
||||||
Py_INCREF(descr);
|
Py_INCREF(descr);
|
||||||
f = descr->ob_type->tp_descr_set;
|
f = Py_TYPE(descr)->tp_descr_set;
|
||||||
if (f != NULL) {
|
if (f != NULL) {
|
||||||
res = f(descr, obj, value);
|
res = f(descr, obj, value);
|
||||||
goto done;
|
goto done;
|
||||||
|
@ -1408,15 +1408,15 @@ PyObject_IsTrue(PyObject *v)
|
||||||
return 0;
|
return 0;
|
||||||
if (v == Py_None)
|
if (v == Py_None)
|
||||||
return 0;
|
return 0;
|
||||||
else if (v->ob_type->tp_as_number != NULL &&
|
else if (Py_TYPE(v)->tp_as_number != NULL &&
|
||||||
v->ob_type->tp_as_number->nb_bool != NULL)
|
Py_TYPE(v)->tp_as_number->nb_bool != NULL)
|
||||||
res = (*v->ob_type->tp_as_number->nb_bool)(v);
|
res = (*Py_TYPE(v)->tp_as_number->nb_bool)(v);
|
||||||
else if (v->ob_type->tp_as_mapping != NULL &&
|
else if (Py_TYPE(v)->tp_as_mapping != NULL &&
|
||||||
v->ob_type->tp_as_mapping->mp_length != NULL)
|
Py_TYPE(v)->tp_as_mapping->mp_length != NULL)
|
||||||
res = (*v->ob_type->tp_as_mapping->mp_length)(v);
|
res = (*Py_TYPE(v)->tp_as_mapping->mp_length)(v);
|
||||||
else if (v->ob_type->tp_as_sequence != NULL &&
|
else if (Py_TYPE(v)->tp_as_sequence != NULL &&
|
||||||
v->ob_type->tp_as_sequence->sq_length != NULL)
|
Py_TYPE(v)->tp_as_sequence->sq_length != NULL)
|
||||||
res = (*v->ob_type->tp_as_sequence->sq_length)(v);
|
res = (*Py_TYPE(v)->tp_as_sequence->sq_length)(v);
|
||||||
else
|
else
|
||||||
return 1;
|
return 1;
|
||||||
/* if it is negative, it should be either -1 or -2 */
|
/* if it is negative, it should be either -1 or -2 */
|
||||||
|
@ -1443,7 +1443,7 @@ PyCallable_Check(PyObject *x)
|
||||||
{
|
{
|
||||||
if (x == NULL)
|
if (x == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
return x->ob_type->tp_call != NULL;
|
return Py_TYPE(x)->tp_call != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -631,7 +631,7 @@ range_subscript(rangeobject* self, PyObject* item)
|
||||||
}
|
}
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"range indices must be integers or slices, not %.200s",
|
"range indices must be integers or slices, not %.200s",
|
||||||
item->ob_type->tp_name);
|
Py_TYPE(item)->tp_name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2345,7 +2345,7 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
|
||||||
assert(args != NULL && PyTuple_Check(args));
|
assert(args != NULL && PyTuple_Check(args));
|
||||||
assert(kwds == NULL || PyDict_Check(kwds));
|
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)
|
/* We only want type itself to accept the one-argument form (#27157)
|
||||||
Note: We don't call PyType_CheckExact as that also allows subclasses */
|
Note: We don't call PyType_CheckExact as that also allows subclasses */
|
||||||
if (metatype == &PyType_Type) {
|
if (metatype == &PyType_Type) {
|
||||||
|
@ -3230,7 +3230,7 @@ type_getattro(PyTypeObject *type, PyObject *name)
|
||||||
if (!PyUnicode_Check(name)) {
|
if (!PyUnicode_Check(name)) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"attribute name must be string, not '%.200s'",
|
"attribute name must be string, not '%.200s'",
|
||||||
name->ob_type->tp_name);
|
Py_TYPE(name)->tp_name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3888,12 +3888,12 @@ object_richcompare(PyObject *self, PyObject *other, int op)
|
||||||
case Py_NE:
|
case Py_NE:
|
||||||
/* By default, __ne__() delegates to __eq__() and inverts the result,
|
/* By default, __ne__() delegates to __eq__() and inverts the result,
|
||||||
unless the latter returns NotImplemented. */
|
unless the latter returns NotImplemented. */
|
||||||
if (self->ob_type->tp_richcompare == NULL) {
|
if (Py_TYPE(self)->tp_richcompare == NULL) {
|
||||||
res = Py_NotImplemented;
|
res = Py_NotImplemented;
|
||||||
Py_INCREF(res);
|
Py_INCREF(res);
|
||||||
break;
|
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) {
|
if (res != NULL && res != Py_NotImplemented) {
|
||||||
int ok = PyObject_IsTrue(res);
|
int ok = PyObject_IsTrue(res);
|
||||||
Py_DECREF(res);
|
Py_DECREF(res);
|
||||||
|
@ -4215,7 +4215,7 @@ _PyObject_GetState(PyObject *obj, int required)
|
||||||
if (getstate == NULL) {
|
if (getstate == NULL) {
|
||||||
PyObject *slotnames;
|
PyObject *slotnames;
|
||||||
|
|
||||||
if (required && obj->ob_type->tp_itemsize) {
|
if (required && Py_TYPE(obj)->tp_itemsize) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"cannot pickle '%.200s' object",
|
"cannot pickle '%.200s' object",
|
||||||
Py_TYPE(obj)->tp_name);
|
Py_TYPE(obj)->tp_name);
|
||||||
|
@ -4248,13 +4248,13 @@ _PyObject_GetState(PyObject *obj, int required)
|
||||||
assert(slotnames == Py_None || PyList_Check(slotnames));
|
assert(slotnames == Py_None || PyList_Check(slotnames));
|
||||||
if (required) {
|
if (required) {
|
||||||
Py_ssize_t basicsize = PyBaseObject_Type.tp_basicsize;
|
Py_ssize_t basicsize = PyBaseObject_Type.tp_basicsize;
|
||||||
if (obj->ob_type->tp_dictoffset)
|
if (Py_TYPE(obj)->tp_dictoffset)
|
||||||
basicsize += sizeof(PyObject *);
|
basicsize += sizeof(PyObject *);
|
||||||
if (obj->ob_type->tp_weaklistoffset)
|
if (Py_TYPE(obj)->tp_weaklistoffset)
|
||||||
basicsize += sizeof(PyObject *);
|
basicsize += sizeof(PyObject *);
|
||||||
if (slotnames != Py_None)
|
if (slotnames != Py_None)
|
||||||
basicsize += sizeof(PyObject *) * PyList_GET_SIZE(slotnames);
|
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(slotnames);
|
||||||
Py_DECREF(state);
|
Py_DECREF(state);
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
|
@ -4725,7 +4725,7 @@ object___format___impl(PyObject *self, PyObject *format_spec)
|
||||||
if (PyUnicode_GET_LENGTH(format_spec) > 0) {
|
if (PyUnicode_GET_LENGTH(format_spec) > 0) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"unsupported format string passed to %.200s.__format__",
|
"unsupported format string passed to %.200s.__format__",
|
||||||
self->ob_type->tp_name);
|
Py_TYPE(self)->tp_name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return PyObject_Str(self);
|
return PyObject_Str(self);
|
||||||
|
@ -4744,10 +4744,10 @@ object___sizeof___impl(PyObject *self)
|
||||||
Py_ssize_t res, isize;
|
Py_ssize_t res, isize;
|
||||||
|
|
||||||
res = 0;
|
res = 0;
|
||||||
isize = self->ob_type->tp_itemsize;
|
isize = Py_TYPE(self)->tp_itemsize;
|
||||||
if (isize > 0)
|
if (isize > 0)
|
||||||
res = Py_SIZE(self) * isize;
|
res = Py_SIZE(self) * isize;
|
||||||
res += self->ob_type->tp_basicsize;
|
res += Py_TYPE(self)->tp_basicsize;
|
||||||
|
|
||||||
return PyLong_FromSsize_t(res);
|
return PyLong_FromSsize_t(res);
|
||||||
}
|
}
|
||||||
|
@ -4794,7 +4794,7 @@ object___dir___impl(PyObject *self)
|
||||||
if (_PyObject_LookupAttrId(self, &PyId___class__, &itsclass) < 0) {
|
if (_PyObject_LookupAttrId(self, &PyId___class__, &itsclass) < 0) {
|
||||||
goto error;
|
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? */
|
__class__ exists? */
|
||||||
if (itsclass != NULL && merge_class_dict(dict, itsclass) < 0)
|
if (itsclass != NULL && merge_class_dict(dict, itsclass) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -7537,7 +7537,7 @@ set_names(PyTypeObject *type)
|
||||||
_PyErr_FormatFromCause(PyExc_RuntimeError,
|
_PyErr_FormatFromCause(PyExc_RuntimeError,
|
||||||
"Error calling __set_name__ on '%.100s' instance %R "
|
"Error calling __set_name__ on '%.100s' instance %R "
|
||||||
"in '%.100s'",
|
"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);
|
Py_DECREF(names_to_set);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8401,7 +8401,7 @@ charmapencode_lookup(Py_UCS4 c, PyObject *mapping)
|
||||||
/* wrong return value */
|
/* wrong return value */
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"character mapping must return integer, bytes or None, not %.400s",
|
"character mapping must return integer, bytes or None, not %.400s",
|
||||||
x->ob_type->tp_name);
|
Py_TYPE(x)->tp_name);
|
||||||
Py_DECREF(x);
|
Py_DECREF(x);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -11082,8 +11082,8 @@ PyUnicode_Compare(PyObject *left, PyObject *right)
|
||||||
}
|
}
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"Can't compare %.100s and %.100s",
|
"Can't compare %.100s and %.100s",
|
||||||
left->ob_type->tp_name,
|
Py_TYPE(left)->tp_name,
|
||||||
right->ob_type->tp_name);
|
Py_TYPE(right)->tp_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11353,7 +11353,7 @@ PyUnicode_Concat(PyObject *left, PyObject *right)
|
||||||
if (!PyUnicode_Check(right)) {
|
if (!PyUnicode_Check(right)) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"can only concatenate str (not \"%.200s\") to str",
|
"can only concatenate str (not \"%.200s\") to str",
|
||||||
right->ob_type->tp_name);
|
Py_TYPE(right)->tp_name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (PyUnicode_READY(right) < 0)
|
if (PyUnicode_READY(right) < 0)
|
||||||
|
|
Loading…
Reference in New Issue