[Python-checkins] cpython (merge 3.5 -> 3.6): Merge from 3.5.

serhiy.storchaka python-checkins at python.org
Wed Dec 21 05:56:41 EST 2016


https://hg.python.org/cpython/rev/9b2e71492b53
changeset:   105765:9b2e71492b53
branch:      3.6
parent:      105760:bfd4140d9c5d
parent:      105764:957091874ea0
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Wed Dec 21 12:35:11 2016 +0200
summary:
  Merge from 3.5.

files:
  Lib/test/test_xml_etree_c.py |  10 ++++++++++
  Misc/NEWS                    |   2 ++
  Modules/_elementtree.c       |   2 ++
  3 files changed, 14 insertions(+), 0 deletions(-)


diff --git a/Lib/test/test_xml_etree_c.py b/Lib/test/test_xml_etree_c.py
--- a/Lib/test/test_xml_etree_c.py
+++ b/Lib/test/test_xml_etree_c.py
@@ -11,6 +11,7 @@
                                 fresh=['_elementtree', 'xml.etree'])
 
 
+ at unittest.skipUnless(cET, 'requires _elementtree')
 class MiscTests(unittest.TestCase):
     # Issue #8651.
     @support.bigmemtest(size=support._2G + 100, memuse=1, dry_run=False)
@@ -54,6 +55,15 @@
             del element.attrib
         self.assertEqual(element.attrib, {'A': 'B', 'C': 'D'})
 
+    def test_trashcan(self):
+        # If this test fails, it will most likely die via segfault.
+        e = root = cET.Element('root')
+        for i in range(200000):
+            e = cET.SubElement(e, 'x')
+        del e
+        del root
+        support.gc_collect()
+
 
 @unittest.skipUnless(cET, 'requires _elementtree')
 class TestAliasWorking(unittest.TestCase):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -40,6 +40,8 @@
 Library
 -------
 
+- Issue #28871: Fixed a crash when deallocate deep ElementTree.
+
 - Issue #19542: Fix bugs in WeakValueDictionary.setdefault() and
   WeakValueDictionary.pop() when a GC collection happens in another
   thread.
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -626,6 +626,7 @@
 element_dealloc(ElementObject* self)
 {
     PyObject_GC_UnTrack(self);
+    Py_TRASHCAN_SAFE_BEGIN(self)
 
     if (self->weakreflist != NULL)
         PyObject_ClearWeakRefs((PyObject *) self);
@@ -636,6 +637,7 @@
 
     RELEASE(sizeof(ElementObject), "destroy element");
     Py_TYPE(self)->tp_free((PyObject *)self);
+    Py_TRASHCAN_SAFE_END(self)
 }
 
 /* -------------------------------------------------------------------- */

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list