Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions Modules/_elementtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,26 +376,26 @@ get_attrib_from_keywords(PyObject *kwds)
if (attrib_str == NULL) {
return NULL;
}
PyObject *attrib = PyDict_GetItemWithError(kwds, attrib_str);

if (attrib) {
PyObject *attrib;
if (PyDict_GetItemRef(kwds, attrib_str, &attrib) == 0) {
attrib = PyDict_New();
}
else if (attrib) {
/* If attrib was found in kwds, copy its value and remove it from
* kwds
*/
if (!PyDict_Check(attrib)) {
Py_DECREF(attrib_str);
PyErr_Format(PyExc_TypeError, "attrib must be dict, not %.100s",
Py_TYPE(attrib)->tp_name);
Py_DECREF(attrib);
return NULL;
}
attrib = PyDict_Copy(attrib);
Py_SETREF(attrib, PyDict_Copy(attrib));
if (attrib && PyDict_DelItem(kwds, attrib_str) < 0) {
Py_SETREF(attrib, NULL);
}
}
else if (!PyErr_Occurred()) {
attrib = PyDict_New();
}

Py_DECREF(attrib_str);

Expand Down Expand Up @@ -1427,11 +1427,14 @@ _elementtree_Element_get_impl(ElementObject *self, PyObject *key,
{
if (self->extra && self->extra->attrib) {
PyObject *attrib = Py_NewRef(self->extra->attrib);
PyObject *value = Py_XNewRef(PyDict_GetItemWithError(attrib, key));
Py_DECREF(attrib);
if (value != NULL || PyErr_Occurred()) {
PyObject *value;
if (PyDict_GetItemRef(attrib, key, &value) != 0) {
// found or error
Py_DECREF(attrib);
return value;
}
// not found
Py_DECREF(attrib);
}

return Py_NewRef(default_value);
Expand Down Expand Up @@ -3092,9 +3095,7 @@ makeuniversal(XMLParserObject* self, const char* string)
if (!key)
return NULL;

value = Py_XNewRef(PyDict_GetItemWithError(self->names, key));

if (value == NULL && !PyErr_Occurred()) {
if (PyDict_GetItemRef(self->names, key, &value) == 0) {
/* new name. convert to universal name, and decode as
necessary */

Expand Down