mirror of
https://github.com/python/cpython.git
synced 2026-04-14 07:41:00 +00:00
gh-146056: Rework ref counting in treebuilder_handle_end() (#146167)
Use more regular code to handle reference counting in treebuilder_handle_end(). Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
fb8d8d9c9f
commit
90f9991abb
1 changed files with 11 additions and 8 deletions
|
|
@ -2840,8 +2840,6 @@ treebuilder_handle_data(TreeBuilderObject* self, PyObject* data)
|
|||
LOCAL(PyObject*)
|
||||
treebuilder_handle_end(TreeBuilderObject* self, PyObject* tag)
|
||||
{
|
||||
PyObject* item;
|
||||
|
||||
if (treebuilder_flush_data(self) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -2854,17 +2852,22 @@ treebuilder_handle_end(TreeBuilderObject* self, PyObject* tag)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
item = self->last;
|
||||
self->last = Py_NewRef(self->this);
|
||||
Py_XSETREF(self->last_for_tail, self->last);
|
||||
PyObject *last = self->last;
|
||||
PyObject *last_for_tail = self->last_for_tail;
|
||||
PyObject *this = self->this;
|
||||
self->last = Py_NewRef(this);
|
||||
self->last_for_tail = Py_NewRef(this);
|
||||
self->index--;
|
||||
self->this = Py_NewRef(PyList_GET_ITEM(self->stack, self->index));
|
||||
Py_DECREF(item);
|
||||
Py_DECREF(last);
|
||||
Py_XDECREF(last_for_tail);
|
||||
|
||||
if (treebuilder_append_event(self, self->end_event_obj, self->last) < 0)
|
||||
if (treebuilder_append_event(self, self->end_event_obj, self->last) < 0) {
|
||||
Py_DECREF(this);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return Py_NewRef(self->last);
|
||||
return this;
|
||||
}
|
||||
|
||||
LOCAL(PyObject*)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue