[Python-checkins] r47062 - in python/branches/release24-maint: Lib/test/test_exceptions.py Objects/abstract.c Objects/typeobject.c

armin.rigo python-checkins at python.org
Thu Jun 22 00:11:17 CEST 2006


Author: armin.rigo
Date: Thu Jun 22 00:11:16 2006
New Revision: 47062

Modified:
   python/branches/release24-maint/Lib/test/test_exceptions.py
   python/branches/release24-maint/Objects/abstract.c
   python/branches/release24-maint/Objects/typeobject.c
Log:
Backport of r47061.


Modified: python/branches/release24-maint/Lib/test/test_exceptions.py
==============================================================================
--- python/branches/release24-maint/Lib/test/test_exceptions.py	(original)
+++ python/branches/release24-maint/Lib/test/test_exceptions.py	Thu Jun 22 00:11:16 2006
@@ -209,3 +209,18 @@
     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()

Modified: python/branches/release24-maint/Objects/abstract.c
==============================================================================
--- python/branches/release24-maint/Objects/abstract.c	(original)
+++ python/branches/release24-maint/Objects/abstract.c	Thu Jun 22 00:11:16 2006
@@ -1792,11 +1792,7 @@
         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,

Modified: python/branches/release24-maint/Objects/typeobject.c
==============================================================================
--- python/branches/release24-maint/Objects/typeobject.c	(original)
+++ python/branches/release24-maint/Objects/typeobject.c	Thu Jun 22 00:11:16 2006
@@ -4530,7 +4530,16 @@
 
 	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;
 }


More information about the Python-checkins mailing list