summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-10-28 23:06:57 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-10-28 23:06:57 (GMT)
commit98e2b452975f13b13052aeb9d166ed8a3ef45063 (patch)
tree2d7ee32804bc590346f62f45bcb1e46b0221f90b /Lib
parentd7a3ab962bb773258ad1906c26af1ca75ed7daf7 (diff)
downloadcpython-98e2b452975f13b13052aeb9d166ed8a3ef45063.zip
cpython-98e2b452975f13b13052aeb9d166ed8a3ef45063.tar.gz
cpython-98e2b452975f13b13052aeb9d166ed8a3ef45063.tar.bz2
Merged revisions 85896 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r85896 | antoine.pitrou | 2010-10-29 00:56:58 +0200 (ven., 29 oct. 2010) | 4 lines Issue #5437: A preallocated MemoryError instance should not hold traceback data (including local variables caught in the stack trace) alive infinitely. ........
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_exceptions.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index b10835d..41e3d44 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -669,6 +669,46 @@ class ExceptionTests(unittest.TestCase):
tb2 = raiseMemError()
self.assertEqual(tb1, tb2)
+ def test_memory_error_cleanup(self):
+ # Issue #5437: preallocated MemoryError instances should not keep
+ # traceback objects alive.
+ from _testcapi import raise_memoryerror
+ class C:
+ pass
+ wr = None
+ def inner():
+ nonlocal wr
+ c = C()
+ wr = weakref.ref(c)
+ raise_memoryerror()
+ # We cannot use assertRaises since it manually deletes the traceback
+ try:
+ inner()
+ except MemoryError as e:
+ self.assertNotEqual(wr(), None)
+ else:
+ self.fail("MemoryError not raised")
+ self.assertEqual(wr(), None)
+
+ def test_recursion_error_cleanup(self):
+ # Same test as above, but with "recursion exceeded" errors
+ class C:
+ pass
+ wr = None
+ def inner():
+ nonlocal wr
+ c = C()
+ wr = weakref.ref(c)
+ inner()
+ # We cannot use assertRaises since it manually deletes the traceback
+ try:
+ inner()
+ except RuntimeError as e:
+ self.assertNotEqual(wr(), None)
+ else:
+ self.fail("RuntimeError not raised")
+ self.assertEqual(wr(), None)
+
def test_main():
run_unittest(ExceptionTests)