summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Bendersky <eliben@gmail.com>2013-05-18 14:52:34 (GMT)
committerEli Bendersky <eliben@gmail.com>2013-05-18 14:52:34 (GMT)
commitef9683b73f8980fb7cfa39166670d3998b092804 (patch)
tree4c9e076649babc6116f93abce18e1f097c7ea123
parent587d3bf78a091c9629fc7952e47197838d338d47 (diff)
downloadcpython-ef9683b73f8980fb7cfa39166670d3998b092804.zip
cpython-ef9683b73f8980fb7cfa39166670d3998b092804.tar.gz
cpython-ef9683b73f8980fb7cfa39166670d3998b092804.tar.bz2
Issue #17989: element_setattro returned incorrect error value.
This caused an exception to be raised later than expected.
-rw-r--r--Modules/_elementtree.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index 86fdd2f..9caef99 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -1808,17 +1808,16 @@ element_getattro(ElementObject* self, PyObject* nameobj)
return res;
}
-static PyObject*
+static int
element_setattro(ElementObject* self, PyObject* nameobj, PyObject* value)
{
char *name = "";
if (PyUnicode_Check(nameobj))
name = _PyUnicode_AsString(nameobj);
- if (name == NULL)
- return NULL;
-
- if (strcmp(name, "tag") == 0) {
+ if (name == NULL) {
+ return -1;
+ } else if (strcmp(name, "tag") == 0) {
Py_DECREF(self->tag);
self->tag = value;
Py_INCREF(self->tag);
@@ -1837,11 +1836,12 @@ element_setattro(ElementObject* self, PyObject* nameobj, PyObject* value)
self->extra->attrib = value;
Py_INCREF(self->extra->attrib);
} else {
- PyErr_SetString(PyExc_AttributeError, name);
- return NULL;
+ PyErr_SetString(PyExc_AttributeError,
+ "Can't set arbitraty attributes on Element");
+ return -1;
}
- return NULL;
+ return 0;
}
static PySequenceMethods element_as_sequence = {