Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions Lib/test/test_marshal.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ def f():
code = f.__code__
a = []
code = code.replace(co_consts=code.co_consts + (a,))
# This test creates a reference loop which leads to reference leaks,
# so we need to break the loop manually. See gh-148722.
self.addCleanup(a.clear)
a.append(code)
for v in range(marshal.version + 1):
self.assertRaises(ValueError, marshal.dumps, code, v)
Expand Down Expand Up @@ -410,10 +413,12 @@ def test_loads_abnormal_reference_loops(self):
self.assertIs(a[0][None], a)

# Direct self-reference which cannot be created in Python.
data = b'\xa8\x01\x00\x00\x00r\x00\x00\x00\x00' # (<R>,)
a = marshal.loads(data)
self.assertIsInstance(a, tuple)
self.assertIs(a[0], a)
# This creates a reference loop which cannot be collected.
if False:
data = b'\xa8\x01\x00\x00\x00r\x00\x00\x00\x00' # (<R>,)
a = marshal.loads(data)
self.assertIsInstance(a, tuple)
self.assertIs(a[0], a)

# Direct self-references which cannot be created in Python
# because of unhashability.
Expand Down
Loading