mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +00:00
bpo-42536: GC track recycled tuples (GH-23623) (GH-23651)
Several built-in and standard library types now ensure that their internal result tuples are always tracked by the garbage collector:
- collections.OrderedDict.items
- dict.items
- enumerate
- functools.reduce
- itertools.combinations
- itertools.combinations_with_replacement
- itertools.permutations
- itertools.product
- itertools.zip_longest
- zip
Previously, they could have become untracked by a prior garbage collection.
(cherry picked from commit 226a012d1c
)
This commit is contained in:
parent
e9a6dcdefa
commit
60463e8e4f
12 changed files with 192 additions and 0 deletions
|
@ -2619,6 +2619,11 @@ zip_next(zipobject *lz)
|
|||
PyTuple_SET_ITEM(result, i, item);
|
||||
Py_DECREF(olditem);
|
||||
}
|
||||
// bpo-42536: The GC may have untracked this result tuple. Since we're
|
||||
// recycling it, make sure it's tracked again:
|
||||
if (!_PyObject_GC_IS_TRACKED(result)) {
|
||||
_PyObject_GC_TRACK(result);
|
||||
}
|
||||
} else {
|
||||
result = PyTuple_New(tuplesize);
|
||||
if (result == NULL)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue