[Python-checkins] CVS: python/dist/src/Python ceval.c,2.280,2.281

Fred L. Drake fdrake@users.sourceforge.net
Thu, 04 Oct 2001 12:26:45 -0700


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

Modified Files:
	ceval.c 
Log Message:
Fix bug in profiler modifications detected only in debug builds.
The new profiler event stream includes a "return" event even when an
exception is being propogated, but the machinery that called the profile
hook did not save & restore the exception.  In debug mode, the exception
was detected during the execution of the profile callback, which did not
have the proper internal flags set for the exception.  Saving & restoring
the exception state solves the problem.


Index: ceval.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v
retrieving revision 2.280
retrieving revision 2.281
diff -C2 -d -r2.280 -r2.281
*** ceval.c	2001/10/04 14:48:42	2.280
--- ceval.c	2001/10/04 19:26:43	2.281
***************
*** 49,52 ****
--- 49,54 ----
  static int call_trace(Py_tracefunc, PyObject *, PyFrameObject *,
  		      int, PyObject *);
+ static void call_trace_protected(Py_tracefunc, PyObject *,
+ 				 PyFrameObject *, int);
  static void call_exc_trace(Py_tracefunc, PyObject *, PyFrameObject *);
  static PyObject *loop_subscript(PyObject *, PyObject *);
***************
*** 2298,2304 ****
  		}
  		if (tstate->c_profilefunc) {
! 			if (call_trace(tstate->c_profilefunc,
! 				       tstate->c_profileobj, f,
! 				       PyTrace_RETURN, retval)) {
  				Py_XDECREF(retval);
  				retval = NULL;
--- 2300,2310 ----
  		}
  		if (tstate->c_profilefunc) {
! 			if (why == WHY_EXCEPTION)
! 				call_trace_protected(tstate->c_profilefunc,
! 						     tstate->c_profileobj, f,
! 						     PyTrace_RETURN);
! 			else if (call_trace(tstate->c_profilefunc,
! 					    tstate->c_profileobj, f,
! 					    PyTrace_RETURN, retval)) {
  				Py_XDECREF(retval);
  				retval = NULL;
***************
*** 2813,2816 ****
--- 2819,2839 ----
  	err = call_trace(func, self, f, PyTrace_EXCEPTION, arg);
  	Py_DECREF(arg);
+ 	if (err == 0)
+ 		PyErr_Restore(type, value, traceback);
+ 	else {
+ 		Py_XDECREF(type);
+ 		Py_XDECREF(value);
+ 		Py_XDECREF(traceback);
+ 	}
+ }
+ 
+ static void
+ call_trace_protected(Py_tracefunc func, PyObject *obj, PyFrameObject *frame,
+ 		     int what)
+ {
+ 	PyObject *type, *value, *traceback;
+ 	int err;
+ 	PyErr_Fetch(&type, &value, &traceback);
+ 	err = call_trace(func, obj, frame, what, NULL);
  	if (err == 0)
  		PyErr_Restore(type, value, traceback);