diff options
author | Brandt Bucher <brandtbucher@gmail.com> | 2020-12-07 20:08:24 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-07 20:08:24 (GMT) |
commit | 7c797982383ebfd9cca39c480dcf6132979dd06f (patch) | |
tree | df4adc3932cda7a6f21bb71a366541c933d0d23b /Python | |
parent | ca52aa3ddd949ce2d259b4263344339b56db00b7 (diff) | |
download | cpython-7c797982383ebfd9cca39c480dcf6132979dd06f.zip cpython-7c797982383ebfd9cca39c480dcf6132979dd06f.tar.gz cpython-7c797982383ebfd9cca39c480dcf6132979dd06f.tar.bz2 |
bpo-42536: GC track recycled tuples (GH-23623) (GH-23652)
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 226a012d1cd61f42ecd3056c554922f359a1a35d)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/bltinmodule.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index e42d5f2..3767f55 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -4,6 +4,7 @@ #include <ctype.h> #include "ast.h" #undef Yield /* undefine macro conflicting with <winbase.h> */ +#include "pycore_object.h" // _PyObject_GC_TRACK() #include "pycore_pystate.h" #include "pycore_tupleobject.h" @@ -2618,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) |