Skip to content

Commit

Permalink
Store state in TreeBuilderObject context
Browse files Browse the repository at this point in the history
  • Loading branch information
erlend-aasland committed Jan 20, 2023
1 parent 13e36d9 commit 44c5447
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Modules/_elementtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -2291,6 +2291,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 @@ -2324,6 +2325,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 @@ -2355,7 +2357,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 @@ -2549,7 +2551,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 @@ -2609,7 +2611,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 comments on commit 44c5447

Please sign in to comment.