Index: Objects/abstract.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Objects/abstract.c,v retrieving revision 2.119 diff -u -r2.119 abstract.c --- Objects/abstract.c 1 Mar 2003 01:44:32 -0000 2.119 +++ Objects/abstract.c 20 Mar 2004 16:02:11 -0000 @@ -2035,8 +2035,8 @@ return -1; } -int -PyObject_IsInstance(PyObject *inst, PyObject *cls) +static int +recursive_IsInstance(PyObject *inst, PyObject *cls, int recursion_depth) { PyObject *icls; static PyObject *__class__ = NULL; @@ -2071,14 +2071,19 @@ } } else if (PyTuple_Check(cls)) { - /* Not a general sequence -- that opens up the road to - recursion and stack overflow. */ int i, n; + if (!recursion_depth) { + PyErr_SetString(PyExc_RuntimeError, + "Recursion depth exceeded"); + return NULL; + } + n = PyTuple_GET_SIZE(cls); for (i = 0; i < n; i++) { - retval = PyObject_IsInstance( - inst, PyTuple_GET_ITEM(cls, i)); + retval = recursive_IsInstance( + inst, PyTuple_GET_ITEM(cls, i), + recursion_depth-1); if (retval != 0) break; } @@ -2103,7 +2108,13 @@ } int -PyObject_IsSubclass(PyObject *derived, PyObject *cls) +PyObject_IsInstance(PyObject *inst, PyObject *cls) +{ + return recursive_IsInstance(inst, cls, Py_GetRecursionLimit()); +} + +static int +recursive_IsSubclass(PyObject *derived, PyObject *cls, int recursion_depth) { int retval; @@ -2115,9 +2126,17 @@ if (PyTuple_Check(cls)) { int i; int n = PyTuple_GET_SIZE(cls); + + if (!recursion_depth) { + PyErr_SetString(PyExc_RuntimeError, + "Recursion depth exceeded"); + return NULL; + } + for (i = 0; i < n; ++i) { - retval = PyObject_IsSubclass( - derived, PyTuple_GET_ITEM(cls, i)); + retval = recursive_IsSubclass( + derived, PyTuple_GET_ITEM(cls, i), + recursion_depth-1); if (retval != 0) { /* either found it, or got an error */ return retval; @@ -2143,6 +2162,12 @@ return retval; } +int +PyObject_IsSubclass(PyObject *derived, PyObject *cls) +{ + return recursive_IsSubclass(derived, cls, Py_GetRecursionLimit()); +} + PyObject * PyObject_GetIter(PyObject *o) {