Message286785
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? |
|
Date |
User |
Action |
Args |
2017-02-02 13:34:51 | vstinner | set | recipients:
+ vstinner, larry, methane, python-dev, martin.panter, serhiy.storchaka |
2017-02-02 13:34:51 | vstinner | set | messageid: <1486042491.68.0.227427220935.issue29300@psf.upfronthosting.co.za> |
2017-02-02 13:34:51 | vstinner | link | issue29300 messages |
2017-02-02 13:34:51 | vstinner | create | |
|