Skip to content

Commit 597adb0

Browse files
committed
Revert using a tuple directly
1 parent 7c81286 commit 597adb0

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

Python/ceval.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ _PyEval_MatchClass(PyThreadState *tstate, PyObject *subject, PyObject *type,
757757
return NULL;
758758
}
759759
}
760-
PyObject *attrs = PyTuple_New(nattrs);
760+
PyObject *attrs = PyList_New(0);
761761
if (attrs == NULL) {
762762
Py_XDECREF(seen);
763763
return NULL;
@@ -800,7 +800,9 @@ _PyEval_MatchClass(PyThreadState *tstate, PyObject *subject, PyObject *type,
800800
}
801801
if (match_self) {
802802
// Easy. Copy the subject itself, and move on to kwargs.
803-
PyTuple_SET_ITEM(attrs, 0, subject);
803+
if (PyList_Append(attrs, subject) < 0) {
804+
goto fail;
805+
}
804806
}
805807
else {
806808
for (Py_ssize_t i = 0; i < nargs; i++) {
@@ -816,7 +818,11 @@ _PyEval_MatchClass(PyThreadState *tstate, PyObject *subject, PyObject *type,
816818
if (attr == NULL) {
817819
goto fail;
818820
}
819-
PyTuple_SET_ITEM(attrs, i, attr);
821+
if (PyList_Append(attrs, attr) < 0) {
822+
Py_DECREF(attr);
823+
goto fail;
824+
}
825+
Py_DECREF(attr);
820826
}
821827
}
822828
Py_CLEAR(match_args);
@@ -828,8 +834,13 @@ _PyEval_MatchClass(PyThreadState *tstate, PyObject *subject, PyObject *type,
828834
if (attr == NULL) {
829835
goto fail;
830836
}
831-
PyTuple_SET_ITEM(attrs, nargs + i, attr);
837+
if (PyList_Append(attrs, attr) < 0) {
838+
Py_DECREF(attr);
839+
goto fail;
840+
}
841+
Py_DECREF(attr);
832842
}
843+
Py_SETREF(attrs, PyList_AsTuple(attrs));
833844
Py_XDECREF(seen);
834845
return attrs;
835846
fail:

0 commit comments

Comments
 (0)