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 lemburg
Recipients lemburg, loewis, pitrou, vstinner
Date 2010-08-17.15:42:57
SpamBayes Score 0.0
Marked as misclassified No
Message-id <4C6AADFF.3050209@egenix.com>
In-reply-to <1281978153.17.0.301612840444.issue9602@psf.upfronthosting.co.za>
Content
STINNER Victor wrote:
> 
> STINNER Victor <victor.stinner@haypocalc.com> added the comment:
> 
>> Note that the buffer interface release API is meant to protect
>> against such modifications, so I don't see why rejecting objects
>> that do implement this API should be rejected.
> 
> As I explained, the release API is *not* used by PyObject_AsCharBuffer() in Python 2.7 and 3.2.
> 
> Pseudo-code example:
> ---
> PyObject_AsCharBuffer(obj, &str, &size)
> ... modify or destroy obj ...
> str is no more valid here
> ---

Right, but as I explained before: this doesn't really happen in
practice, otherwise we would have had issues with these APIs
long before the Py_buffers were introduced.

Note that the same comment applies to PyObject_AsReadBuffer() and
PyObject_AsWriteBuffer().

For Python 2.7 you can't change anything anymore. For Python 3.2
you could start a deprecation process as outlined in PEP 4, if you
feel this really is such a big issue.

>> Restricting the API to read-only buffers would seriously limit
>> it's functionality. I'm -1 on doing that.
> 
> PyObject_AsCharBuffer() is dangerous because the caller has to ensure that the object is not modified or destroyed. Antoine proposes to deprecated PyObject_AsCharBuffer().
> 
> PyObject_GetBuffer() can replace PyObject_AsCharBuffer(): it's easy to get the pointer to the buffer content (view.buf) and the size (view.len) using PyObject_GetBuffer(), and it does protect the buffer against modification or destuction thanks to the release API (PyBuffer_Release). But PyObject_GetBuffer() is maybe a little bit to low level, eg. it doesn't check that the buffer is contiguous, and it requires a flag argument. A new function is maybe needed to replace PyObject_AsCharBuffer(). Eg. PyObject_GetCharBuffer() which will call PyObject_GetBuffer() (the caller will then have to call PyBuffer_Release() to release the buffer).
> 
> Example:
> ---
> PyObject_GetCharBuffer(obj, &view, &str, &size)
> ... use str and size ...
> PyBuffer_Release(view);
> ---
> or just
> ---
> PyObject_GetCharBuffer(obj, &view)
> ... use view.buf and view.len ...
> PyBuffer_Release(view);
> ---

Why add a new function ? Python 3.2 doesn't provide a way to access
a *character* buffer version of an object anymore. Not that this is
good, or shouldn't be readded at some point, but right now, we don't
have a need for such an API.
History
Date User Action Args
2010-08-17 15:43:00lemburgsetrecipients: + lemburg, loewis, pitrou, vstinner
2010-08-17 15:42:58lemburglinkissue9602 messages
2010-08-17 15:42:57lemburgcreate