[Python-checkins] r78766 - in python/branches/py3k: Lib/test/test_exceptions.py Misc/NEWS Python/ceval.c
benjamin.peterson
python-checkins at python.org
Sun Mar 7 18:10:51 CET 2010
Author: benjamin.peterson
Date: Sun Mar 7 18:10:51 2010
New Revision: 78766
Log:
prevent generator finalization from invalidating sys.exc_info() #7173
Modified:
python/branches/py3k/Lib/test/test_exceptions.py
python/branches/py3k/Misc/NEWS
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 Sun Mar 7 18:10:51 2010
@@ -6,7 +6,8 @@
import pickle
import weakref
-from test.support import TESTFN, unlink, run_unittest, captured_output
+from test.support import (TESTFN, unlink, run_unittest, captured_output,
+ gc_collect)
# XXX This is not really enough, each *operation* should be tested!
@@ -554,6 +555,20 @@
del g
self.assertEquals(sys.exc_info()[0], TypeError)
+ def test_generator_finalizing_and_exc_info(self):
+ # See #7173
+ def simple_gen():
+ yield 1
+ def run_gen():
+ gen = simple_gen()
+ try:
+ raise RuntimeError
+ except RuntimeError:
+ return next(gen)
+ run_gen()
+ gc_collect()
+ self.assertEqual(sys.exc_info(), (None, None, None))
+
def test_3114(self):
# Bug #3114: in its destructor, MyObject retrieves a pointer to
# obsolete and/or deallocated objects.
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS (original)
+++ python/branches/py3k/Misc/NEWS Sun Mar 7 18:10:51 2010
@@ -12,6 +12,8 @@
Core and Builtins
-----------------
+- Issue #7173: Generator finalization could invalidate sys.exc_info().
+
- Issue #7544: Preallocate thread memory before creating the thread to avoid
a fatal error in low memory condition.
Modified: python/branches/py3k/Python/ceval.c
==============================================================================
--- python/branches/py3k/Python/ceval.c (original)
+++ python/branches/py3k/Python/ceval.c Sun Mar 7 18:10:51 2010
@@ -1159,7 +1159,7 @@
assert(stack_pointer != NULL);
f->f_stacktop = NULL; /* remains NULL unless yield suspends frame */
- if (f->f_code->co_flags & CO_GENERATOR) {
+ if (co->co_flags & CO_GENERATOR && !throwflag) {
if (f->f_exc_type != NULL && f->f_exc_type != Py_None) {
/* We were in an except handler when we left,
restore the exception state which was put aside
More information about the Python-checkins
mailing list