]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-111789: Use PyDict_GetItemRef() in Modules/_zoneinfo.c (GH-112078)
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 10 Jan 2024 13:35:10 +0000 (15:35 +0200)
committerGitHub <noreply@github.com>
Wed, 10 Jan 2024 13:35:10 +0000 (15:35 +0200)
Modules/_zoneinfo.c

index 77644c3155bc33eed71786d70e47c515724640b9..fcd4af64df0be94c1c1577d7a119c8c1af0ed955 100644 (file)
@@ -853,28 +853,19 @@ load_timedelta(zoneinfo_state *state, long seconds)
     if (pyoffset == NULL) {
         return NULL;
     }
-    rv = PyDict_GetItemWithError(state->TIMEDELTA_CACHE, pyoffset);
-    if (rv == NULL) {
-        if (PyErr_Occurred()) {
-            goto error;
-        }
+    if (PyDict_GetItemRef(state->TIMEDELTA_CACHE, pyoffset, &rv) == 0) {
         PyObject *tmp = PyDateTimeAPI->Delta_FromDelta(
             0, seconds, 0, 1, PyDateTimeAPI->DeltaType);
 
-        if (tmp == NULL) {
-            goto error;
+        if (tmp != NULL) {
+            rv = PyDict_SetDefault(state->TIMEDELTA_CACHE, pyoffset, tmp);
+            Py_XINCREF(rv);
+            Py_DECREF(tmp);
         }
-
-        rv = PyDict_SetDefault(state->TIMEDELTA_CACHE, pyoffset, tmp);
-        Py_DECREF(tmp);
     }
 
-    Py_XINCREF(rv);
     Py_DECREF(pyoffset);
     return rv;
-error:
-    Py_DECREF(pyoffset);
-    return NULL;
 }
 
 /* Constructor for _ttinfo object - this starts by initializing the _ttinfo