From 0c17d0d96e9684e29a731227452355da79b14b5b Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sat, 20 Aug 2011 14:01:05 +0200 Subject: Issue #12326: sys.platform is now always 'linux2' on Linux Even if Python is compiled on Linux 3. --- Misc/NEWS | 3 +++ configure | 1 + configure.in | 1 + 3 files changed, 5 insertions(+) diff --git a/Misc/NEWS b/Misc/NEWS index a62b485..a4251e3 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -16,6 +16,9 @@ Core and Builtins Library ------- +- Issue #12326: sys.platform is now always 'linux2' on Linux, even if Python + is compiled on Linux 3. + - Issue #12650: Fix a race condition where a subprocess.Popen could leak resources (FD/zombie) when killed at the wrong time. diff --git a/configure b/configure index 508ae34..9d85e35 100755 --- a/configure +++ b/configure @@ -2997,6 +2997,7 @@ then MACHDEP="$ac_md_system$ac_md_release" case $MACHDEP in + linux*) MACHDEP="linux2";; cygwin*) MACHDEP="cygwin";; darwin*) MACHDEP="darwin";; irix646) MACHDEP="irix6";; diff --git a/configure.in b/configure.in index c4ad4e8..3e60d8e 100644 --- a/configure.in +++ b/configure.in @@ -290,6 +290,7 @@ then MACHDEP="$ac_md_system$ac_md_release" case $MACHDEP in + linux*) MACHDEP="linux2";; cygwin*) MACHDEP="cygwin";; darwin*) MACHDEP="darwin";; irix646) MACHDEP="irix6";; -- cgit v0.12 From a370fcf3b2211242c888558237557eb4895391d0 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sat, 20 Aug 2011 14:15:03 +0200 Subject: Issue #12791: Break reference cycles early when a generator exits with an exception. --- Lib/test/test_exceptions.py | 62 +++++++++++++++++++++++++++++++++++++++++++++ Misc/NEWS | 3 +++ Objects/genobject.c | 11 ++++++++ 3 files changed, 76 insertions(+) diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 46ddc82..d3c0062 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -607,6 +607,68 @@ class ExceptionTests(unittest.TestCase): gc_collect() self.assertEqual(sys.exc_info(), (None, None, None)) + def _check_generator_cleanup_exc_state(self, testfunc): + # Issue #12791: exception state is cleaned up as soon as a generator + # is closed (reference cycles are broken). + class MyException(Exception): + def __init__(self, obj): + self.obj = obj + class MyObj: + pass + + def raising_gen(): + try: + raise MyException(obj) + except MyException: + yield + + obj = MyObj() + wr = weakref.ref(obj) + g = raising_gen() + next(g) + testfunc(g) + g = obj = None + obj = wr() + self.assertIs(obj, None) + + def test_generator_throw_cleanup_exc_state(self): + def do_throw(g): + try: + g.throw(RuntimeError()) + except RuntimeError: + pass + self._check_generator_cleanup_exc_state(do_throw) + + def test_generator_close_cleanup_exc_state(self): + def do_close(g): + g.close() + self._check_generator_cleanup_exc_state(do_close) + + def test_generator_del_cleanup_exc_state(self): + def do_del(g): + g = None + self._check_generator_cleanup_exc_state(do_del) + + def test_generator_next_cleanup_exc_state(self): + def do_next(g): + try: + next(g) + except StopIteration: + pass + else: + self.fail("should have raised StopIteration") + self._check_generator_cleanup_exc_state(do_next) + + def test_generator_send_cleanup_exc_state(self): + def do_send(g): + try: + g.send(None) + except StopIteration: + pass + else: + self.fail("should have raised StopIteration") + self._check_generator_cleanup_exc_state(do_send) + def test_3114(self): # Bug #3114: in its destructor, MyObject retrieves a pointer to # obsolete and/or deallocated objects. diff --git a/Misc/NEWS b/Misc/NEWS index a4251e3..f8c135f 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ What's New in Python 3.2.3? Core and Builtins ----------------- +- Issue #12791: Break reference cycles early when a generator exits with + an exception. + - Issue #12266: Fix str.capitalize() to correctly uppercase/lowercase titlecased and cased non-letter characters. diff --git a/Objects/genobject.c b/Objects/genobject.c index 3fa1b4e..01cd44a 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -100,6 +100,17 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc) if (!result || f->f_stacktop == NULL) { /* generator can't be rerun, so release the frame */ + /* first clean reference cycle through stored exception traceback */ + PyObject *t, *v, *tb; + t = f->f_exc_type; + v = f->f_exc_value; + tb = f->f_exc_traceback; + f->f_exc_type = NULL; + f->f_exc_value = NULL; + f->f_exc_traceback = NULL; + Py_XDECREF(t); + Py_XDECREF(v); + Py_XDECREF(tb); Py_DECREF(f); gen->gi_frame = NULL; } -- cgit v0.12