]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-111789: Use PyDict_GetItemRef() in Python/compile.c (GH-112083)
authorSerhiy Storchaka <storchaka@gmail.com>
Fri, 23 Feb 2024 11:35:27 +0000 (13:35 +0200)
committerGitHub <noreply@github.com>
Fri, 23 Feb 2024 11:35:27 +0000 (12:35 +0100)
Co-authored-by: Ɓukasz Langa <lukasz@langa.pl>
Python/compile.c

index d857239690e7b54684da779f83dd3c20d74def68..6b17f3bcaf2264406e1a01c9682bb657fc8772a7 100644 (file)
@@ -921,11 +921,10 @@ dict_add_o(PyObject *dict, PyObject *o)
     PyObject *v;
     Py_ssize_t arg;
 
-    v = PyDict_GetItemWithError(dict, o);
+    if (PyDict_GetItemRef(dict, o, &v) < 0) {
+        return ERROR;
+    }
     if (!v) {
-        if (PyErr_Occurred()) {
-            return ERROR;
-        }
         arg = PyDict_GET_SIZE(dict);
         v = PyLong_FromSsize_t(arg);
         if (!v) {
@@ -935,10 +934,10 @@ dict_add_o(PyObject *dict, PyObject *o)
             Py_DECREF(v);
             return ERROR;
         }
-        Py_DECREF(v);
     }
     else
         arg = PyLong_AsLong(v);
+    Py_DECREF(v);
     return arg;
 }