8000 GH-92123: Store _elementtree state in type contexts by erlend-aasland · Pull Request #101190 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-92123: Store _elementtree state in type contexts #101190

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

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
8000
Diff view
Next Next commit
Store state in TreeBuilderObject context
  • Loading branch information
erlend-aasland committed Jan 22, 2023
commit dd92ea20778d1dd9a2d7fa928e63b276d9eb19e8
8 changes: 5 additions & 3 deletions Modules/_elementtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -2289,6 +2289,7 @@ typedef struct {

char insert_comments;
char insert_pis;
elementtreestate *state;
} TreeBuilderObject;

#define TreeBuilder_CheckExact(st, op) Py_IS_TYPE((op), (st)->TreeBuilder_Type)
Expand Down Expand Up @@ -2322,6 +2323,7 @@ treebuilder_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
t->start_ns_event_obj = t->end_ns_event_obj = NULL;
t->comment_event_obj = t->pi_event_obj = NULL;
t->insert_comments = t->insert_pis = 0;
t->state = ET_STATE_GLOBAL;
}
return (PyObject *)t;
}
Expand Down Expand Up @@ -2353,7 +2355,7 @@ _elementtree_TreeBuilder___init___impl(TreeBuilderObject *self,
}

if (comment_factory == Py_None) {
elementtreestate *st = ET_STATE_GLOBAL;
elementtreestate *st = self->state;
comment_factory = st->comment_factory;
}
if (comment_factory) {
Expand Down Expand Up @@ -2547,7 +2549,7 @@ treebuilder_flush_data(TreeBuilderObject* self)
if (!self->data) {
return 0;
}
elementtreestate *st = ET_STATE_GLOBAL;
elementtreestate *st = self->state;
if (!self->last_for_tail) {
PyObject *element = self->last;
return treebuilder_extend_element_text_or_tail(
Expand Down Expand Up @@ -2607,7 +2609,7 @@ treebuilder_handle_start(TreeBuilderObject* self, PyObject* tag,
{
PyObject* node;
PyObject* this;
elementtreestate *st = ET_STATE_GLOBAL;
elementtreestate *st = self->state;

if (treebuilder_flush_data(self) < 0) {
return NULL;
Expand Down
0