diff options
Diffstat (limited to 'Objects/memoryobject.c')
-rw-r--r-- | Objects/memoryobject.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/Objects/memoryobject.c b/Objects/memoryobject.c index 74cad7d..fe54366 100644 --- a/Objects/memoryobject.c +++ b/Objects/memoryobject.c @@ -2156,8 +2156,23 @@ static PyObject * memory_hex(PyMemoryViewObject *self, PyObject *dummy) { Py_buffer *src = VIEW_ADDR(self); + PyObject *bytes; + PyObject *ret; + CHECK_RELEASED(self); - return _Py_strhex(src->buf, src->len); + + if (MV_C_CONTIGUOUS(self->flags)) { + return _Py_strhex(src->buf, src->len); + } + + bytes = memory_tobytes(self, dummy); + if (bytes == NULL) + return NULL; + + ret = _Py_strhex(PyBytes_AS_STRING(bytes), Py_SIZE(bytes)); + Py_DECREF(bytes); + + return ret; } static PyObject * |