From fb4d6ecd0757c0863b8a2e45a57a6dfec13fbff6 Mon Sep 17 00:00:00 2001 From: "Michael W. Hudson" Date: Wed, 2 Oct 2002 13:13:45 +0000 Subject: [PATCH] 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 ;-). --- Lib/test/test_trace.py | 20 ++++++++++++++++++++ Python/ceval.c | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/Lib/test/test_trace.py b/Lib/test/test_trace.py index 314801d8bd1..91112e8b211 100644 --- a/Lib/test/test_trace.py +++ b/Lib/test/test_trace.py @@ -177,8 +177,28 @@ def test_8_settrace_and_return(self): def test_9_settrace_and_raise(self): 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(): test_support.run_unittest(TraceTestCase) + test_support.run_unittest(RaisingTraceFuncTestCase) if __name__ == "__main__": test_main() diff --git a/Python/ceval.c b/Python/ceval.c index 362cd0bce70..493043303e8 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -636,6 +636,8 @@ eval_frame(PyFrameObject *f) if (call_trace(tstate->c_tracefunc, tstate->c_traceobj, f, PyTrace_CALL, Py_None)) { /* Trace function raised an error */ + --tstate->recursion_depth; + tstate->frame = f->f_back; return NULL; } } @@ -646,6 +648,8 @@ eval_frame(PyFrameObject *f) tstate->c_profileobj, f, PyTrace_CALL, Py_None)) { /* Profile function raised an error */ + --tstate->recursion_depth; + tstate->frame = f->f_back; return NULL; } }