[Python-checkins] python/dist/src/Objects classobject.c,2.154,2.155

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Thu, 13 Jun 2002 14:31:53 -0700


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv7570

Modified Files:
	classobject.c 
Log Message:
Fix for SF bug 532646.  This is a little simpler than what Neal
suggested there, based upon a better analysis (__getattr__ is a red
herring).  Will backport to 2.2.


Index: classobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/classobject.c,v
retrieving revision 2.154
retrieving revision 2.155
diff -C2 -d -r2.154 -r2.155
*** classobject.c	26 Oct 2001 17:56:51 -0000	2.154
--- classobject.c	13 Jun 2002 21:31:27 -0000	2.155
***************
*** 1880,1883 ****
--- 1880,1884 ----
  instance_call(PyObject *func, PyObject *arg, PyObject *kw)
  {
+ 	PyThreadState *tstate = PyThreadState_GET();
  	PyObject *res, *call = PyObject_GetAttrString(func, "__call__");
  	if (call == NULL) {
***************
*** 1889,1893 ****
  		return NULL;
  	}
! 	res = PyObject_Call(call, arg, kw);
  	Py_DECREF(call);
  	return res;
--- 1890,1909 ----
  		return NULL;
  	}
! 	/* We must check and increment the recursion depth here. Scenario:
! 	       class A:
! 	           pass
! 	       A.__call__ = A() # that's right
! 	       a = A() # ok
! 	       a() # infinite recursion
! 	   This bounces between instance_call() and PyObject_Call() without
! 	   ever hitting eval_frame() (which has the main recursion check). */
! 	if (tstate->recursion_depth++ > Py_GetRecursionLimit()) {
! 		PyErr_SetString(PyExc_RuntimeError,
! 				"maximum __call__ recursion depth exceeded");
! 		res = NULL;
! 	}
! 	else
! 		res = PyObject_Call(call, arg, kw);
! 	tstate->recursion_depth--;
  	Py_DECREF(call);
  	return res;