From: Brett Cannon Date: Fri, 9 Jun 2006 22:38:29 +0000 (+0000) Subject: Backport of fix of bug #532646 for new-style classes. X-Git-Tag: v2.4.4c1~190 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7afe7fe14afc3e84f2c1e7b1f666b557860f430c;p=thirdparty%2FPython%2Fcpython.git Backport of fix of bug #532646 for new-style classes. --- diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 4b57a74c9819..ed779db2eea5 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -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() diff --git a/Misc/NEWS b/Misc/NEWS index 5230d9ac2f7b..f83d112fe62b 100644 --- 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 diff --git a/Objects/abstract.c b/Objects/abstract.c index 159af3499bef..895e915fc582 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -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,