diff options
author | Armin Rigo <arigo@tunes.org> | 2006-06-21 21:58:50 (GMT) |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2006-06-21 21:58:50 (GMT) |
commit | 53c1692f6ac592a8c0d5a6f83017019b52625969 (patch) | |
tree | cf3bbc857dcacec8d9f1ac63c14cb05906fc7378 /Objects | |
parent | f92b9c21edd77356179050549465e58276cad532 (diff) | |
download | cpython-53c1692f6ac592a8c0d5a6f83017019b52625969.zip cpython-53c1692f6ac592a8c0d5a6f83017019b52625969.tar.gz cpython-53c1692f6ac592a8c0d5a6f83017019b52625969.tar.bz2 |
Fix for an obscure bug introduced by revs 46806 and 46808, with a test.
The problem of checking too eagerly for recursive calls is the
following: if a RuntimeError is caused by recursion, and if code needs
to normalize it immediately (as in the 2nd test), then
PyErr_NormalizeException() needs a call to the RuntimeError class to
instantiate it, and this hits the recursion limit again... causing
PyErr_NormalizeException() to never finish.
Moved this particular recursion check to slot_tp_call(), which is not
involved in instantiating built-in exceptions.
Backport candidate.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/abstract.c | 12 | ||||
-rw-r--r-- | Objects/typeobject.c | 9 |
2 files changed, 10 insertions, 11 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c index d16660b..638e417 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -1796,17 +1796,7 @@ PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) ternaryfunc call; if ((call = func->ob_type->tp_call) != NULL) { - PyObject *result = NULL; - /* slot_tp_call() will be called and ends up calling - PyObject_Call() if the object returned for __call__ has - __call__ itself defined upon it. This can be an infinite - recursion if you set __call__ in a class to an instance of - it. */ - if (Py_EnterRecursiveCall(" in __call__")) { - return NULL; - } - result = (*call)(func, arg, kw); - Py_LeaveRecursiveCall(); + PyObject *result = (*call)(func, arg, kw); if (result == NULL && !PyErr_Occurred()) PyErr_SetString( PyExc_SystemError, diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 439676f..760ef95 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -4590,7 +4590,16 @@ slot_tp_call(PyObject *self, PyObject *args, PyObject *kwds) if (meth == NULL) return NULL; + + /* PyObject_Call() will end up calling slot_tp_call() again if + the object returned for __call__ has __call__ itself defined + upon it. This can be an infinite recursion if you set + __call__ in a class to an instance of it. */ + if (Py_EnterRecursiveCall(" in __call__")) + return NULL; res = PyObject_Call(meth, args, kwds); + Py_LeaveRecursiveCall(); + Py_DECREF(meth); return res; } |