Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6e7740c

Browse files
committed
apply a fix for #3611 where the current exception context was deleted with a generator causing a segfault
1 parent 41e3667 commit 6e7740c

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

Lib/test/test_exceptions.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,28 @@ def __del__(self):
564564
pass
565565
self.assertEquals(e, (None, None, None))
566566

567+
def test_3118(self):
568+
def gen():
569+
try:
570+
yield 1
571+
finally:
572+
pass
573+
574+
def f():
575+
g = gen()
576+
next(g)
577+
try:
578+
try:
579+
raise ValueError
580+
except:
581+
del g
582+
raise KeyError
583+
except Exception as e:
584+
self.assert_(isinstance(e.__context__, ValueError))
585+
586+
f()
587+
588+
567589
def test_badisinstance(self):
568590
# Bug #2542: if issubclass(e, MyException) raises an exception,
569591
# it should be ignored

Python/ceval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2453,7 +2453,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
24532453

24542454
if (b->b_type == EXCEPT_HANDLER) {
24552455
UNWIND_EXCEPT_HANDLER(b);
2456-
if (why == WHY_EXCEPTION) {
2456+
if (why == WHY_EXCEPTION && !throwflag) {
24572457
Py_CLEAR(tstate->exc_type);
24582458
Py_CLEAR(tstate->exc_value);
24592459
Py_CLEAR(tstate->exc_traceback);

0 commit comments

Comments
 (0)