summaryrefslogtreecommitdiffstats
path: root/Objects/enumobject.c
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@gmail.com>2020-12-05 03:45:57 (GMT)
committerGitHub <noreply@github.com>2020-12-05 03:45:57 (GMT)
commit226a012d1cd61f42ecd3056c554922f359a1a35d (patch)
tree86407049a5d2c22b0ce8626407ca106eb3c26afd /Objects/enumobject.c
parent2de5097ba4c50eba90df55696a7b2e74c93834d4 (diff)
downloadcpython-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/enumobject.c')
-rw-r--r--Objects/enumobject.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/Objects/enumobject.c b/Objects/enumobject.c
index 8b5e7d3..98ece3f 100644
--- a/Objects/enumobject.c
+++ b/Objects/enumobject.c
@@ -2,6 +2,7 @@
#include "Python.h"
#include "pycore_long.h" // _PyLong_GetOne()
+#include "pycore_object.h" // _PyObject_GC_TRACK()
#include "clinic/enumobject.c.h"
@@ -131,6 +132,11 @@ enum_next_long(enumobject *en, PyObject* next_item)
PyTuple_SET_ITEM(result, 1, next_item);
Py_DECREF(old_index);
Py_DECREF(old_item);
+ // 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);
+ }
return result;
}
result = PyTuple_New(2);
@@ -176,6 +182,11 @@ enum_next(enumobject *en)
PyTuple_SET_ITEM(result, 1, next_item);
Py_DECREF(old_index);
Py_DECREF(old_item);
+ // 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);
+ }
return result;
}
result = PyTuple_New(2);