Skip to content

Commit fbb7342

Browse files
Do not track immutable tuples in PyTuple_Pack
1 parent 48d0d0d commit fbb7342

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Objects/tupleobject.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,18 @@ PyTuple_Pack(Py_ssize_t n, ...)
175175
return NULL;
176176
}
177177
items = result->ob_item;
178+
bool track = false;
178179
for (i = 0; i < n; i++) {
179180
o = va_arg(vargs, PyObject *);
180181
items[i] = Py_NewRef(o);
182+
if (!track && _PyObject_GC_MAY_BE_TRACKED(items[i])) {
183+
track = true;
184+
}
181185
}
182186
va_end(vargs);
183-
_PyObject_GC_TRACK(result);
187+
if (track) {
188+
_PyObject_GC_TRACK(result);
189+
}
184190
return (PyObject *)result;
185191
}
186192

0 commit comments

Comments
 (0)