Skip to content

gh-111789: Use PyDict_GetItemRef() in Modules/_zoneinfo.c #112078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions Modules/_zoneinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down