-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
gh-146056: Fix TreeBuilder stack in xml.etree #146062
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2431,7 +2431,7 @@ treebuilder_new(PyTypeObject *type, PyObject *args, PyObject *kwds) | |
| t->element_factory = NULL; | ||
| t->comment_factory = NULL; | ||
| t->pi_factory = NULL; | ||
| t->stack = PyList_New(20); | ||
| t->stack = PyList_New(0); | ||
| if (!t->stack) { | ||
| Py_DECREF(t->this); | ||
| Py_DECREF(t->last); | ||
|
|
@@ -2856,9 +2856,9 @@ treebuilder_handle_end(TreeBuilderObject* self, PyObject* tag) | |
|
|
||
| item = self->last; | ||
| self->last = Py_NewRef(self->this); | ||
| Py_XSETREF(self->last_for_tail, self->last); | ||
| Py_XSETREF(self->last_for_tail, Py_NewRef(self->last)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wrote #146167 which uses your suggestion. |
||
| self->index--; | ||
| self->this = Py_NewRef(PyList_GET_ITEM(self->stack, self->index)); | ||
| Py_SETREF(self->this, Py_NewRef(PyList_GET_ITEM(self->stack, self->index))); | ||
| Py_DECREF(item); | ||
|
|
||
| if (treebuilder_append_event(self, self->end_event_obj, self->last) < 0) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can have performance impact.