mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	Fix for the recursion_level bug Armin Rigo reported in sf
patch #617312, both on the trunk and the 22-maint branch. Also added a test case, and ported the test_trace I wrote for HEAD to 2.2.2 (with all those horrible extra 'line' events ;-).
This commit is contained in:
		
							parent
							
								
									3c6d6f2ff7
								
							
						
					
					
						commit
						fb4d6ecd07
					
				
					 2 changed files with 24 additions and 0 deletions
				
			
		|  | @ -177,8 +177,28 @@ def test_8_settrace_and_return(self): | ||||||
|     def test_9_settrace_and_raise(self): |     def test_9_settrace_and_raise(self): | ||||||
|         self.run_test2(settrace_and_raise) |         self.run_test2(settrace_and_raise) | ||||||
| 
 | 
 | ||||||
|  | class RaisingTraceFuncTestCase(unittest.TestCase): | ||||||
|  |     def test_it(self): | ||||||
|  |         def tr(frame, event, arg): | ||||||
|  |             raise ValueError # just something that isn't RuntimeError | ||||||
|  |         def f(): | ||||||
|  |             return 1 | ||||||
|  |         try: | ||||||
|  |             for i in xrange(sys.getrecursionlimit() + 1): | ||||||
|  |                 sys.settrace(tr) | ||||||
|  |                 try: | ||||||
|  |                     f() | ||||||
|  |                 except ValueError: | ||||||
|  |                     pass | ||||||
|  |                 else: | ||||||
|  |                     self.fail("exception not thrown!") | ||||||
|  |         except RuntimeError: | ||||||
|  |             self.fail("recursion counter not reset") | ||||||
|  |              | ||||||
|  | 
 | ||||||
| def test_main(): | def test_main(): | ||||||
|     test_support.run_unittest(TraceTestCase) |     test_support.run_unittest(TraceTestCase) | ||||||
|  |     test_support.run_unittest(RaisingTraceFuncTestCase) | ||||||
| 
 | 
 | ||||||
| if __name__ == "__main__": | if __name__ == "__main__": | ||||||
|     test_main() |     test_main() | ||||||
|  |  | ||||||
|  | @ -636,6 +636,8 @@ eval_frame(PyFrameObject *f) | ||||||
| 			if (call_trace(tstate->c_tracefunc, tstate->c_traceobj, | 			if (call_trace(tstate->c_tracefunc, tstate->c_traceobj, | ||||||
| 				       f, PyTrace_CALL, Py_None)) { | 				       f, PyTrace_CALL, Py_None)) { | ||||||
| 				/* Trace function raised an error */ | 				/* Trace function raised an error */ | ||||||
|  | 				--tstate->recursion_depth; | ||||||
|  | 				tstate->frame = f->f_back; | ||||||
| 				return NULL; | 				return NULL; | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  | @ -646,6 +648,8 @@ eval_frame(PyFrameObject *f) | ||||||
| 				       tstate->c_profileobj, | 				       tstate->c_profileobj, | ||||||
| 				       f, PyTrace_CALL, Py_None)) { | 				       f, PyTrace_CALL, Py_None)) { | ||||||
| 				/* Profile function raised an error */ | 				/* Profile function raised an error */ | ||||||
|  | 				--tstate->recursion_depth; | ||||||
|  | 				tstate->frame = f->f_back; | ||||||
| 				return NULL; | 				return NULL; | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Michael W. Hudson
						Michael W. Hudson