STINNER Victor added the comment:
Martin Panter: """FYI Victor, you can make non-C-contiguous buffers by slicing
memoryview:
>>> struct.unpack(">L", memoryview(b"1234")[::-1])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
BufferError: memoryview: underlying buffer is not C-contiguous"""
Oh, it means that the Argument Clinic change doesn't add new checks on the
buffer? In Python 3.6, memory_getbuf() raises an exception in the following
code:
if (!REQ_STRIDES(flags)) {
if (!MV_C_CONTIGUOUS(baseflags)) {
PyErr_SetString(PyExc_BufferError,
"memoryview: underlying buffer is not C-contiguous");
return -1;
}
view->strides = NULL;
}
I undersrtand that memory_getbuf() is smart enough to raise an exception
becaues the buffer is not contiguous. But a weaker implementation of getbuffer
may not implement such check, whereas getbuffer() double check that the buffer
is C-contiguous. Am I right?
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue29300>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com