[Python-checkins] CVS: python/dist/src/Objects object.c,2.124.4.20,2.124.4.21 typeobject.c,2.16.8.56,2.16.8.57
Guido van Rossum
gvanrossum@users.sourceforge.net
2001年7月02日 17:37:49 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv15305/Objects
Modified Files:
Tag: descr-branch
object.c typeobject.c
Log Message:
Fix the subtype test (the previous checkins broke test_descr.py
because the subtype test was being applied in a multiple-inheritance
situation).
First, _PyObject_TypeCheck() is renamed to PyType_IsSubtype() and
moved from object.c to typeobject.c, where it belings.
Next, its implementation is changed to use the MRO tuple if it exists;
for bootstrap reasons, it walks the tp_base chain (single inheritance
only) as a fallback.
Finally, issubtype() is deleted and calls to it are replaced with a
call to PyType_IsSubtype().
Index: object.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/object.c,v
retrieving revision 2.124.4.20
retrieving revision 2.124.4.21
diff -C2 -r2.124.4.20 -r2.124.4.21
*** object.c 2001年07月02日 17:08:33 2.124.4.20
--- object.c 2001年07月03日 00:37:47 2.124.4.21
***************
*** 1325,1344 ****
- /* type test with subclassing support */
-
- int
- _PyObject_TypeCheck(PyTypeObject *tp, PyTypeObject *type)
- {
- do {
- if (tp == type)
- return 1;
- if (!PyType_HasFeature(tp, Py_TPFLAGS_HAVE_CLASS))
- return 0;
- tp = tp->tp_base;
- } while (tp != NULL);
- return 0;
- }
-
-
/*
NoObject is usable as a non-NULL undefined value, used by the macro None.
--- 1325,1328 ----
Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.16.8.56
retrieving revision 2.16.8.57
diff -C2 -r2.16.8.56 -r2.16.8.57
*** typeobject.c 2001年07月02日 18:06:06 2.16.8.56
--- typeobject.c 2001年07月03日 00:37:47 2.16.8.57
***************
*** 184,216 ****
} etype;
! static int
! issubtype(PyTypeObject *a, PyTypeObject *b)
{
! PyObject *bases;
! PyTypeObject *base;
! int i, n;
! if (b == &PyBaseObject_Type)
! return 1; /* Every type is an implicit subtype of this */
! while (a != NULL) {
! if (a == b)
! return 1;
! bases = a->tp_bases;
! a = a->tp_base;
! if (bases != NULL && PyTuple_Check(bases)) {
! n = PyTuple_GET_SIZE(bases);
! for (i = 0; i < n; i++) {
! base = (PyTypeObject *)
! PyTuple_GET_ITEM(bases, i);
! if (base == b)
! return 1;
! if (base != a) {
! if (issubtype(base, b))
! return 1;
! }
! }
}
}
- return 0;
}
--- 184,216 ----
} etype;
! /* type test with subclassing support */
!
! int
! PyType_IsSubtype(PyTypeObject *a, PyTypeObject *b)
{
! PyObject *mro;
! mro = a->tp_mro;
! if (mro != NULL) {
! /* Deal with multiple inheritance without recursion
! by walking the MRO tuple */
! int i, n;
! assert(PyTuple_Check(mro));
! n = PyTuple_GET_SIZE(mro);
! for (i = 0; i < n; i++) {
! if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b)
! return 1;
}
+ return 0;
+ }
+ else {
+ /* a is not completely initilized yet; follow tp_base */
+ do {
+ if (a == b)
+ return 1;
+ a = a->tp_base;
+ } while (a != NULL);
+ return b == &PyBaseObject_Type;
}
}
***************
*** 322,328 ****
}
candidate = solid_base(base_i);
! if (issubtype(winner, candidate))
;
! else if (issubtype(candidate, winner)) {
winner = candidate;
base = base_i;
--- 322,328 ----
}
candidate = solid_base(base_i);
! if (PyType_IsSubtype(winner, candidate))
;
! else if (PyType_IsSubtype(candidate, winner)) {
winner = candidate;
base = base_i;
***************
*** 413,419 ****
tmp = PyTuple_GET_ITEM(bases, i);
tmptype = tmp->ob_type;
! if (issubtype(metatype, tmptype))
continue;
! if (issubtype(tmptype, metatype)) {
metatype = tmptype;
continue;
--- 413,419 ----
tmp = PyTuple_GET_ITEM(bases, i);
tmptype = tmp->ob_type;
! if (PyType_IsSubtype(metatype, tmptype))
continue;
! if (PyType_IsSubtype(tmptype, metatype)) {
metatype = tmptype;
continue;