From a24107b04c1277e3c1105f98aff5bfa3a98b33a0 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 25 Feb 2019 17:59:46 +0200 Subject: bpo-35459: Use PyDict_GetItemWithError() instead of PyDict_GetItem(). (GH-11112) --- Modules/_elementtree.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'Modules/_elementtree.c') 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)) -- cgit v1.2.3