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.

Title: BufferObject doesn't support new buffer interface
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, benjamin.peterson, eric.araujo, kristjan.jonsson, lemburg, pitrou, python-dev, skrah, tseaver
Priority: normal Keywords: easy, patch

Created on 2010-10-27 08:49 by kristjan.jonsson, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
buffer_newbuf.patch kristjan.jonsson, 2010-10-27 08:49 review
Messages (9)
msg119683 - (view) Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) Date: 2010-10-27 08:49
The BufferObject in 2.7 doesn't support the new buffer interface.
This makes it useless for use with the new memoryview object.
This simple patch adds that support.
msg119691 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-10-27 11:25
Unless there is a mismatch between the documentation and the code, I suspect this will be rejected by the release manager.
msg119714 - (view) Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) Date: 2010-10-27 14:40
Well, we can always fix the documentation, then :)
Seriously, having two different buffer interfaces in the interpreter core that can only communicate through weird middle men (like str()) should be considered a bug.  There shouldn't be any surprises like this. Simple is better than complex.
msg119721 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2010-10-27 17:08
The memoryview object was added to simplify porting applications to Python3. If that backport is incomplete in the sense that the memoryview object is not compatible with the standard Python2 object for such memory views, then I'd consider that a bug.

Without compatibility to the buffer objects, there's no way to make other Python2 buffer interface compatible object compatible to memoryviews.

Alternatively, the Python2 memoryview object implementation could also accept objects with the old buffer interface, much like "s*" does.

Note that the patch needs to check the buffer flags - writing to such buffers is not allowed.
msg119749 - (view) Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) Date: 2010-10-28 01:28
Do you mean that we should disable writing for the new style buffer interface?  Currently the patch respects the Buffer object's read-only flag (self->b_readonly):

static int buffer_getbuffer(PyBufferObject *self, Py_buffer *buf, int flags)
	void *ptr;
	Py_ssize_t size;
	if (!get_buf(self, &ptr, &size, ANY_BUFFER))
		return -1;
	return PyBuffer_FillInfo(buf, (PyObject*)self, ptr, size,
		self->b_readonly, flags);
msg156388 - (view) Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) Date: 2012-03-20 09:12
Bumping this.  Do we want this fixed as a bug in 2.7 or left alone?
msg184527 - (view) Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) Date: 2013-03-18 21:20
Bump, 2.7.4 will be cut next week ...
msg184561 - (view) Author: Tres Seaver (tseaver) * Date: 2013-03-19 00:05
Looks good to me.
msg184716 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-03-20 00:40
New changeset 6b3217b96a77 by Kristján Valur Jónsson in branch '2.7':
Issue #10211 : Buffer object should support the new buffer interface.
Date User Action Args
2022-04-11 14:57:07adminsetgithub: 54420
2013-03-22 22:53:21Arfreversetstage: resolved
2013-03-22 17:26:10kristjan.jonssonsetstatus: open -> closed
resolution: fixed
2013-03-20 00:40:30python-devsetnosy: + python-dev
messages: + msg184716
2013-03-19 00:12:10Arfreversetnosy: + Arfrever
2013-03-19 00:05:34tseaversetnosy: + tseaver
messages: + msg184561
2013-03-18 21:20:34kristjan.jonssonsetmessages: + msg184527
2012-03-20 09:12:02kristjan.jonssonsetmessages: + msg156388
2012-02-09 22:45:55skrahsetnosy: + skrah
2010-10-28 13:53:12eric.araujosetnosy: + pitrou
2010-10-28 01:28:42kristjan.jonssonsetmessages: + msg119749
2010-10-27 17:08:29lemburgsetnosy: + lemburg
messages: + msg119721
2010-10-27 14:40:01kristjan.jonssonsetmessages: + msg119714
2010-10-27 11:25:10eric.araujosetnosy: + eric.araujo, benjamin.peterson
messages: + msg119691
2010-10-27 08:49:10kristjan.jonssoncreate