diff options
author | Stefan Krah <skrah@bytereef.org> | 2012-11-02 16:49:22 (GMT) |
---|---|---|
committer | Stefan Krah <skrah@bytereef.org> | 2012-11-02 16:49:22 (GMT) |
commit | 4af77a027680f2aa956a4d1c50947d6e2dbd0185 (patch) | |
tree | 5da6482a5d2dd2472b83f1a9438b227166322b96 /Objects | |
parent | e6996ed5d9c3ce149a8384a625521ab5a0820ae3 (diff) | |
download | cpython-4af77a027680f2aa956a4d1c50947d6e2dbd0185.zip cpython-4af77a027680f2aa956a4d1c50947d6e2dbd0185.tar.gz cpython-4af77a027680f2aa956a4d1c50947d6e2dbd0185.tar.bz2 |
Issue #15814: Use hash function that is compatible with the equality
definition from #15573.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/memoryobject.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Objects/memoryobject.c b/Objects/memoryobject.c index d56faf8..dd6fe82 100644 --- a/Objects/memoryobject.c +++ b/Objects/memoryobject.c @@ -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; |