Skip to content

Commit 44c5447

Browse files
Store state in TreeBuilderObject context
1 parent 13e36d9 commit 44c5447

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Modules/_elementtree.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2291,6 +2291,7 @@ typedef struct {
22912291

22922292
char insert_comments;
22932293
char insert_pis;
2294+
elementtreestate *state;
22942295
} TreeBuilderObject;
22952296

22962297
#define TreeBuilder_CheckExact(st, op) Py_IS_TYPE((op), (st)->TreeBuilder_Type)
@@ -2324,6 +2325,7 @@ treebuilder_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
23242325
t->start_ns_event_obj = t->end_ns_event_obj = NULL;
23252326
t->comment_event_obj = t->pi_event_obj = NULL;
23262327
t->insert_comments = t->insert_pis = 0;
2328+
t->state = ET_STATE_GLOBAL;
23272329
}
23282330
return (PyObject *)t;
23292331
}
@@ -2355,7 +2357,7 @@ _elementtree_TreeBuilder___init___impl(TreeBuilderObject *self,
23552357
}
23562358

23572359
if (comment_factory == Py_None) {
2358-
elementtreestate *st = ET_STATE_GLOBAL;
2360+
elementtreestate *st = self->state;
23592361
comment_factory = st->comment_factory;
23602362
}
23612363
if (comment_factory) {
@@ -2549,7 +2551,7 @@ treebuilder_flush_data(TreeBuilderObject* self)
25492551
if (!self->data) {
25502552
return 0;
25512553
}
2552-
elementtreestate *st = ET_STATE_GLOBAL;
2554+
elementtreestate *st = self->state;
25532555
if (!self->last_for_tail) {
25542556
PyObject *element = self->last;
25552557
return treebuilder_extend_element_text_or_tail(
@@ -2609,7 +2611,7 @@ treebuilder_handle_start(TreeBuilderObject* self, PyObject* tag,
26092611
{
26102612
PyObject* node;
26112613
PyObject* this;
2612-
elementtreestate *st = ET_STATE_GLOBAL;
2614+
elementtreestate *st = self->state;
26132615

26142616
if (treebuilder_flush_data(self) < 0) {
26152617
return NULL;

0 commit comments

Comments
 (0)