diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2024-01-10 13:35:10 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-10 13:35:10 (GMT) |
commit | 183b97bb9db075197153ad82b8ffdfce8e913250 (patch) | |
tree | c76ace16a09d371a4baba9054ecb625a2c3404c3 /Modules | |
parent | be5e65fdf67b1817e173e73443564c7c146b09a4 (diff) | |
download | cpython-183b97bb9db075197153ad82b8ffdfce8e913250.zip cpython-183b97bb9db075197153ad82b8ffdfce8e913250.tar.gz cpython-183b97bb9db075197153ad82b8ffdfce8e913250.tar.bz2 |
gh-111789: Use PyDict_GetItemRef() in Modules/_zoneinfo.c (GH-112078)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_zoneinfo.c | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c index 77644c3..fcd4af6 100644 --- a/Modules/_zoneinfo.c +++ b/Modules/_zoneinfo.c @@ -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 |