summaryrefslogtreecommitdiffstats
path: root/Objects/dictobject.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 /Objects/dictobject.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 'Objects/dictobject.c')
-rw-r--r--Objects/dictobject.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 42d71e5..00d6ab3 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -3434,7 +3434,7 @@ PyDict_Contains(PyObject *op, PyObject *key)
/* Internal version of PyDict_Contains used when the hash value is already known */
int
-_PyDict_Contains(PyObject *op, PyObject *key, Py_hash_t hash)
+_PyDict_Contains_KnownHash(PyObject *op, PyObject *key, Py_hash_t hash)
{
PyDictObject *mp = (PyDictObject *)op;
PyObject *value;
@@ -3446,6 +3446,16 @@ _PyDict_Contains(PyObject *op, PyObject *key, Py_hash_t hash)
return (ix != DKIX_EMPTY && value != NULL);
}
+int
+_PyDict_ContainsId(PyObject *op, struct _Py_Identifier *key)
+{
+ PyObject *kv = _PyUnicode_FromId(key); /* borrowed */
+ if (kv == NULL) {
+ return -1;
+ }
+ return PyDict_Contains(op, kv);
+}
+
/* Hack to implement "key in dict" */
static PySequenceMethods dict_as_sequence = {
0, /* sq_length */
@@ -3590,18 +3600,6 @@ PyTypeObject PyDict_Type = {
.tp_vectorcall = dict_vectorcall,
};
-PyObject *
-_PyDict_GetItemId(PyObject *dp, struct _Py_Identifier *key)
-{
- PyObject *kv;
- kv = _PyUnicode_FromId(key); /* borrowed */
- if (kv == NULL) {
- PyErr_Clear();
- return NULL;
- }
- return PyDict_GetItem(dp, kv);
-}
-
/* For backward compatibility with old dictionary interface */
PyObject *