diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-06-12 06:47:20 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-06-12 06:47:20 (GMT) |
commit | f0ee5ccd19ec9ad0fd6c98ebf128832c225565cd (patch) | |
tree | 6ed466bf5490987d53848f58e1c581a7b89b8c7f /Modules | |
parent | cf2ad555113e4afc6f8cd5ac5235deef6a3fdf82 (diff) | |
parent | 9062c261a4f9268f4621548ec205c80411f75b6e (diff) | |
download | cpython-f0ee5ccd19ec9ad0fd6c98ebf128832c225565cd.zip cpython-f0ee5ccd19ec9ad0fd6c98ebf128832c225565cd.tar.gz cpython-f0ee5ccd19ec9ad0fd6c98ebf128832c225565cd.tar.bz2 |
Issue #25455: Fixed a crash in repr of ElementTree.Element with recursive tag.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_elementtree.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index 63639c7..b32f2ad 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -1610,10 +1610,23 @@ _elementtree_Element_remove_impl(ElementObject *self, PyObject *subelement) static PyObject* element_repr(ElementObject* self) { - if (self->tag) - return PyUnicode_FromFormat("<Element %R at %p>", self->tag, self); - else + int status; + + if (self->tag == NULL) return PyUnicode_FromFormat("<Element at %p>", self); + + status = Py_ReprEnter((PyObject *)self); + if (status == 0) { + PyObject *res; + res = PyUnicode_FromFormat("<Element %R at %p>", self->tag, self); + Py_ReprLeave((PyObject *)self); + return res; + } + if (status > 0) + PyErr_Format(PyExc_RuntimeError, + "reentrant call inside %s.__repr__", + Py_TYPE(self)->tp_name); + return NULL; } /*[clinic input] |