gh-146056: Fix TreeBuilder stack in xml.etree by vstinner · Pull Request #146062 · python/cpython
This is unrelated.
If rewrite this code to be more explicit or safe, I would write something like
PyObject *last = self->last; PyObject *last_for_tail = self->last_for_tail; PyObject *this = self->this; self->index--; self->this = Py_NewRef(PyList_GET_ITEM(self->stack, self->index)); self->last = Py_NewRef(this); self->last_for_tail = Py_NewRef(this); Py_DECREF(last); Py_XDECREF(last_for_tail); if (treebuilder_append_event(self, self->end_event_obj, this) < 0) { Py_DECREF(this); return NULL; } return this;
But we should also look a the other ends -- how these attributes are set in other code in this file. This is a separate issue.