[Python-checkins] CVS: python/dist/src/Objects abstract.c,2.83,2.84
Guido van Rossum
gvanrossum@users.sourceforge.net
Sun, 07 Oct 2001 13:53:47 -0700
- Previous message: [Python-checkins] CVS: python/dist/src/Lib ftplib.py,1.57,1.58 httplib.py,1.39,1.40 poplib.py,1.17,1.18 smtplib.py,1.43,1.44 telnetlib.py,1.15,1.16
- Next message: [Python-checkins] CVS: python/dist/src/Python bltinmodule.c,2.239,2.240
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv13774
Modified Files:
abstract.c
Log Message:
Implement isinstance(x, (A, B, ...)). Note that we only allow tuples,
not other sequences (then we'd have to except strings, and we'd still
be susceptible to recursive attacks).
Index: abstract.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/abstract.c,v
retrieving revision 2.83
retrieving revision 2.84
diff -C2 -d -r2.83 -r2.84
*** abstract.c 2001/10/01 17:10:18 2.83
--- abstract.c 2001/10/07 20:53:45 2.84
***************
*** 1806,1809 ****
--- 1806,1823 ----
retval = PyObject_TypeCheck(inst, (PyTypeObject *)cls);
}
+ else if (PyTuple_Check(cls)) {
+ /* Not a general sequence -- that opens up the road to
+ recursion and stack overflow. */
+ int i, n;
+
+ n = PyTuple_GET_SIZE(cls);
+ for (i = 0; i < n; i++) {
+ retval = PyObject_IsInstance(
+ inst, PyTuple_GET_ITEM(cls, i));
+ if (retval != 0)
+ break;
+ }
+ return retval;
+ }
else if (!PyInstance_Check(inst)) {
if (__class__ == NULL) {
***************
*** 1828,1832 ****
if (retval < 0) {
PyErr_SetString(PyExc_TypeError,
! "isinstance() arg 2 must be a class or type");
}
return retval;
--- 1842,1847 ----
if (retval < 0) {
PyErr_SetString(PyExc_TypeError,
! "isinstance() arg 2 must be a class or type "
! "or tuple of those");
}
return retval;
- Previous message: [Python-checkins] CVS: python/dist/src/Lib ftplib.py,1.57,1.58 httplib.py,1.39,1.40 poplib.py,1.17,1.18 smtplib.py,1.43,1.44 telnetlib.py,1.15,1.16
- Next message: [Python-checkins] CVS: python/dist/src/Python bltinmodule.c,2.239,2.240
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]