mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #28123: _PyDict_GetItem_KnownHash() now can raise an exception as
PyDict_GetItemWithError(). Patch by Xiang Zhang.
This commit is contained in:
parent
873305b28c
commit
f0b311bd73
4 changed files with 76 additions and 26 deletions
|
@ -2300,6 +2300,8 @@ _count_elements(PyObject *self, PyObject *args)
|
|||
|
||||
oldval = _PyDict_GetItem_KnownHash(mapping, key, hash);
|
||||
if (oldval == NULL) {
|
||||
if (PyErr_Occurred())
|
||||
goto done;
|
||||
if (_PyDict_SetItem_KnownHash(mapping, key, one, hash) < 0)
|
||||
goto done;
|
||||
} else {
|
||||
|
|
|
@ -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
|
||||
|
@ -4003,6 +4023,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},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue