diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-01-25 08:49:40 (GMT) |
---|---|---|
committer | INADA Naoki <methane@users.noreply.github.com> | 2018-01-25 08:49:40 (GMT) |
commit | f320be77ffb73e3b9e7fc98c37b8df3975d84b40 (patch) | |
tree | 552338f0200938249233fa4aa7b00add61965337 /Objects/odictobject.c | |
parent | 2b822a0bb1de2612c85d8f75e3ce89eda2ac9f68 (diff) | |
download | cpython-f320be77ffb73e3b9e7fc98c37b8df3975d84b40.zip cpython-f320be77ffb73e3b9e7fc98c37b8df3975d84b40.tar.gz cpython-f320be77ffb73e3b9e7fc98c37b8df3975d84b40.tar.bz2 |
bpo-32571: Avoid raising unneeded AttributeError and silencing it in C code (GH-5222)
Add two new private APIs: _PyObject_LookupAttr() and _PyObject_LookupAttrId()
Diffstat (limited to 'Objects/odictobject.c')
-rw-r--r-- | Objects/odictobject.c | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/Objects/odictobject.c b/Objects/odictobject.c index 218aa2c..bf19fed 100644 --- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -2359,7 +2359,10 @@ mutablemapping_update(PyObject *self, PyObject *args, PyObject *kwargs) goto handle_kwargs; } - func = _PyObject_GetAttrId(other, &PyId_keys); + if (_PyObject_LookupAttrId(other, &PyId_keys, &func) < 0) { + Py_DECREF(other); + return NULL; + } if (func != NULL) { PyObject *keys, *iterator, *key; keys = _PyObject_CallNoArg(func); @@ -2391,15 +2394,11 @@ mutablemapping_update(PyObject *self, PyObject *args, PyObject *kwargs) return NULL; goto handle_kwargs; } - else if (!PyErr_ExceptionMatches(PyExc_AttributeError)) { + + if (_PyObject_LookupAttrId(other, &PyId_items, &func) < 0) { Py_DECREF(other); return NULL; } - else { - PyErr_Clear(); - } - - func = _PyObject_GetAttrId(other, &PyId_items); if (func != NULL) { PyObject *items; Py_DECREF(other); @@ -2413,13 +2412,6 @@ mutablemapping_update(PyObject *self, PyObject *args, PyObject *kwargs) return NULL; goto handle_kwargs; } - else if (!PyErr_ExceptionMatches(PyExc_AttributeError)) { - Py_DECREF(other); - return NULL; - } - else { - PyErr_Clear(); - } res = mutablemapping_add_pairs(self, other); Py_DECREF(other); |