summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2020-03-02 23:55:20 (GMT)
committerGitHub <noreply@github.com>2020-03-02 23:55:20 (GMT)
commit9ddcb914f9c2debe7c1359b2450cd1573e86b91c (patch)
tree1967dd5ab55fd5eab0193f042481ec054c655684 /Lib/test
parent7ad99821d8ae75222c50e69194a39f535bb058f5 (diff)
downloadcpython-9ddcb914f9c2debe7c1359b2450cd1573e86b91c.zip
cpython-9ddcb914f9c2debe7c1359b2450cd1573e86b91c.tar.gz
cpython-9ddcb914f9c2debe7c1359b2450cd1573e86b91c.tar.bz2
[3.8] bpo-39778: Don't traverse weak-reference lists OrderedDict's tp_traverse and tp_clear (GH-18749) (GH-18756)
Objects do not own weak references to them directly through the __weakref__ list so these do not need to be traversed by the GC. (cherry picked from commit 0c2b509)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_ordered_dict.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_ordered_dict.py b/Lib/test/test_ordered_dict.py
index 148a9bd..085e5f6 100644
--- a/Lib/test/test_ordered_dict.py
+++ b/Lib/test/test_ordered_dict.py
@@ -753,6 +753,26 @@ class CPythonOrderedDictTests(OrderedDictTests, unittest.TestCase):
self.assertEqual(list(unpickled), expected)
self.assertEqual(list(it), expected)
+ @support.cpython_only
+ def test_weakref_list_is_not_traversed(self):
+ # Check that the weakref list is not traversed when collecting
+ # OrderedDict objects. See bpo-39778 for more information.
+
+ gc.collect()
+
+ x = self.OrderedDict()
+ x.cycle = x
+
+ cycle = []
+ cycle.append(cycle)
+
+ x_ref = weakref.ref(x)
+ cycle.append(x_ref)
+
+ del x, cycle, x_ref
+
+ gc.collect()
+
class PurePythonOrderedDictSubclassTests(PurePythonOrderedDictTests):