aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Modules/_elementtree.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-02-25 17:59:46 +0200
committerGitHub <noreply@github.com>2019-02-25 17:59:46 +0200
commita24107b04c1277e3c1105f98aff5bfa3a98b33a0 (patch)
tree55aa5a700e08e3ba27b0361df2b1043be5c4701a /Modules/_elementtree.c
parenta180b007d96fe68b32f11dec720fbd0cd5b6758a (diff)
downloadcpython-a24107b04c1277e3c1105f98aff5bfa3a98b33a0.tar.gz
cpython-a24107b04c1277e3c1105f98aff5bfa3a98b33a0.zip
bpo-35459: Use PyDict_GetItemWithError() instead of PyDict_GetItem(). (GH-11112)
Diffstat (limited to 'Modules/_elementtree.c')
-rw-r--r--Modules/_elementtree.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index b1a96299f24..1e58cd05b51 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -339,7 +339,7 @@ get_attrib_from_keywords(PyObject *kwds)
if (attrib_str == NULL) {
return NULL;
}
- PyObject *attrib = PyDict_GetItem(kwds, attrib_str);
+ PyObject *attrib = PyDict_GetItemWithError(kwds, attrib_str);
if (attrib) {
/* If attrib was found in kwds, copy its value and remove it from
@@ -356,7 +356,8 @@ get_attrib_from_keywords(PyObject *kwds)
Py_DECREF(attrib);
attrib = NULL;
}
- } else {
+ }
+ else if (!PyErr_Occurred()) {
attrib = PyDict_New();
}
@@ -1393,9 +1394,13 @@ _elementtree_Element_get_impl(ElementObject *self, PyObject *key,
if (!self->extra || self->extra->attrib == Py_None)
value = default_value;
else {
- value = PyDict_GetItem(self->extra->attrib, key);
- if (!value)
+ value = PyDict_GetItemWithError(self->extra->attrib, key);
+ if (!value) {
+ if (PyErr_Occurred()) {
+ return NULL;
+ }
value = default_value;
+ }
}
Py_INCREF(value);
@@ -2848,11 +2853,12 @@ makeuniversal(XMLParserObject* self, const char* string)
if (!key)
return NULL;
- value = PyDict_GetItem(self->names, key);
+ value = PyDict_GetItemWithError(self->names, key);
if (value) {
Py_INCREF(value);
- } else {
+ }
+ else if (!PyErr_Occurred()) {
/* new name. convert to universal name, and decode as
necessary */
@@ -2974,7 +2980,7 @@ expat_default_handler(XMLParserObject* self, const XML_Char* data_in,
if (!key)
return;
- value = PyDict_GetItem(self->entity, key);
+ value = PyDict_GetItemWithError(self->entity, key);
if (value) {
if (TreeBuilder_CheckExact(self->target))