Stefan Krah added the comment:
Yes, PyBuffer_FillInfo() is a bit confusing: The canonical usage *looks* as
if "flags" were somehow used in the Py_buffer struct to mark a buffer as having
certain capabilities:
Modules/_io/bufferedio.c:
-------------------------
if (PyBuffer_FillInfo(&buf, NULL, start, len, 0, PyBUF_CONTIG) == -1)
return -1;
memobj = PyMemoryView_FromBuffer(&buf);
What really goes on since Python 3.3 is that memobj is a memoryview
with (shape,strides,format), since missing Py_buffer values are
reconstructed.
So all memoryviews -- when acting as an exporter as in this example --
have PyBUF_FULL capabilities. To make that clear, we should actually
change the PyBUF_CONTIG in the above example to PyBUF_FULL. Then
the mental model is:
PyBuffer_FillInfo(..., PyBUF_FULL)
^
| "Request" full buffer to export.
memobj
^
| Request anything from PyBUF_SIMPLE to PyBUF_FULL. Note
| that e.g. with PyBUF_SIMPLE the consumer's shape and
| strides will be NULL!
Consumer
And that model is consistent with the usage of PyBuffer_FillInfo() inside
a getbufferproc, where "flags" of course can be anything.
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue21778>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com