mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
bpo-35459: Use PyDict_GetItemWithError() instead of PyDict_GetItem(). (GH-11112)
This commit is contained in:
parent
a180b007d9
commit
a24107b04c
31 changed files with 538 additions and 242 deletions
|
@ -1144,7 +1144,7 @@ _PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method)
|
|||
dictptr = _PyObject_GetDictPtr(obj);
|
||||
if (dictptr != NULL && (dict = *dictptr) != NULL) {
|
||||
Py_INCREF(dict);
|
||||
attr = PyDict_GetItem(dict, name);
|
||||
attr = PyDict_GetItemWithError(dict, name);
|
||||
if (attr != NULL) {
|
||||
Py_INCREF(attr);
|
||||
*method = attr;
|
||||
|
@ -1152,7 +1152,13 @@ _PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method)
|
|||
Py_XDECREF(descr);
|
||||
return 0;
|
||||
}
|
||||
Py_DECREF(dict);
|
||||
else {
|
||||
Py_DECREF(dict);
|
||||
if (PyErr_Occurred()) {
|
||||
Py_XDECREF(descr);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (meth_found) {
|
||||
|
@ -1249,13 +1255,23 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name,
|
|||
}
|
||||
if (dict != NULL) {
|
||||
Py_INCREF(dict);
|
||||
res = PyDict_GetItem(dict, name);
|
||||
res = PyDict_GetItemWithError(dict, name);
|
||||
if (res != NULL) {
|
||||
Py_INCREF(res);
|
||||
Py_DECREF(dict);
|
||||
goto done;
|
||||
}
|
||||
Py_DECREF(dict);
|
||||
else {
|
||||
Py_DECREF(dict);
|
||||
if (PyErr_Occurred()) {
|
||||
if (suppress && PyErr_ExceptionMatches(PyExc_AttributeError)) {
|
||||
PyErr_Clear();
|
||||
}
|
||||
else {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (f != NULL) {
|
||||
|
@ -1943,8 +1959,11 @@ Py_ReprEnter(PyObject *obj)
|
|||
early on startup. */
|
||||
if (dict == NULL)
|
||||
return 0;
|
||||
list = _PyDict_GetItemId(dict, &PyId_Py_Repr);
|
||||
list = _PyDict_GetItemIdWithError(dict, &PyId_Py_Repr);
|
||||
if (list == NULL) {
|
||||
if (PyErr_Occurred()) {
|
||||
return -1;
|
||||
}
|
||||
list = PyList_New(0);
|
||||
if (list == NULL)
|
||||
return -1;
|
||||
|
@ -1976,7 +1995,7 @@ Py_ReprLeave(PyObject *obj)
|
|||
if (dict == NULL)
|
||||
goto finally;
|
||||
|
||||
list = _PyDict_GetItemId(dict, &PyId_Py_Repr);
|
||||
list = _PyDict_GetItemIdWithError(dict, &PyId_Py_Repr);
|
||||
if (list == NULL || !PyList_Check(list))
|
||||
goto finally;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue