8000 bpo-42536: GC track recycled tuples by brandtbucher · Pull Request #23623 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-42536: GC track recycled tuples #23623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Dec 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Replace single-character names
  • Loading branch information
brandtbucher committed Dec 4, 2020
commit 6ec236882a61a56b84ea41ea8c2b24768b6ea8ee
4 changes: 2 additions & 2 deletions Lib/test/test_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1762,12 +1762,12 @@ def test_zip_result_gc(self):
# bpo-42536: zip's tuple-reuse speed trick breaks the GC's assumptions
# about what can be untracked. Make sure we re-track result tuples
# whenever we reuse them.
z = zip([[]])
it = zip([[]])
gc.collect()
# That GC collection probably untracked the recycled internal result
# tuple, which is initialized to (None,). Make sure it's re-tracked when
# it's mutated and returned from __next__:
self.assertTrue(gc.is_tracked(next(z)))
self.assertTrue(gc.is_tracked(next(it)))

def test_format(self):
# Test the basic machinery of the format() builtin. Don't test
Expand Down
8 changes: 4 additions & 4 deletions Lib/test/test_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -1457,19 +1457,19 @@ def test_dict_items_result_gc(self):
# bpo-42536: dict.items's tuple-reuse speed trick breaks the GC's
# assumptions about what can be untracked. Make sure we re-track result
# tuples whenever we reuse them.
i = iter({None: []}.items())
it = iter({None: []}.items())
gc.collect()
# That GC collection probably untracked the recycled internal result
# tuple, which is initialized to (None, None). Make sure it's re-tracked
# when it's mutated and returned from __next__:
self.assertTrue(gc.is_tracked(next(i)))
self.assertTrue(gc.is_tracked(next(it)))

@support.cpython_only
def test_dict_items_result_gc(self):
# Same as test_dict_items_result_gc above, but reversed.
i = reversed({None: []}.items())
it = reversed({None: []}.items())
gc.collect()
self.assertTrue(gc.is_tracked(next(i)))
self.assertTrue(gc.is_tracked(next(it)))


class CAPITest(unittest.TestCase):
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_enumerate.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ def test_enumerate_result_gc(self):
# bpo-42536: enumerate's tuple-reuse speed trick breaks the GC's
# assumptions about what can be untracked. Make sure we re-track result
# tuples whenever we reuse them.
e = self.enum([[]])
it = self.enum([[]])
gc.collect()
# That GC collection probably untracked the recycled internal result
# tuple, which is initialized to (None, None). Make sure it's re-tracked
# when it's mutated and returned from __next__:
self.assertTrue(gc.is_tracked(next(e)))
self.assertTrue(gc.is_tracked(next(it)))

class MyEnum(enumerate):
pass
Expand Down
28 changes: 14 additions & 14 deletions Lib/test/test_itertools.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,13 @@ def test_combinations_result_gc(self):
# bpo-42536: combinations's tuple-reuse speed trick breaks the GC's
# assumptions about what can be untracked. Make sure we re-track result
# tuples whenever we reuse them.
c = combinations([None, []], 1)
next(c)
it = combinations([None, []], 1)
next(it)
gc.collect()
# That GC collection probably untracked the recycled internal result
# tuple, which has the value (None,). Make sure it's re-tracked when
# it's mutated and returned from __next__:
self.assertTrue(gc.is_tracked(next(c)))
self.assertTrue(gc.is_tracked(next(it)))

def test_combinations_with_replacement(self):
cwr = combinations_with_replacement
Expand Down Expand Up @@ -401,10 +401,10 @@ def test_combinations_with_replacement_tuple_reuse(self):
def test_combinations_with_replacement_result_gc(self):
# Same as test_combinations_result_gc above, but for
# combinations_with_replacement.
c = combinations_with_replacement([None, []], 1)
next(c)
it = combinations_with_replacement([None, []], 1)
next(it)
gc.collect()
self.assertTrue(gc.is_tracked(next(c)))
self.assertTrue(gc.is_tracked(next(it)))

def test_permutations(self):
self.assertRaises(TypeError, permutations) # too few arguments
Expand Down Expand Up @@ -482,10 +482,10 @@ def test_permutations_tuple_reuse(self):
@support.cpython_only
def test_permutations_result_gc(self):
# Same as test_combinations_result_gc above, but for permutations.
p = permutations([None, []], 1)
next(p)
it = permutations([None, []], 1)
next(it)
gc.collect()
self.assertTrue(gc.is_tracked(next(p)))
self.assertTrue(gc.is_tracked(next(it)))

def test_combinatorics(self):
# Test relationships between product(), permutations(),
Expand Down Expand Up @@ -1000,9 +1000,9 @@ def test_zip_longest_tuple_reuse(self):
@support.cpython_only
def test_zip_longest_result_gc(self):
# Same as test_combinations_result_gc above, but for zip_longest.
z = zip_longest([[]])
it = zip_longest([[]])
gc.collect()
self.assertTrue(gc.is_tracked(next(z)))
self.assertTrue(gc.is_tracked(next(it)))

def test_zip_longest_pickling(self):
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
Expand Down Expand Up @@ -1153,10 +1153,10 @@ def test_product_tuple_reuse(self):
@support.cpython_only
def test_product_result_gc(self):
# Same as test_combinations_result_gc above, but for product.
p = product([None, []])
next(p)
it = product([None, []])
next(it)
gc.collect()
self.assertTrue(gc.is_tracked(next(p)))
self.assertTrue(gc.is_tracked(next(it)))

def test_product_pickling(self):
# check copy, deepcopy, pickle
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_ordered_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,12 +705,12 @@ def test_ordered_dict_items_result_gc(self):
# bpo-42536: OrderedDict.items's tuple-reuse speed trick breaks the GC's
# assumptions about what can be untracked. Make sure we re-track result
# tuples whenever we reuse them.
i = iter(self.OrderedDict({None: []}).items())
it = iter(self.OrderedDict({None: []}).items())
gc.collect()
# That GC collection probably untracked the recycled internal result
# tuple, which is initialized to (None, None). Make sure it's re-tracked
# when it's mutated and returned from __next__:
self.assertTrue(gc.is_tracked(next(i)))
self.assertTrue(gc.is_tracked(next(it)))

class PurePythonOrderedDictTests(OrderedDictTests, unittest.TestCase):

Expand Down
0