]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport of r47061.
authorArmin Rigo <arigo@tunes.org>
Wed, 21 Jun 2006 22:11:16 +0000 (22:11 +0000)
committerArmin Rigo <arigo@tunes.org>
Wed, 21 Jun 2006 22:11:16 +0000 (22:11 +0000)
Lib/test/test_exceptions.py
Objects/abstract.c
Objects/typeobject.c

index c157122b5b0c668f5d685ccbf836f2de9fd81ea9..547abd132c736b146d3b7b348e6d76522eed473f 100644 (file)
@@ -209,3 +209,18 @@ if not sys.platform.startswith('java'):
     test_capi2()
 
 unlink(TESTFN)
+
+def test_infinite_recursion():
+    def g():
+        try:
+            return g()
+        except ValueError:
+            return -1
+    try:
+        g()
+    except RuntimeError:
+        pass
+    else:
+        print "Expected exception"
+
+test_infinite_recursion()
index 15ed89ea4f6e68e52c63e741d5d0994178050482..159af3499bef56ed3f967878a850ddec3dd792f5 100644 (file)
@@ -1792,11 +1792,7 @@ PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw)
         ternaryfunc call;
 
        if ((call = func->ob_type->tp_call) != NULL) {
-               PyObject *result = NULL;
-               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,
index bb4b7a8cf020485fe3b1c734f9663f9b30e07ae7..c2312fe0e609172a45b731c4a74fdce093de6ab7 100644 (file)
@@ -4530,7 +4530,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;
 }