summaryrefslogtreecommitdiffstats
path: root/Modules/_zoneinfo.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2020-10-26 06:43:39 (GMT)
committerGitHub <noreply@github.com>2020-10-26 06:43:39 (GMT)
commitfb5db7ec58624cab0797b4050735be865d380823 (patch)
tree7b0421bb759ba01f0d735296738472faa4ce11b8 /Modules/_zoneinfo.c
parent96a9eed2457c05af6953890d89463704c9d99c57 (diff)
downloadcpython-fb5db7ec58624cab0797b4050735be865d380823.zip
cpython-fb5db7ec58624cab0797b4050735be865d380823.tar.gz
cpython-fb5db7ec58624cab0797b4050735be865d380823.tar.bz2
bpo-42006: Stop using PyDict_GetItem, PyDict_GetItemString and _PyDict_GetItemId. (GH-22648)
These functions are considered not safe because they suppress all internal errors and can return wrong result. PyDict_GetItemString and _PyDict_GetItemId can also silence current exception in rare cases. Remove no longer used _PyDict_GetItemId. Add _PyDict_ContainsId and rename _PyDict_Contains into _PyDict_Contains_KnownHash.
Diffstat (limited to 'Modules/_zoneinfo.c')
-rw-r--r--Modules/_zoneinfo.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c
index bee59b8..76b667d 100644
--- a/Modules/_zoneinfo.c
+++ b/Modules/_zoneinfo.c
@@ -722,17 +722,16 @@ zoneinfo__unpickle(PyTypeObject *cls, PyObject *args)
static PyObject *
load_timedelta(long seconds)
{
- PyObject *rv = NULL;
+ PyObject *rv;
PyObject *pyoffset = PyLong_FromLong(seconds);
if (pyoffset == NULL) {
return NULL;
}
- int contains = PyDict_Contains(TIMEDELTA_CACHE, pyoffset);
- if (contains == -1) {
- goto error;
- }
-
- if (!contains) {
+ rv = PyDict_GetItemWithError(TIMEDELTA_CACHE, pyoffset);
+ if (rv == NULL) {
+ if (PyErr_Occurred()) {
+ goto error;
+ }
PyObject *tmp = PyDateTimeAPI->Delta_FromDelta(
0, seconds, 0, 1, PyDateTimeAPI->DeltaType);
@@ -743,12 +742,9 @@ load_timedelta(long seconds)
rv = PyDict_SetDefault(TIMEDELTA_CACHE, pyoffset, tmp);
Py_DECREF(tmp);
}
- else {
- rv = PyDict_GetItem(TIMEDELTA_CACHE, pyoffset);
- }
+ Py_XINCREF(rv);
Py_DECREF(pyoffset);
- Py_INCREF(rv);
return rv;
error:
Py_DECREF(pyoffset);