mirror of
https://github.com/python/cpython.git
synced 2025-09-14 12:46:49 +00:00
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
This commit is contained in:
parent
d586559c31
commit
e93237dfcc
108 changed files with 916 additions and 908 deletions
|
@ -57,7 +57,7 @@ type_set_name(PyTypeObject *type, PyObject *value, void *context)
|
|||
if (!PyString_Check(value)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"can only assign string to %s.__name__, not '%s'",
|
||||
type->tp_name, Py_Type(value)->tp_name);
|
||||
type->tp_name, Py_TYPE(value)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
if (strlen(PyString_AS_STRING(value))
|
||||
|
@ -203,7 +203,7 @@ type_set_bases(PyTypeObject *type, PyObject *value, void *context)
|
|||
if (!PyTuple_Check(value)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"can only assign tuple to %s.__bases__, not %s",
|
||||
type->tp_name, Py_Type(value)->tp_name);
|
||||
type->tp_name, Py_TYPE(value)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
if (PyTuple_GET_SIZE(value) == 0) {
|
||||
|
@ -218,7 +218,7 @@ type_set_bases(PyTypeObject *type, PyObject *value, void *context)
|
|||
PyErr_Format(
|
||||
PyExc_TypeError,
|
||||
"%s.__bases__ must be tuple of old- or new-style classes, not '%s'",
|
||||
type->tp_name, Py_Type(ob)->tp_name);
|
||||
type->tp_name, Py_TYPE(ob)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
if (PyType_Check(ob)) {
|
||||
|
@ -343,8 +343,8 @@ type_get_doc(PyTypeObject *type, void *context)
|
|||
result = Py_None;
|
||||
Py_INCREF(result);
|
||||
}
|
||||
else if (Py_Type(result)->tp_descr_get) {
|
||||
result = Py_Type(result)->tp_descr_get(result, NULL,
|
||||
else if (Py_TYPE(result)->tp_descr_get) {
|
||||
result = Py_TYPE(result)->tp_descr_get(result, NULL,
|
||||
(PyObject *)type);
|
||||
}
|
||||
else {
|
||||
|
@ -488,7 +488,7 @@ traverse_slots(PyTypeObject *type, PyObject *self, visitproc visit, void *arg)
|
|||
Py_ssize_t i, n;
|
||||
PyMemberDef *mp;
|
||||
|
||||
n = Py_Size(type);
|
||||
n = Py_SIZE(type);
|
||||
mp = PyHeapType_GET_MEMBERS((PyHeapTypeObject *)type);
|
||||
for (i = 0; i < n; i++, mp++) {
|
||||
if (mp->type == T_OBJECT_EX) {
|
||||
|
@ -512,10 +512,10 @@ subtype_traverse(PyObject *self, visitproc visit, void *arg)
|
|||
|
||||
/* Find the nearest base with a different tp_traverse,
|
||||
and traverse slots while we're at it */
|
||||
type = Py_Type(self);
|
||||
type = Py_TYPE(self);
|
||||
base = type;
|
||||
while ((basetraverse = base->tp_traverse) == subtype_traverse) {
|
||||
if (Py_Size(base)) {
|
||||
if (Py_SIZE(base)) {
|
||||
int err = traverse_slots(base, self, visit, arg);
|
||||
if (err)
|
||||
return err;
|
||||
|
@ -547,7 +547,7 @@ clear_slots(PyTypeObject *type, PyObject *self)
|
|||
Py_ssize_t i, n;
|
||||
PyMemberDef *mp;
|
||||
|
||||
n = Py_Size(type);
|
||||
n = Py_SIZE(type);
|
||||
mp = PyHeapType_GET_MEMBERS((PyHeapTypeObject *)type);
|
||||
for (i = 0; i < n; i++, mp++) {
|
||||
if (mp->type == T_OBJECT_EX && !(mp->flags & READONLY)) {
|
||||
|
@ -569,10 +569,10 @@ subtype_clear(PyObject *self)
|
|||
|
||||
/* Find the nearest base with a different tp_clear
|
||||
and clear slots while we're at it */
|
||||
type = Py_Type(self);
|
||||
type = Py_TYPE(self);
|
||||
base = type;
|
||||
while ((baseclear = base->tp_clear) == subtype_clear) {
|
||||
if (Py_Size(base))
|
||||
if (Py_SIZE(base))
|
||||
clear_slots(base, self);
|
||||
base = base->tp_base;
|
||||
assert(base);
|
||||
|
@ -593,7 +593,7 @@ subtype_dealloc(PyObject *self)
|
|||
destructor basedealloc;
|
||||
|
||||
/* Extract the type; we expect it to be a heap type */
|
||||
type = Py_Type(self);
|
||||
type = Py_TYPE(self);
|
||||
assert(type->tp_flags & Py_TPFLAGS_HEAPTYPE);
|
||||
|
||||
/* Test whether the type has GC exactly once */
|
||||
|
@ -615,7 +615,7 @@ subtype_dealloc(PyObject *self)
|
|||
/* Find the nearest base with a different tp_dealloc */
|
||||
base = type;
|
||||
while ((basedealloc = base->tp_dealloc) == subtype_dealloc) {
|
||||
assert(Py_Size(base) == 0);
|
||||
assert(Py_SIZE(base) == 0);
|
||||
base = base->tp_base;
|
||||
assert(base);
|
||||
}
|
||||
|
@ -683,7 +683,7 @@ subtype_dealloc(PyObject *self)
|
|||
/* Clear slots up to the nearest base with a different tp_dealloc */
|
||||
base = type;
|
||||
while ((basedealloc = base->tp_dealloc) == subtype_dealloc) {
|
||||
if (Py_Size(base))
|
||||
if (Py_SIZE(base))
|
||||
clear_slots(base, self);
|
||||
base = base->tp_base;
|
||||
assert(base);
|
||||
|
@ -877,13 +877,13 @@ lookup_maybe(PyObject *self, char *attrstr, PyObject **attrobj)
|
|||
if (*attrobj == NULL)
|
||||
return NULL;
|
||||
}
|
||||
res = _PyType_Lookup(Py_Type(self), *attrobj);
|
||||
res = _PyType_Lookup(Py_TYPE(self), *attrobj);
|
||||
if (res != NULL) {
|
||||
descrgetfunc f;
|
||||
if ((f = Py_Type(res)->tp_descr_get) == NULL)
|
||||
if ((f = Py_TYPE(res)->tp_descr_get) == NULL)
|
||||
Py_INCREF(res);
|
||||
else
|
||||
res = f(res, self, (PyObject *)(Py_Type(self)));
|
||||
res = f(res, self, (PyObject *)(Py_TYPE(self)));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -1301,7 +1301,7 @@ mro_internal(PyTypeObject *type)
|
|||
PyObject *mro, *result, *tuple;
|
||||
int checkit = 0;
|
||||
|
||||
if (Py_Type(type) == &PyType_Type) {
|
||||
if (Py_TYPE(type) == &PyType_Type) {
|
||||
result = mro_implementation(type);
|
||||
}
|
||||
else {
|
||||
|
@ -1336,7 +1336,7 @@ mro_internal(PyTypeObject *type)
|
|||
else if (!PyType_Check(cls)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"mro() returned a non-class ('%.500s')",
|
||||
Py_Type(cls)->tp_name);
|
||||
Py_TYPE(cls)->tp_name);
|
||||
Py_DECREF(tuple);
|
||||
return -1;
|
||||
}
|
||||
|
@ -1565,7 +1565,7 @@ subtype_setdict(PyObject *obj, PyObject *value, void *context)
|
|||
if (value != NULL && !PyDict_Check(value)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"__dict__ must be set to a dictionary, "
|
||||
"not a '%.200s'", Py_Type(value)->tp_name);
|
||||
"not a '%.200s'", Py_TYPE(value)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
dict = *dictptr;
|
||||
|
@ -1581,16 +1581,16 @@ subtype_getweakref(PyObject *obj, void *context)
|
|||
PyObject **weaklistptr;
|
||||
PyObject *result;
|
||||
|
||||
if (Py_Type(obj)->tp_weaklistoffset == 0) {
|
||||
if (Py_TYPE(obj)->tp_weaklistoffset == 0) {
|
||||
PyErr_SetString(PyExc_AttributeError,
|
||||
"This object has no __weakref__");
|
||||
return NULL;
|
||||
}
|
||||
assert(Py_Type(obj)->tp_weaklistoffset > 0);
|
||||
assert(Py_Type(obj)->tp_weaklistoffset + sizeof(PyObject *) <=
|
||||
(size_t)(Py_Type(obj)->tp_basicsize));
|
||||
assert(Py_TYPE(obj)->tp_weaklistoffset > 0);
|
||||
assert(Py_TYPE(obj)->tp_weaklistoffset + sizeof(PyObject *) <=
|
||||
(size_t)(Py_TYPE(obj)->tp_basicsize));
|
||||
weaklistptr = (PyObject **)
|
||||
((char *)obj + Py_Type(obj)->tp_weaklistoffset);
|
||||
((char *)obj + Py_TYPE(obj)->tp_weaklistoffset);
|
||||
if (*weaklistptr == NULL)
|
||||
result = Py_None;
|
||||
else
|
||||
|
@ -1630,7 +1630,7 @@ valid_identifier(PyObject *s)
|
|||
if (!PyString_Check(s)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"__slots__ items must be strings, not '%.200s'",
|
||||
Py_Type(s)->tp_name);
|
||||
Py_TYPE(s)->tp_name);
|
||||
return 0;
|
||||
}
|
||||
p = (unsigned char *) PyString_AS_STRING(s);
|
||||
|
@ -1740,8 +1740,8 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
|
|||
|
||||
if (PyType_CheckExact(metatype) && nargs == 1 && nkwds == 0) {
|
||||
PyObject *x = PyTuple_GET_ITEM(args, 0);
|
||||
Py_INCREF(Py_Type(x));
|
||||
return (PyObject *) Py_Type(x);
|
||||
Py_INCREF(Py_TYPE(x));
|
||||
return (PyObject *) Py_TYPE(x);
|
||||
}
|
||||
|
||||
/* SF bug 475327 -- if that didn't trigger, we need 3
|
||||
|
@ -2176,7 +2176,7 @@ _PyType_Lookup(PyTypeObject *type, PyObject *name)
|
|||
static PyObject *
|
||||
type_getattro(PyTypeObject *type, PyObject *name)
|
||||
{
|
||||
PyTypeObject *metatype = Py_Type(type);
|
||||
PyTypeObject *metatype = Py_TYPE(type);
|
||||
PyObject *meta_attribute, *attribute;
|
||||
descrgetfunc meta_get;
|
||||
|
||||
|
@ -2193,7 +2193,7 @@ type_getattro(PyTypeObject *type, PyObject *name)
|
|||
meta_attribute = _PyType_Lookup(metatype, name);
|
||||
|
||||
if (meta_attribute != NULL) {
|
||||
meta_get = Py_Type(meta_attribute)->tp_descr_get;
|
||||
meta_get = Py_TYPE(meta_attribute)->tp_descr_get;
|
||||
|
||||
if (meta_get != NULL && PyDescr_IsData(meta_attribute)) {
|
||||
/* Data descriptors implement tp_descr_set to intercept
|
||||
|
@ -2211,7 +2211,7 @@ type_getattro(PyTypeObject *type, PyObject *name)
|
|||
attribute = _PyType_Lookup(type, name);
|
||||
if (attribute != NULL) {
|
||||
/* Implement descriptor functionality, if any */
|
||||
descrgetfunc local_get = Py_Type(attribute)->tp_descr_get;
|
||||
descrgetfunc local_get = Py_TYPE(attribute)->tp_descr_get;
|
||||
|
||||
Py_XDECREF(meta_attribute);
|
||||
|
||||
|
@ -2289,7 +2289,7 @@ type_dealloc(PyTypeObject *type)
|
|||
PyObject_Free((char *)type->tp_doc);
|
||||
Py_XDECREF(et->ht_name);
|
||||
Py_XDECREF(et->ht_slots);
|
||||
Py_Type(type)->tp_free((PyObject *)type);
|
||||
Py_TYPE(type)->tp_free((PyObject *)type);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
@ -2499,7 +2499,7 @@ object_init(PyObject *self, PyObject *args, PyObject *kwds)
|
|||
{
|
||||
int err = 0;
|
||||
if (excess_args(args, kwds)) {
|
||||
PyTypeObject *type = Py_Type(self);
|
||||
PyTypeObject *type = Py_TYPE(self);
|
||||
if (type->tp_init != object_init &&
|
||||
type->tp_new != object_new)
|
||||
{
|
||||
|
@ -2546,7 +2546,7 @@ object_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||
static void
|
||||
object_dealloc(PyObject *self)
|
||||
{
|
||||
Py_Type(self)->tp_free(self);
|
||||
Py_TYPE(self)->tp_free(self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
@ -2555,7 +2555,7 @@ object_repr(PyObject *self)
|
|||
PyTypeObject *type;
|
||||
PyObject *mod, *name, *rtn;
|
||||
|
||||
type = Py_Type(self);
|
||||
type = Py_TYPE(self);
|
||||
mod = type_module(type, NULL);
|
||||
if (mod == NULL)
|
||||
PyErr_Clear();
|
||||
|
@ -2584,7 +2584,7 @@ object_str(PyObject *self)
|
|||
{
|
||||
unaryfunc f;
|
||||
|
||||
f = Py_Type(self)->tp_repr;
|
||||
f = Py_TYPE(self)->tp_repr;
|
||||
if (f == NULL)
|
||||
f = object_repr;
|
||||
return f(self);
|
||||
|
@ -2593,8 +2593,8 @@ object_str(PyObject *self)
|
|||
static PyObject *
|
||||
object_get_class(PyObject *self, void *closure)
|
||||
{
|
||||
Py_INCREF(Py_Type(self));
|
||||
return (PyObject *)(Py_Type(self));
|
||||
Py_INCREF(Py_TYPE(self));
|
||||
return (PyObject *)(Py_TYPE(self));
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -2679,7 +2679,7 @@ compatible_for_assignment(PyTypeObject* oldto, PyTypeObject* newto, char* attr)
|
|||
static int
|
||||
object_set_class(PyObject *self, PyObject *value, void *closure)
|
||||
{
|
||||
PyTypeObject *oldto = Py_Type(self);
|
||||
PyTypeObject *oldto = Py_TYPE(self);
|
||||
PyTypeObject *newto;
|
||||
|
||||
if (value == NULL) {
|
||||
|
@ -2690,7 +2690,7 @@ object_set_class(PyObject *self, PyObject *value, void *closure)
|
|||
if (!PyType_Check(value)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"__class__ must be set to new-style class, not '%s' object",
|
||||
Py_Type(value)->tp_name);
|
||||
Py_TYPE(value)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
newto = (PyTypeObject *)value;
|
||||
|
@ -2703,7 +2703,7 @@ object_set_class(PyObject *self, PyObject *value, void *closure)
|
|||
}
|
||||
if (compatible_for_assignment(newto, oldto, "__class__")) {
|
||||
Py_INCREF(newto);
|
||||
Py_Type(self) = newto;
|
||||
Py_TYPE(self) = newto;
|
||||
Py_DECREF(oldto);
|
||||
return 0;
|
||||
}
|
||||
|
@ -2799,7 +2799,7 @@ reduce_2(PyObject *obj)
|
|||
if (args != NULL && !PyTuple_Check(args)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"__getnewargs__ should return a tuple, "
|
||||
"not '%.200s'", Py_Type(args)->tp_name);
|
||||
"not '%.200s'", Py_TYPE(args)->tp_name);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
@ -3481,8 +3481,8 @@ PyType_Ready(PyTypeObject *type)
|
|||
NULL when type is &PyBaseObject_Type, and we know its ob_type is
|
||||
not NULL (it's initialized to &PyType_Type). But coverity doesn't
|
||||
know that. */
|
||||
if (Py_Type(type) == NULL && base != NULL)
|
||||
Py_Type(type) = Py_Type(base);
|
||||
if (Py_TYPE(type) == NULL && base != NULL)
|
||||
Py_TYPE(type) = Py_TYPE(base);
|
||||
|
||||
/* Initialize tp_bases */
|
||||
bases = type->tp_bases;
|
||||
|
@ -3854,7 +3854,7 @@ getindex(PyObject *self, PyObject *arg)
|
|||
if (i == -1 && PyErr_Occurred())
|
||||
return -1;
|
||||
if (i < 0) {
|
||||
PySequenceMethods *sq = Py_Type(self)->tp_as_sequence;
|
||||
PySequenceMethods *sq = Py_TYPE(self)->tp_as_sequence;
|
||||
if (sq && sq->sq_length) {
|
||||
Py_ssize_t n = (*sq->sq_length)(self);
|
||||
if (n < 0)
|
||||
|
@ -4030,14 +4030,14 @@ wrap_cmpfunc(PyObject *self, PyObject *args, void *wrapped)
|
|||
if (!check_num_args(args, 1))
|
||||
return NULL;
|
||||
other = PyTuple_GET_ITEM(args, 0);
|
||||
if (Py_Type(other)->tp_compare != func &&
|
||||
!PyType_IsSubtype(Py_Type(other), Py_Type(self))) {
|
||||
if (Py_TYPE(other)->tp_compare != func &&
|
||||
!PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) {
|
||||
PyErr_Format(
|
||||
PyExc_TypeError,
|
||||
"%s.__cmp__(x,y) requires y to be a '%s', not a '%s'",
|
||||
Py_Type(self)->tp_name,
|
||||
Py_Type(self)->tp_name,
|
||||
Py_Type(other)->tp_name);
|
||||
Py_TYPE(self)->tp_name,
|
||||
Py_TYPE(self)->tp_name,
|
||||
Py_TYPE(other)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
res = (*func)(self, other);
|
||||
|
@ -4051,7 +4051,7 @@ wrap_cmpfunc(PyObject *self, PyObject *args, void *wrapped)
|
|||
static int
|
||||
hackcheck(PyObject *self, setattrofunc func, char *what)
|
||||
{
|
||||
PyTypeObject *type = Py_Type(self);
|
||||
PyTypeObject *type = Py_TYPE(self);
|
||||
while (type && type->tp_flags & Py_TPFLAGS_HEAPTYPE)
|
||||
type = type->tp_base;
|
||||
/* If type is NULL now, this is a really weird type.
|
||||
|
@ -4251,7 +4251,7 @@ tp_new_wrapper(PyObject *self, PyObject *args, PyObject *kwds)
|
|||
PyErr_Format(PyExc_TypeError,
|
||||
"%s.__new__(X): X is not a type object (%s)",
|
||||
type->tp_name,
|
||||
Py_Type(arg0)->tp_name);
|
||||
Py_TYPE(arg0)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
subtype = (PyTypeObject *)arg0;
|
||||
|
@ -4342,14 +4342,14 @@ method_is_overloaded(PyObject *left, PyObject *right, char *name)
|
|||
PyObject *a, *b;
|
||||
int ok;
|
||||
|
||||
b = PyObject_GetAttrString((PyObject *)(Py_Type(right)), name);
|
||||
b = PyObject_GetAttrString((PyObject *)(Py_TYPE(right)), name);
|
||||
if (b == NULL) {
|
||||
PyErr_Clear();
|
||||
/* If right doesn't have it, it's not overloaded */
|
||||
return 0;
|
||||
}
|
||||
|
||||
a = PyObject_GetAttrString((PyObject *)(Py_Type(left)), name);
|
||||
a = PyObject_GetAttrString((PyObject *)(Py_TYPE(left)), name);
|
||||
if (a == NULL) {
|
||||
PyErr_Clear();
|
||||
Py_DECREF(b);
|
||||
|
@ -4374,14 +4374,14 @@ static PyObject * \
|
|||
FUNCNAME(PyObject *self, PyObject *other) \
|
||||
{ \
|
||||
static PyObject *cache_str, *rcache_str; \
|
||||
int do_other = Py_Type(self) != Py_Type(other) && \
|
||||
Py_Type(other)->tp_as_number != NULL && \
|
||||
Py_Type(other)->tp_as_number->SLOTNAME == TESTFUNC; \
|
||||
if (Py_Type(self)->tp_as_number != NULL && \
|
||||
Py_Type(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
|
||||
int do_other = Py_TYPE(self) != Py_TYPE(other) && \
|
||||
Py_TYPE(other)->tp_as_number != NULL && \
|
||||
Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
|
||||
if (Py_TYPE(self)->tp_as_number != NULL && \
|
||||
Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
|
||||
PyObject *r; \
|
||||
if (do_other && \
|
||||
PyType_IsSubtype(Py_Type(other), Py_Type(self)) && \
|
||||
PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self)) && \
|
||||
method_is_overloaded(self, other, ROPSTR)) { \
|
||||
r = call_maybe( \
|
||||
other, ROPSTR, &rcache_str, "(O)", self); \
|
||||
|
@ -4393,7 +4393,7 @@ FUNCNAME(PyObject *self, PyObject *other) \
|
|||
r = call_maybe( \
|
||||
self, OPSTR, &cache_str, "(O)", other); \
|
||||
if (r != Py_NotImplemented || \
|
||||
Py_Type(other) == Py_Type(self)) \
|
||||
Py_TYPE(other) == Py_TYPE(self)) \
|
||||
return r; \
|
||||
Py_DECREF(r); \
|
||||
} \
|
||||
|
@ -4451,12 +4451,12 @@ slot_sq_item(PyObject *self, Py_ssize_t i)
|
|||
if (getitem_str == NULL)
|
||||
return NULL;
|
||||
}
|
||||
func = _PyType_Lookup(Py_Type(self), getitem_str);
|
||||
func = _PyType_Lookup(Py_TYPE(self), getitem_str);
|
||||
if (func != NULL) {
|
||||
if ((f = Py_Type(func)->tp_descr_get) == NULL)
|
||||
if ((f = Py_TYPE(func)->tp_descr_get) == NULL)
|
||||
Py_INCREF(func);
|
||||
else {
|
||||
func = f(func, self, (PyObject *)(Py_Type(self)));
|
||||
func = f(func, self, (PyObject *)(Py_TYPE(self)));
|
||||
if (func == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -4595,8 +4595,8 @@ slot_nb_power(PyObject *self, PyObject *other, PyObject *modulus)
|
|||
/* Three-arg power doesn't use __rpow__. But ternary_op
|
||||
can call this when the second argument's type uses
|
||||
slot_nb_power, so check before calling self.__pow__. */
|
||||
if (Py_Type(self)->tp_as_number != NULL &&
|
||||
Py_Type(self)->tp_as_number->nb_power == slot_nb_power) {
|
||||
if (Py_TYPE(self)->tp_as_number != NULL &&
|
||||
Py_TYPE(self)->tp_as_number->nb_power == slot_nb_power) {
|
||||
return call_method(self, "__pow__", &pow_str,
|
||||
"(OO)", other, modulus);
|
||||
}
|
||||
|
@ -4786,12 +4786,12 @@ _PyObject_SlotCompare(PyObject *self, PyObject *other)
|
|||
{
|
||||
int c;
|
||||
|
||||
if (Py_Type(self)->tp_compare == _PyObject_SlotCompare) {
|
||||
if (Py_TYPE(self)->tp_compare == _PyObject_SlotCompare) {
|
||||
c = half_compare(self, other);
|
||||
if (c <= 1)
|
||||
return c;
|
||||
}
|
||||
if (Py_Type(other)->tp_compare == _PyObject_SlotCompare) {
|
||||
if (Py_TYPE(other)->tp_compare == _PyObject_SlotCompare) {
|
||||
c = half_compare(other, self);
|
||||
if (c < -1)
|
||||
return -2;
|
||||
|
@ -4816,7 +4816,7 @@ slot_tp_repr(PyObject *self)
|
|||
}
|
||||
PyErr_Clear();
|
||||
return PyString_FromFormat("<%s object at %p>",
|
||||
Py_Type(self)->tp_name, self);
|
||||
Py_TYPE(self)->tp_name, self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
@ -4916,7 +4916,7 @@ slot_tp_getattro(PyObject *self, PyObject *name)
|
|||
static PyObject *
|
||||
slot_tp_getattr_hook(PyObject *self, PyObject *name)
|
||||
{
|
||||
PyTypeObject *tp = Py_Type(self);
|
||||
PyTypeObject *tp = Py_TYPE(self);
|
||||
PyObject *getattr, *getattribute, *res;
|
||||
static PyObject *getattribute_str = NULL;
|
||||
static PyObject *getattr_str = NULL;
|
||||
|
@ -4940,7 +4940,7 @@ slot_tp_getattr_hook(PyObject *self, PyObject *name)
|
|||
}
|
||||
getattribute = _PyType_Lookup(tp, getattribute_str);
|
||||
if (getattribute == NULL ||
|
||||
(Py_Type(getattribute) == &PyWrapperDescr_Type &&
|
||||
(Py_TYPE(getattribute) == &PyWrapperDescr_Type &&
|
||||
((PyWrapperDescrObject *)getattribute)->d_wrapped ==
|
||||
(void *)PyObject_GenericGetAttr))
|
||||
res = PyObject_GenericGetAttr(self, name);
|
||||
|
@ -4999,13 +4999,13 @@ slot_tp_richcompare(PyObject *self, PyObject *other, int op)
|
|||
{
|
||||
PyObject *res;
|
||||
|
||||
if (Py_Type(self)->tp_richcompare == slot_tp_richcompare) {
|
||||
if (Py_TYPE(self)->tp_richcompare == slot_tp_richcompare) {
|
||||
res = half_richcompare(self, other, op);
|
||||
if (res != Py_NotImplemented)
|
||||
return res;
|
||||
Py_DECREF(res);
|
||||
}
|
||||
if (Py_Type(other)->tp_richcompare == slot_tp_richcompare) {
|
||||
if (Py_TYPE(other)->tp_richcompare == slot_tp_richcompare) {
|
||||
res = half_richcompare(other, self, _Py_SwappedOp[op]);
|
||||
if (res != Py_NotImplemented) {
|
||||
return res;
|
||||
|
@ -5038,7 +5038,7 @@ slot_tp_iter(PyObject *self)
|
|||
if (func == NULL) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"'%.200s' object is not iterable",
|
||||
Py_Type(self)->tp_name);
|
||||
Py_TYPE(self)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
Py_DECREF(func);
|
||||
|
@ -5055,7 +5055,7 @@ slot_tp_iternext(PyObject *self)
|
|||
static PyObject *
|
||||
slot_tp_descr_get(PyObject *self, PyObject *obj, PyObject *type)
|
||||
{
|
||||
PyTypeObject *tp = Py_Type(self);
|
||||
PyTypeObject *tp = Py_TYPE(self);
|
||||
PyObject *get;
|
||||
static PyObject *get_str = NULL;
|
||||
|
||||
|
@ -5113,7 +5113,7 @@ slot_tp_init(PyObject *self, PyObject *args, PyObject *kwds)
|
|||
if (res != Py_None) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"__init__() should return None, not '%.200s'",
|
||||
Py_Type(res)->tp_name);
|
||||
Py_TYPE(res)->tp_name);
|
||||
Py_DECREF(res);
|
||||
return -1;
|
||||
}
|
||||
|
@ -5198,7 +5198,7 @@ slot_tp_del(PyObject *self)
|
|||
_Py_NewReference(self);
|
||||
self->ob_refcnt = refcnt;
|
||||
}
|
||||
assert(!PyType_IS_GC(Py_Type(self)) ||
|
||||
assert(!PyType_IS_GC(Py_TYPE(self)) ||
|
||||
_Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED);
|
||||
/* If Py_REF_DEBUG, _Py_NewReference bumped _Py_RefTotal, so
|
||||
* we need to undo that. */
|
||||
|
@ -5210,8 +5210,8 @@ slot_tp_del(PyObject *self)
|
|||
* undone.
|
||||
*/
|
||||
#ifdef COUNT_ALLOCS
|
||||
--Py_Type(self)->tp_frees;
|
||||
--Py_Type(self)->tp_allocs;
|
||||
--Py_TYPE(self)->tp_frees;
|
||||
--Py_TYPE(self)->tp_allocs;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -5573,7 +5573,7 @@ update_one_slot(PyTypeObject *type, slotdef *p)
|
|||
descr = _PyType_Lookup(type, p->name_strobj);
|
||||
if (descr == NULL)
|
||||
continue;
|
||||
if (Py_Type(descr) == &PyWrapperDescr_Type) {
|
||||
if (Py_TYPE(descr) == &PyWrapperDescr_Type) {
|
||||
void **tptr = resolve_slotdups(type, p->name_strobj);
|
||||
if (tptr == NULL || tptr == ptr)
|
||||
generic = p->function;
|
||||
|
@ -5588,7 +5588,7 @@ update_one_slot(PyTypeObject *type, slotdef *p)
|
|||
use_generic = 1;
|
||||
}
|
||||
}
|
||||
else if (Py_Type(descr) == &PyCFunction_Type &&
|
||||
else if (Py_TYPE(descr) == &PyCFunction_Type &&
|
||||
PyCFunction_GET_FUNCTION(descr) ==
|
||||
(PyCFunction)tp_new_wrapper &&
|
||||
strcmp(p->name, "__new__") == 0)
|
||||
|
@ -5859,7 +5859,7 @@ super_dealloc(PyObject *self)
|
|||
Py_XDECREF(su->obj);
|
||||
Py_XDECREF(su->type);
|
||||
Py_XDECREF(su->obj_type);
|
||||
Py_Type(self)->tp_free(self);
|
||||
Py_TYPE(self)->tp_free(self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
@ -5924,7 +5924,7 @@ super_getattro(PyObject *self, PyObject *name)
|
|||
res = PyDict_GetItem(dict, name);
|
||||
if (res != NULL) {
|
||||
Py_INCREF(res);
|
||||
f = Py_Type(res)->tp_descr_get;
|
||||
f = Py_TYPE(res)->tp_descr_get;
|
||||
if (f != NULL) {
|
||||
tmp = f(res,
|
||||
/* Only pass 'obj' param if
|
||||
|
@ -5960,7 +5960,7 @@ supercheck(PyTypeObject *type, PyObject *obj)
|
|||
the normal case; the return value is obj.__class__.
|
||||
|
||||
But... when obj is an instance, we want to allow for the case where
|
||||
Py_Type(obj) is not a subclass of type, but obj.__class__ is!
|
||||
Py_TYPE(obj) is not a subclass of type, but obj.__class__ is!
|
||||
This will allow using super() with a proxy for obj.
|
||||
*/
|
||||
|
||||
|
@ -5971,9 +5971,9 @@ supercheck(PyTypeObject *type, PyObject *obj)
|
|||
}
|
||||
|
||||
/* Normal case */
|
||||
if (PyType_IsSubtype(Py_Type(obj), type)) {
|
||||
Py_INCREF(Py_Type(obj));
|
||||
return Py_Type(obj);
|
||||
if (PyType_IsSubtype(Py_TYPE(obj), type)) {
|
||||
Py_INCREF(Py_TYPE(obj));
|
||||
return Py_TYPE(obj);
|
||||
}
|
||||
else {
|
||||
/* Try the slow way */
|
||||
|
@ -5990,7 +5990,7 @@ supercheck(PyTypeObject *type, PyObject *obj)
|
|||
|
||||
if (class_attr != NULL &&
|
||||
PyType_Check(class_attr) &&
|
||||
(PyTypeObject *)class_attr != Py_Type(obj))
|
||||
(PyTypeObject *)class_attr != Py_TYPE(obj))
|
||||
{
|
||||
int ok = PyType_IsSubtype(
|
||||
(PyTypeObject *)class_attr, type);
|
||||
|
@ -6021,10 +6021,10 @@ super_descr_get(PyObject *self, PyObject *obj, PyObject *type)
|
|||
Py_INCREF(self);
|
||||
return self;
|
||||
}
|
||||
if (Py_Type(su) != &PySuper_Type)
|
||||
if (Py_TYPE(su) != &PySuper_Type)
|
||||
/* If su is an instance of a (strict) subclass of super,
|
||||
call its type */
|
||||
return PyObject_CallFunctionObjArgs((PyObject *)Py_Type(su),
|
||||
return PyObject_CallFunctionObjArgs((PyObject *)Py_TYPE(su),
|
||||
su->type, obj, NULL);
|
||||
else {
|
||||
/* Inline the common case */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue