mirror of
https://github.com/python/cpython
synced 2026-09-29 10:35:30 +03:00
Issue #15814: Use hash function that is compatible with the equality
definition from #15573.
This commit is contained in:
parent
e6996ed5d9
commit
4af77a0276
3 changed files with 38 additions and 8 deletions
|
|
@ -2707,6 +2707,8 @@ memory_hash(PyMemoryViewObject *self)
|
|||
if (self->hash == -1) {
|
||||
Py_buffer *view = &self->view;
|
||||
char *mem = view->buf;
|
||||
Py_ssize_t ret;
|
||||
char fmt;
|
||||
|
||||
CHECK_RELEASED_INT(self);
|
||||
|
||||
|
|
@ -2715,6 +2717,12 @@ memory_hash(PyMemoryViewObject *self)
|
|||
"cannot hash writable memoryview object");
|
||||
return -1;
|
||||
}
|
||||
ret = get_native_fmtchar(&fmt, view->format);
|
||||
if (ret < 0 || !IS_BYTE_FORMAT(fmt)) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"memoryview: hashing is restricted to formats 'B', 'b' or 'c'");
|
||||
return -1;
|
||||
}
|
||||
if (view->obj != NULL && PyObject_Hash(view->obj) == -1) {
|
||||
/* Keep the original error message */
|
||||
return -1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue