]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport of fix of bug #532646 for new-style classes.
authorBrett Cannon <bcannon@gmail.com>
Fri, 9 Jun 2006 22:38:29 +0000 (22:38 +0000)
committerBrett Cannon <bcannon@gmail.com>
Fri, 9 Jun 2006 22:38:29 +0000 (22:38 +0000)
Lib/test/test_descr.py
Misc/NEWS
Objects/abstract.c

index 4b57a74c98191064fb8d2e74e58bade31717bfde..ed779db2eea5d8b05fda66ede6cc76ce4efb230e 100644 (file)
@@ -3116,6 +3116,21 @@ def kwdargs():
     list.__init__(a, sequence=[0, 1, 2])
     vereq(a, [0, 1, 2])
 
+def recursive__call__():
+    if verbose: print ("Testing recursive __call__() by setting to instance of "
+                        "class ...")
+    class A(object):
+        pass
+
+    A.__call__ = A()
+    try:
+        A()()
+    except RuntimeError:
+        pass
+    else:
+        raise TestFailed("Recursion limit should have been reached for "
+                         "__call__()")
+
 def delhook():
     if verbose: print "Testing __del__ hook..."
     log = []
@@ -4118,6 +4133,7 @@ def test_main():
     buffer_inherit()
     str_of_str_subclass()
     kwdargs()
+    recursive__call__()
     delhook()
     hashinherit()
     strops()
index 5230d9ac2f7b343a9bab4e92b2e684cb896effd4..f83d112fe62b4ea82dab64159c9a5d3220e1ecfb 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,10 @@ What's New in Python 2.4.4c1?
 Core and builtins
 -----------------
 
+- Bug #532646: The object set to the __call__ attribute has its own __call__
+  attribute checked; this continues until the attribute can no longer be found
+  or segfaulting.  Recursion limit is now followed.
+
 - Bug #1454485: Don't crash on Unicode characters <0.
 
 - Patch #1488312, Fix memory alignment problem on SPARC in unicode
index 159af3499bef56ed3f967878a850ddec3dd792f5..895e915fc58291f73bf19ddc329669a181640328 100644 (file)
@@ -1792,7 +1792,10 @@ PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw)
         ternaryfunc call;
 
        if ((call = func->ob_type->tp_call) != NULL) {
+               if (Py_EnterRecursiveCall(" in __call__"))
+                       return NULL;
                PyObject *result = (*call)(func, arg, kw);
+               Py_LeaveRecursiveCall();
                if (result == NULL && !PyErr_Occurred())
                        PyErr_SetString(
                                PyExc_SystemError,