summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@gmail.com>2020-12-07 20:07:48 (GMT)
committerGitHub <noreply@github.com>2020-12-07 20:07:48 (GMT)
commit60463e8e4f79e5b5e96dc43fb83ded373b489e33 (patch)
treea396c7ee5d9b3db595fac4980fc0700e4fe8a2e9 /Python
parente9a6dcdefabb6c19074566f4ee0e02daaf57be18 (diff)
downloadcpython-60463e8e4f79e5b5e96dc43fb83ded373b489e33.zip
cpython-60463e8e4f79e5b5e96dc43fb83ded373b489e33.tar.gz
cpython-60463e8e4f79e5b5e96dc43fb83ded373b489e33.tar.bz2
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 226a012d1cd61f42ecd3056c554922f359a1a35d)
Diffstat (limited to 'Python')
-rw-r--r--Python/bltinmodule.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 199b09c..614012d 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -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)