Skip to content

Commit e30756d

Browse files
committed
remove versioning
1 parent 7fc9932 commit e30756d

File tree

1 file changed

+9
-23
lines changed

1 file changed

+9
-23
lines changed

Modules/_elementtree.c

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,6 @@ typedef struct {
229229
PyObject* *children;
230230

231231
PyObject* _children[STATIC_CHILDREN];
232-
233-
/* incremented whenever the object is externally mutated */
234-
size_t version;
235232
} ElementObjectExtra;
236233

237234
typedef struct {
@@ -281,8 +278,6 @@ create_extra(ElementObject* self, PyObject* attrib)
281278
self->extra->allocated = STATIC_CHILDREN;
282279
self->extra->children = self->extra->_children;
283280

284-
self->extra->version = 0;
285-
286281
return 0;
287282
}
288283

@@ -510,7 +505,6 @@ element_resize(ElementObject* self, Py_ssize_t extra)
510505
}
511506
self->extra->children = children;
512507
self->extra->allocated = size;
513-
self->extra->version++;
514508
}
515509

516510
return 0;
@@ -544,7 +538,6 @@ element_add_subelement(elementtreestate *st, ElementObject *self,
544538
self->extra->children[self->extra->length] = Py_NewRef(element);
545539

546540
self->extra->length++;
547-
self->extra->version++;
548541

549542
return 0;
550543
}
@@ -786,7 +779,6 @@ _elementtree_Element___copy___impl(ElementObject *self, PyTypeObject *cls)
786779

787780
assert(!element->extra->length);
788781
element->extra->length = self->extra->length;
789-
element->extra->version = self->extra->version;
790782
}
791783

792784
return (PyObject*) element;
@@ -870,7 +862,6 @@ _elementtree_Element___deepcopy___impl(ElementObject *self, PyObject *memo)
870862

871863
assert(!element->extra->length);
872864
element->extra->length = self->extra->length;
873-
element->extra->version = 0;
874865
}
875866

876867
/* add object to memo dictionary (so deepcopy won't visit it again) */
@@ -1557,7 +1548,6 @@ _elementtree_Element_insert_impl(ElementObject *self, Py_ssize_t index,
15571548
self->extra->children[index] = Py_NewRef(subelement);
15581549

15591550
self->extra->length++;
1560-
self->extra->version++;
15611551

15621552
Py_RETURN_NONE;
15631553
}
@@ -1648,17 +1638,17 @@ _elementtree_Element_remove_impl(ElementObject *self, PyObject *subelement)
16481638
}
16491639

16501640
Py_ssize_t i;
1651-
size_t old_version = self->extra->version;
1641+
const Py_ssize_t length = self->extra->length;
16521642
for (i = 0; self->extra && i < self->extra->length; i++) {
1653-
if (old_version != self->extra->version) {
1654-
goto fail;
1655-
}
1656-
else if (self->extra->children[i] == subelement) {
1643+
if (self->extra->children[i] == subelement) {
16571644
break;
16581645
}
16591646
PyObject *child = Py_NewRef(self->extra->children[i]);
16601647
int rc = PyObject_RichCompareBool(child, subelement, Py_EQ);
16611648
Py_DECREF(child);
1649+
if (self->extra == NULL || self->extra->length != length) {
1650+
goto fail;
1651+
}
16621652
if (rc > 0) {
16631653
break;
16641654
}
@@ -1667,8 +1657,10 @@ _elementtree_Element_remove_impl(ElementObject *self, PyObject *subelement)
16671657
}
16681658
}
16691659

1670-
// An extra check must be done if the mutation occurs at the very last step.
1671-
if (self->extra == NULL || old_version != self->extra->version) {
1660+
// An extra check must be done if the mutation occurs at the very last
1661+
// step and removes or clears the 'extra' list (the condition on the
1662+
// length would not be satisfied any more).
1663+
if (self->extra == NULL || self->extra->length != length) {
16721664
goto fail;
16731665
}
16741666
else if (i >= self->extra->length) {
@@ -1682,7 +1674,6 @@ _elementtree_Element_remove_impl(ElementObject *self, PyObject *subelement)
16821674
for (; i < self->extra->length; i++) {
16831675
self->extra->children[i] = self->extra->children[i+1];
16841676
}
1685-
self->extra->version++;
16861677

16871678
Py_DECREF(found);
16881679
Py_RETURN_NONE;
@@ -1746,7 +1737,6 @@ _elementtree_Element_set_impl(ElementObject *self, PyObject *key,
17461737
if (PyDict_SetItem(attrib, key, value) < 0)
17471738
return NULL;
17481739

1749-
self->extra->version++;
17501740
Py_RETURN_NONE;
17511741
}
17521742

@@ -1780,7 +1770,6 @@ element_setitem(PyObject* self_, Py_ssize_t index, PyObject* item)
17801770
self->extra->children[i] = self->extra->children[i+1];
17811771
}
17821772

1783-
self->extra->version++;
17841773
Py_DECREF(old);
17851774

17861775
return 0;
@@ -1931,7 +1920,6 @@ element_ass_subscr(PyObject* self_, PyObject* item, PyObject* value)
19311920
}
19321921

19331922
self->extra->length -= slicelen;
1934-
self->extra->version++;
19351923

19361924
/* Discard the recycle list with all the deleted sub-elements */
19371925
Py_DECREF(recycle);
@@ -2007,7 +1995,6 @@ element_ass_subscr(PyObject* self_, PyObject* item, PyObject* value)
20071995
}
20081996

20091997
self->extra->length += newlen - slicelen;
2010-
self->extra->version++;
20111998

20121999
Py_DECREF(seq);
20132000

@@ -2104,7 +2091,6 @@ element_attrib_setter(ElementObject *self, PyObject *value, void *closure)
21042091
return -1;
21052092
}
21062093
Py_XSETREF(self->extra->attrib, Py_NewRef(value));
2107-
self->extra->version++;
21082094
return 0;
21092095
}
21102096

0 commit comments

Comments
 (0)