bpo-32571: Avoid raising unneeded AttributeError and silencing it in C code (GH-5222)

Add two new private APIs: _PyObject_LookupAttr() and _PyObject_LookupAttrId()
This commit is contained in:
Serhiy Storchaka 2018-01-25 10:49:40 +02:00 committed by INADA Naoki
parent 2b822a0bb1
commit f320be77ff
22 changed files with 1455 additions and 1442 deletions

View file

@ -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);