summaryrefslogtreecommitdiff
path: root/Objects/odictobject.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-01-25 10:49:40 +0200
committerINADA Naoki <methane@users.noreply.github.com>2018-01-25 17:49:40 +0900
commitf320be77ffb73e3b9e7fc98c37b8df3975d84b40 (patch)
tree552338f0200938249233fa4aa7b00add61965337 /Objects/odictobject.c
parent2b822a0bb1de2612c85d8f75e3ce89eda2ac9f68 (diff)
downloadcpython-git-f320be77ffb73e3b9e7fc98c37b8df3975d84b40.tar.gz
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.c20
1 files changed, 6 insertions, 14 deletions
diff --git a/Objects/odictobject.c b/Objects/odictobject.c
index 218aa2c5d9..bf19fedb07 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);