summaryrefslogtreecommitdiff
path: root/Modules/_testcapimodule.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-11-06 13:19:38 +0200
committerSerhiy Storchaka <storchaka@gmail.com>2016-11-06 13:19:38 +0200
commit04230c40874d9dae9bafb2a99eac99b4e7a306df (patch)
treeb22e23d90e8c8ec9959b7a743732048443c2e4aa /Modules/_testcapimodule.c
parenta76f014278bd1643e93fdfa9e88f9414ce8354a6 (diff)
parentf0b311bd739d36d62e81dacd27d098c496e8663a (diff)
downloadcpython-git-04230c40874d9dae9bafb2a99eac99b4e7a306df.tar.gz
Issue #28123: _PyDict_GetItem_KnownHash() now can raise an exception as
PyDict_GetItemWithError(). Patch by Xiang Zhang.
Diffstat (limited to 'Modules/_testcapimodule.c')
-rw-r--r--Modules/_testcapimodule.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index d651459891..b343080e59 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -238,6 +238,26 @@ test_dict_iteration(PyObject* self)
return Py_None;
}
+static PyObject*
+dict_getitem_knownhash(PyObject *self, PyObject *args)
+{
+ PyObject *mp, *key, *result;
+ Py_ssize_t hash;
+
+ if (!PyArg_ParseTuple(args, "OOn:dict_getitem_knownhash",
+ &mp, &key, &hash)) {
+ return NULL;
+ }
+
+ result = _PyDict_GetItem_KnownHash(mp, key, (Py_hash_t)hash);
+ if (result == NULL && !PyErr_Occurred()) {
+ _PyErr_SetKeyError(key);
+ return NULL;
+ }
+
+ Py_XINCREF(result);
+ return result;
+}
/* Issue #4701: Check that PyObject_Hash implicitly calls
* PyType_Ready if it hasn't already been called
@@ -3999,6 +4019,7 @@ static PyMethodDef TestMethods[] = {
{"test_datetime_capi", test_datetime_capi, METH_NOARGS},
{"test_list_api", (PyCFunction)test_list_api, METH_NOARGS},
{"test_dict_iteration", (PyCFunction)test_dict_iteration,METH_NOARGS},
+ {"dict_getitem_knownhash", dict_getitem_knownhash, METH_VARARGS},
{"test_lazy_hash_inheritance", (PyCFunction)test_lazy_hash_inheritance,METH_NOARGS},
{"test_long_api", (PyCFunction)test_long_api, METH_NOARGS},
{"test_xincref_doesnt_leak",(PyCFunction)test_xincref_doesnt_leak, METH_NOARGS},