From 6e7740c790bf41f520e304ec17abf79a5373b5cc Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Wed, 20 Aug 2008 23:23:34 +0000 Subject: apply a fix for #3611 where the current exception context was deleted with a generator causing a segfault --- Lib/test/test_exceptions.py | 22 ++++++++++++++++++++++ Python/ceval.c | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 5ce76f1..6075b8d 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -564,6 +564,28 @@ class ExceptionTests(unittest.TestCase): pass self.assertEquals(e, (None, None, None)) + def test_3118(self): + def gen(): + try: + yield 1 + finally: + pass + + def f(): + g = gen() + next(g) + try: + try: + raise ValueError + except: + del g + raise KeyError + except Exception as e: + self.assert_(isinstance(e.__context__, ValueError)) + + f() + + def test_badisinstance(self): # Bug #2542: if issubclass(e, MyException) raises an exception, # it should be ignored diff --git a/Python/ceval.c b/Python/ceval.c index 40ce038..3af0cef 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -2453,7 +2453,7 @@ fast_block_end: if (b->b_type == EXCEPT_HANDLER) { UNWIND_EXCEPT_HANDLER(b); - if (why == WHY_EXCEPTION) { + if (why == WHY_EXCEPTION && !throwflag) { Py_CLEAR(tstate->exc_type); Py_CLEAR(tstate->exc_value); Py_CLEAR(tstate->exc_traceback); -- cgit v0.12