mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Correction for issue1265 (pdb bug with "with" statement).
When an unfinished generator-iterator is garbage collected, PyEval_EvalFrameEx
is called with a GeneratorExit exception set.  This leads to funny results
if the sys.settrace function itself makes use of generators.
A visible effect is that the settrace function is reset to None.
Another is that the eventual "finally" block of the generator is not called.
It is necessary to save/restore the exception around the call to the trace
function.
This happens a lot with py3k: isinstance() of an ABCMeta instance runs
    def __instancecheck__(cls, instance):
        """Override for isinstance(instance, cls)."""
        return any(cls.__subclasscheck__(c)
                   for c in {instance.__class__, type(instance)})
which lets an opened generator expression each time it returns True.
Seems a backport candidate, even if the case is less frequent in 2.5.
			
			
This commit is contained in:
		
							parent
							
								
									8161a65cd8
								
							
						
					
					
						commit
						f05149a257
					
				
					 2 changed files with 59 additions and 9 deletions
				
			
		|  | @ -107,7 +107,7 @@ static int prtrace(PyObject *, char *); | |||
| #endif | ||||
| static int call_trace(Py_tracefunc, PyObject *, PyFrameObject *, | ||||
| 		      int, PyObject *); | ||||
| static void call_trace_protected(Py_tracefunc, PyObject *, | ||||
| static int call_trace_protected(Py_tracefunc, PyObject *, | ||||
| 				 PyFrameObject *, int, PyObject *); | ||||
| static void call_exc_trace(Py_tracefunc, PyObject *, PyFrameObject *); | ||||
| static int maybe_call_line_trace(Py_tracefunc, PyObject *, | ||||
|  | @ -717,8 +717,9 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) | |||
| 			   an argument which depends on the situation. | ||||
| 			   The global trace function is also called | ||||
| 			   whenever an exception is detected. */ | ||||
| 			if (call_trace(tstate->c_tracefunc, tstate->c_traceobj, | ||||
| 				       f, PyTrace_CALL, Py_None)) { | ||||
| 			if (call_trace_protected(tstate->c_tracefunc,  | ||||
| 						 tstate->c_traceobj, | ||||
| 						 f, PyTrace_CALL, Py_None)) { | ||||
| 				/* Trace function raised an error */ | ||||
| 				goto exit_eval_frame; | ||||
| 			} | ||||
|  | @ -726,9 +727,9 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) | |||
| 		if (tstate->c_profilefunc != NULL) { | ||||
| 			/* Similar for c_profilefunc, except it needn't
 | ||||
| 			   return itself and isn't called for "line" events */ | ||||
| 			if (call_trace(tstate->c_profilefunc, | ||||
| 				       tstate->c_profileobj, | ||||
| 				       f, PyTrace_CALL, Py_None)) { | ||||
| 			if (call_trace_protected(tstate->c_profilefunc, | ||||
| 						 tstate->c_profileobj, | ||||
| 						 f, PyTrace_CALL, Py_None)) { | ||||
| 				/* Profile function raised an error */ | ||||
| 				goto exit_eval_frame; | ||||
| 			} | ||||
|  | @ -3127,7 +3128,7 @@ call_exc_trace(Py_tracefunc func, PyObject *self, PyFrameObject *f) | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| static void | ||||
| static int | ||||
| call_trace_protected(Py_tracefunc func, PyObject *obj, PyFrameObject *frame, | ||||
| 		     int what, PyObject *arg) | ||||
| { | ||||
|  | @ -3136,11 +3137,15 @@ call_trace_protected(Py_tracefunc func, PyObject *obj, PyFrameObject *frame, | |||
| 	PyErr_Fetch(&type, &value, &traceback); | ||||
| 	err = call_trace(func, obj, frame, what, arg); | ||||
| 	if (err == 0) | ||||
| 	{ | ||||
| 		PyErr_Restore(type, value, traceback); | ||||
| 		return 0; | ||||
| 	} | ||||
| 	else { | ||||
| 		Py_XDECREF(type); | ||||
| 		Py_XDECREF(value); | ||||
| 		Py_XDECREF(traceback); | ||||
| 		return -1; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Amaury Forgeot d'Arc
						Amaury Forgeot d'Arc