diff options
author | Brandt Bucher <brandtbucher@gmail.com> | 2020-12-05 03:45:57 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-05 03:45:57 (GMT) |
commit | 226a012d1cd61f42ecd3056c554922f359a1a35d (patch) | |
tree | 86407049a5d2c22b0ce8626407ca106eb3c26afd /Objects/odictobject.c | |
parent | 2de5097ba4c50eba90df55696a7b2e74c93834d4 (diff) | |
download | cpython-226a012d1cd61f42ecd3056c554922f359a1a35d.zip cpython-226a012d1cd61f42ecd3056c554922f359a1a35d.tar.gz cpython-226a012d1cd61f42ecd3056c554922f359a1a35d.tar.bz2 |
bpo-42536: GC track recycled tuples (GH-23623)
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.
Diffstat (limited to 'Objects/odictobject.c')
-rw-r--r-- | Objects/odictobject.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/Objects/odictobject.c b/Objects/odictobject.c index 4eb15f9..6c7f117 100644 --- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -1814,6 +1814,11 @@ odictiter_iternext(odictiterobject *di) Py_INCREF(result); Py_DECREF(PyTuple_GET_ITEM(result, 0)); /* borrowed */ Py_DECREF(PyTuple_GET_ITEM(result, 1)); /* borrowed */ + // 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(2); |