diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-02-25 15:59:46 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-25 15:59:46 (GMT) |
commit | a24107b04c1277e3c1105f98aff5bfa3a98b33a0 (patch) | |
tree | 55aa5a700e08e3ba27b0361df2b1043be5c4701a /Objects/object.c | |
parent | a180b007d96fe68b32f11dec720fbd0cd5b6758a (diff) | |
download | cpython-a24107b04c1277e3c1105f98aff5bfa3a98b33a0.zip cpython-a24107b04c1277e3c1105f98aff5bfa3a98b33a0.tar.gz cpython-a24107b04c1277e3c1105f98aff5bfa3a98b33a0.tar.bz2 |
bpo-35459: Use PyDict_GetItemWithError() instead of PyDict_GetItem(). (GH-11112)
Diffstat (limited to 'Objects/object.c')
-rw-r--r-- | Objects/object.c | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/Objects/object.c b/Objects/object.c index 044342f..cf5264b 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -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; |