Skip to content

Commit deddeb5

Browse files
Allow deallocating an empty tuple if a subclass.
1 parent 5e729d8 commit deddeb5

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Objects/tupleobject.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,13 @@ PyTuple_Pack(Py_ssize_t n, ...)
222222
static void
223223
tupledealloc(PyTupleObject *op)
224224
{
225+
/* The empty tuple is statically allocated. */
225226
if ((PyObject *)op == tuple_get_empty()) {
226227
return;
227228
}
228229
Py_ssize_t len = Py_SIZE(op);
229-
/* The empty tuple is statically allocated. */
230-
assert(len > 0);
230+
/* tuple subclasses have their own empty instances. */
231+
assert(len > 0 || !PyTuple_CheckExact(op));
231232
PyObject_GC_UnTrack(op);
232233
Py_TRASHCAN_BEGIN(op, tupledealloc)
233234

@@ -788,6 +789,7 @@ tuple_subtype_new(PyTypeObject *type, PyObject *iterable)
788789
if (tmp == NULL)
789790
return NULL;
790791
assert(PyTuple_Check(tmp));
792+
/* This may allocate an empty tuple that is not the global one. */
791793
newobj = type->tp_alloc(type, n = PyTuple_GET_SIZE(tmp));
792794
if (newobj == NULL) {
793795
Py_DECREF(tmp);

0 commit comments

Comments
 (0)