summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_collections.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-11-01 14:12:34 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-11-01 14:12:34 (GMT)
commit14eefe353e3f251bce0bc7ed3415f78c17174d94 (patch)
treee809c04903624a9caf6a3a8f1b8024b73423f625 /Lib/test/test_collections.py
parent964ec8b2f3bb893ad34d874e55a180a90330bde2 (diff)
downloadcpython-14eefe353e3f251bce0bc7ed3415f78c17174d94.zip
cpython-14eefe353e3f251bce0bc7ed3415f78c17174d94.tar.gz
cpython-14eefe353e3f251bce0bc7ed3415f78c17174d94.tar.bz2
Issue #25395: Fixed crash when highly nested OrderedDict structures were
garbage collected.
Diffstat (limited to 'Lib/test/test_collections.py')
-rw-r--r--Lib/test/test_collections.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index 3ed3abdf..53a3ae4 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -2025,6 +2025,30 @@ class OrderedDictTests:
items = [('a', 1), ('c', 3), ('b', 2)]
self.assertEqual(list(MyOD(items).items()), items)
+ def test_highly_nested(self):
+ # Issue 25395: crashes during garbage collection
+ OrderedDict = self.module.OrderedDict
+ obj = None
+ for _ in range(1000):
+ obj = OrderedDict([(None, obj)])
+ del obj
+ support.gc_collect()
+
+ def test_highly_nested_subclass(self):
+ # Issue 25395: crashes during garbage collection
+ OrderedDict = self.module.OrderedDict
+ deleted = []
+ class MyOD(OrderedDict):
+ def __del__(self):
+ deleted.append(self.i)
+ obj = None
+ for i in range(100):
+ obj = MyOD([(None, obj)])
+ obj.i = i
+ del obj
+ support.gc_collect()
+ self.assertEqual(deleted, list(reversed(range(100))))
+
class PurePythonOrderedDictTests(OrderedDictTests, unittest.TestCase):