[Python-checkins] cpython: Issue #18408: Fix _elementtree.c, don't call Python function from an expat
victor.stinner
python-checkins at python.org
Thu Jul 18 22:46:50 CEST 2013
http://hg.python.org/cpython/rev/6ec0e9347dd4
changeset: 84709:6ec0e9347dd4
user: Victor Stinner <victor.stinner at gmail.com>
date: Thu Jul 18 22:46:14 2013 +0200
summary:
Issue #18408: Fix _elementtree.c, don't call Python function from an expat
handler if a Python exception is set
files:
Modules/_elementtree.c | 28 ++++++++++++++++++++++++++++
1 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -2831,6 +2831,9 @@
if (data_len < 2 || data_in[0] != '&')
return;
+ if (PyErr_Occurred())
+ return;
+
key = PyUnicode_DecodeUTF8(data_in + 1, data_len - 2, "strict");
if (!key)
return;
@@ -2871,6 +2874,9 @@
PyObject* attrib;
int ok;
+ if (PyErr_Occurred())
+ return;
+
/* tag name */
tag = makeuniversal(self, tag_in);
if (!tag)
@@ -2929,6 +2935,9 @@
PyObject* data;
PyObject* res;
+ if (PyErr_Occurred())
+ return;
+
data = PyUnicode_DecodeUTF8(data_in, data_len, "strict");
if (!data)
return; /* parser will look for errors */
@@ -2952,6 +2961,9 @@
PyObject* tag;
PyObject* res = NULL;
+ if (PyErr_Occurred())
+ return;
+
if (TreeBuilder_CheckExact(self->target))
/* shortcut */
/* the standard tree builder doesn't look at the end tag */
@@ -2976,6 +2988,9 @@
PyObject* sprefix = NULL;
PyObject* suri = NULL;
+ if (PyErr_Occurred())
+ return;
+
suri = PyUnicode_DecodeUTF8(uri, strlen(uri), "strict");
if (!suri)
return;
@@ -3000,6 +3015,9 @@
static void
expat_end_ns_handler(XMLParserObject* self, const XML_Char* prefix_in)
{
+ if (PyErr_Occurred())
+ return;
+
treebuilder_handle_namespace(
(TreeBuilderObject*) self->target, 0, NULL, NULL
);
@@ -3011,6 +3029,9 @@
PyObject* comment;
PyObject* res;
+ if (PyErr_Occurred())
+ return;
+
if (self->handle_comment) {
comment = PyUnicode_DecodeUTF8(comment_in, strlen(comment_in), "strict");
if (comment) {
@@ -3033,6 +3054,9 @@
PyObject *parser_doctype = NULL;
PyObject *res = NULL;
+ if (PyErr_Occurred())
+ return;
+
doctype_name_obj = makeuniversal(self, doctype_name);
if (!doctype_name_obj)
return;
@@ -3101,6 +3125,9 @@
PyObject* data;
PyObject* res;
+ if (PyErr_Occurred())
+ return;
+
if (self->handle_pi) {
target = PyUnicode_DecodeUTF8(target_in, strlen(target_in), "strict");
data = PyUnicode_DecodeUTF8(data_in, strlen(data_in), "strict");
@@ -3273,6 +3300,7 @@
{
int ok;
+ assert(!PyErr_Occurred());
ok = EXPAT(Parse)(self->parser, data, data_len, final);
if (PyErr_Occurred())
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list