Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 47bdc40

Browse files
Merge from 3.6.
2 parents b211068 + 690e81f commit 47bdc40

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

Lib/test/test_xml_etree_c.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
fresh=['_elementtree', 'xml.etree'])
1212

1313

14+
@unittest.skipUnless(cET, 'requires _elementtree')
1415
class MiscTests(unittest.TestCase):
1516
# Issue #8651.
1617
@support.bigmemtest(size=support._2G + 100, memuse=1, dry_run=False)
@@ -54,6 +55,15 @@ def test_del_attribute(self):
5455
del element.attrib
5556
self.assertEqual(element.attrib, {'A': 'B', 'C': 'D'})
5657

58+
def test_trashcan(self):
59+
# If this test fails, it will most likely die via segfault.
60+
e = root = cET.Element('root')
61+
for i in range(200000):
62+
e = cET.SubElement(e, 'x')
63+
del e
64+
del root
65+
support.gc_collect()
66+
5767

5868
@unittest.skipUnless(cET, 'requires _elementtree')
5969
class TestAliasWorking(unittest.TestCase):

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ Core and Builtins
205205
Library
206206
-------
207207

208+
- Issue #28871: Fixed a crash when deallocate deep ElementTree.
209+
208210
- Issue #19542: Fix bugs in WeakValueDictionary.setdefault() and
209211
WeakValueDictionary.pop() when a GC collection happens in another
210212
thread.

Modules/_elementtree.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ static void
626626
element_dealloc(ElementObject* self)
627627
{
628628
PyObject_GC_UnTrack(self);
629+
Py_TRASHCAN_SAFE_BEGIN(self)
629630

630631
if (self->weakreflist != NULL)
631632
PyObject_ClearWeakRefs((PyObject *) self);
@@ -636,6 +637,7 @@ element_dealloc(ElementObject* self)
636637

637638
RELEASE(sizeof(ElementObject), "destroy element");
638639
Py_TYPE(self)->tp_free((PyObject *)self);
640+
Py_TRASHCAN_SAFE_END(self)
639641
}
640642

641643
/* -------------------------------------------------------------------- */

0 commit comments

Comments
 (0)