This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author christian.heimes
Recipients christian.heimes, petr.viktorin, pitrou, serhiy.storchaka, skrah, vstinner
Date 2021-10-20.08:19:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1634717961.46.0.965277995693.issue45459@roundup.psfhosted.org>
In-reply-to
Content
All memory is owned by the exporter object. The exporter (aka producer) is the Python type that implements Py_bf_getbuffer and Py_bf_releasebuffer. In majority of cases the exporter doesn't have to set shape, strides, and suboffsets. They are used in special cases, e.g. multidimensional arrays with custom layout. For example they can be used to convert TIFF images from strides big endian format to a NumPy array in little endian format.

It's up to the exporter's Py_bf_getbuffer to decide how it fills shape, strides, and suboffsets, too. For example an exporter could allocate format, shape, strides, and suboffsets on the heap and assign pointers in its getbuffer function and store a hint in the ``internal`` field of Py_buffer. Its releasebuffer function then checks ``internal`` field and performs de-allocations. We must not copy fields. This would break the API.

It would be a bad idea to return copies in PyBuffer_GetLayout(). Consumers have to get the layout every time they access a specific item in the buffer in order to calculate the offset. I'd rather define the arguments as "const". The documentation already states that e.g. "The shape array is read-only for the consumer.".

It is highly unlikely that we will ever have to extend the Py_buffer interface. It is already extremely versatile and can encode complex formats. You can even express the layout of a TIFF image of float32 CMYK in planar configuration (one array of 32bit floats cyan, followed by an array of magenta, then an array of yellow, and finally an array of contrast).

PS: I have removed PyBuffer_NewEx() function. It did not make sense any sense.
History
Date User Action Args
2021-10-20 08:19:21christian.heimessetrecipients: + christian.heimes, pitrou, vstinner, petr.viktorin, skrah, serhiy.storchaka
2021-10-20 08:19:21christian.heimessetmessageid: <1634717961.46.0.965277995693.issue45459@roundup.psfhosted.org>
2021-10-20 08:19:21christian.heimeslinkissue45459 messages
2021-10-20 08:19:21christian.heimescreate