]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-111789: Use PyDict_GetItemRef() in Modules/pyexpat.c (gh-112079)
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 27 Nov 2023 17:51:31 +0000 (19:51 +0200)
committerGitHub <noreply@github.com>
Mon, 27 Nov 2023 17:51:31 +0000 (18:51 +0100)
Modules/pyexpat.c

index 21579a80dd7f703daa6f6818d1aed698d48bd5a4..9d95309dbb7aa67b32faed1b4d6a3f0c3f01cfb0 100644 (file)
@@ -240,19 +240,12 @@ string_intern(xmlparseobject *self, const char* str)
         return result;
     if (!self->intern)
         return result;
-    value = PyDict_GetItemWithError(self->intern, result);
-    if (!value) {
-        if (!PyErr_Occurred() &&
-            PyDict_SetItem(self->intern, result, result) == 0)
-        {
-            return result;
-        }
-        else {
-            Py_DECREF(result);
-            return NULL;
-        }
+    if (PyDict_GetItemRef(self->intern, result, &value) == 0 &&
+        PyDict_SetItem(self->intern, result, result) == 0)
+    {
+        return result;
     }
-    Py_INCREF(value);
+    assert((value != NULL) == !PyErr_Occurred());
     Py_DECREF(result);
     return value;
 }