Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 183b97b

Browse filesBrowse files
gh-111789: Use PyDict_GetItemRef() in Modules/_zoneinfo.c (GH-112078)
1 parent be5e65f commit 183b97b
Copy full SHA for 183b97b

File tree

Expand file treeCollapse file tree

1 file changed

+5
-14
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+5
-14
lines changed

‎Modules/_zoneinfo.c

Copy file name to clipboardExpand all lines: Modules/_zoneinfo.c
+5-14Lines changed: 5 additions & 14 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.