Skip to content

Commit 9c84896

Browse files
serhiy-storchakaaisk
authored andcommitted
pythongh-111789: Use PyDict_GetItemRef() in Modules/_zoneinfo.c (pythonGH-112078)
1 parent 33a36ca commit 9c84896

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

Modules/_zoneinfo.c

+5-14
Original file line numberDiff line numberDiff line change
@@ -853,28 +853,19 @@ load_timedelta(zoneinfo_state *state, long seconds)
853853
if (pyoffset == NULL) {
854854
return NULL;
855855
}
856-
rv = PyDict_GetItemWithError(state->TIMEDELTA_CACHE, pyoffset);
857-
if (rv == NULL) {
858-
if (PyErr_Occurred()) {
859-
goto error;
860-
}
856+
if (PyDict_GetItemRef(state->TIMEDELTA_CACHE, pyoffset, &rv) == 0) {
861857
PyObject *tmp = PyDateTimeAPI->Delta_FromDelta(
862858
0, seconds, 0, 1, PyDateTimeAPI->DeltaType);
863859

864-
if (tmp == NULL) {
865-
goto error;
860+
if (tmp != NULL) {
861+
rv = PyDict_SetDefault(state->TIMEDELTA_CACHE, pyoffset, tmp);
862+
Py_XINCREF(rv);
863+
Py_DECREF(tmp);
866864
}
867-
868-
rv = PyDict_SetDefault(state->TIMEDELTA_CACHE, pyoffset, tmp);
869-
Py_DECREF(tmp);
870865
}
871866

872-
Py_XINCREF(rv);
873867
Py_DECREF(pyoffset);
874868
return rv;
875-
error:
876-
Py_DECREF(pyoffset);
877-
return NULL;
878869
}
879870

880871
/* Constructor for _ttinfo object - this starts by initializing the _ttinfo

0 commit comments

Comments
 (0)