Discussion:
[Python-3000-checkins] r65921 - in python/branches/py3k: Lib/test/test_exceptions.py Python/ceval.c
benjamin.peterson
2008-08-20 23:23:35 UTC
Permalink
Author: benjamin.peterson
Date: Thu Aug 21 01:23:34 2008
New Revision: 65921

Log:
apply a fix for #3611 where the current exception context was deleted with a generator causing a segfault

Modified:
python/branches/py3k/Lib/test/test_exceptions.py
python/branches/py3k/Python/ceval.c

Modified: python/branches/py3k/Lib/test/test_exceptions.py
==============================================================================
--- python/branches/py3k/Lib/test/test_exceptions.py (original)
+++ python/branches/py3k/Lib/test/test_exceptions.py Thu Aug 21 01:23:34 2008
@@ -564,6 +564,28 @@
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

Modified: python/branches/py3k/Python/ceval.c
==============================================================================
--- python/branches/py3k/Python/ceval.c (original)
+++ python/branches/py3k/Python/ceval.c Thu Aug 21 01:23:34 2008
@@ -2453,7 +2453,7 @@

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);

Loading...