summaryrefslogtreecommitdiffstats
path: root/Objects/object.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-11-14 09:25:39 (GMT)
committerGitHub <noreply@github.com>2023-11-14 09:25:39 (GMT)
commit18203a6bc9ccf3a9ba901574dfc772474b027e2a (patch)
tree7c74d43b8155489ccc8990538890b45ef5e5f9fd /Objects/object.c
parente31d65e0b7bb6d6fee4e8df54e10976b4cfab1de (diff)
downloadcpython-18203a6bc9ccf3a9ba901574dfc772474b027e2a.zip
cpython-18203a6bc9ccf3a9ba901574dfc772474b027e2a.tar.gz
cpython-18203a6bc9ccf3a9ba901574dfc772474b027e2a.tar.bz2
gh-111789: Use PyDict_GetItemRef() in Objects/ (GH-111827)
Diffstat (limited to 'Objects/object.c')
-rw-r--r--Objects/object.c31
1 files changed, 11 insertions, 20 deletions
diff --git a/Objects/object.c b/Objects/object.c
index 1003029..1f5b2b4 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -1490,19 +1490,14 @@ _PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method)
}
if (dict != NULL) {
Py_INCREF(dict);
- PyObject *attr = PyDict_GetItemWithError(dict, name);
- if (attr != NULL) {
- *method = Py_NewRef(attr);
+ if (PyDict_GetItemRef(dict, name, method) != 0) {
+ // found or error
Py_DECREF(dict);
Py_XDECREF(descr);
return 0;
}
+ // not found
Py_DECREF(dict);
-
- if (PyErr_Occurred()) {
- Py_XDECREF(descr);
- return 0;
- }
}
if (meth_found) {
@@ -1607,21 +1602,17 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name,
}
if (dict != NULL) {
Py_INCREF(dict);
- res = PyDict_GetItemWithError(dict, name);
+ int rc = PyDict_GetItemRef(dict, name, &res);
+ Py_DECREF(dict);
if (res != NULL) {
- Py_INCREF(res);
- Py_DECREF(dict);
goto done;
}
- else {
- Py_DECREF(dict);
- if (PyErr_Occurred()) {
- if (suppress && PyErr_ExceptionMatches(PyExc_AttributeError)) {
- PyErr_Clear();
- }
- else {
- goto done;
- }
+ else if (rc < 0) {
+ if (suppress && PyErr_ExceptionMatches(PyExc_AttributeError)) {
+ PyErr_Clear();
+ }
+ else {
+ goto done;
}
}
}