[Python-3000] Using memoryviews
M.-A. Lemburg
mal at egenix.com
Tue Nov 25 17:56:49 CET 2008
On 2008-11-22 00:52, Benjamin Peterson wrote:
> On Fri, Nov 21, 2008 at 5:34 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
>> Benjamin Peterson wrote:
>>> On Fri, Nov 21, 2008 at 1:41 PM, M.-A. Lemburg <mal at egenix.com> wrote:
>>>> In the past, we've always tried to provide abstract access methods to
>>>> C struct internals of Python objects and I wonder whether this was
>>>> deliberately not done for Py_buffer structs or simply not considered.
>>>>
>>>> I don't think it's a good idea to use my_Py_buffer->buf in a C
>>>> extension and would rather like to write:
>>>>
>>>> Py_Buffer_AS_BUFFER(my_Py_buffer)
>>>> Py_Buffer_GET_SIZE(my_Py_buffer)
>>>> Py_Buffer_GET_ITEM_SIZE(my_Py_buffer)
>>>> etc.
>>> I think that's a good idea, too, and we should get something like that
>>> in for 3.1. I rather feel like the new buffer API slipped in without
>>> any real review.
>> The review that was done was actually quite extensive - see PEP 3118.
>> However:
>> 1. There's a reason 3118 is still at accepted rather than final - the
>> major foundations (and the all-important underlying protocol) are in
>> place, but there are finishing touches still needed.
>> 2. The review of the PEP focused on the power and capabilities of the
>> underlying protocol and less on the aesthetics of the C API.
>
> I'm not talking necessarily about the PEP and API. I find the
> implementation confusing and contradictory in some places.
>
>> The PEP was fairly explicit that the fields in the Py_buffer struct were
>> public and accessed directly via C syntax though, as are the current
>> docs (http://docs.python.org/dev/3.0/c-api/buffer.html).
>
> Well, I wrote those based on the PEP. :)
I find the implementation of the buffer protocol way too complicated.
One of the reasons why the buffer protocol in Python 2 never caught
on was the fact that it was too complicated and the Python 3 is
even worse in this respect.
In practice you do want to have the ability to hook directly into the
data buffer of an object, but apart from some special needs that PIL
and the numeric folks may have, most users will just want to work
with a single contiguous chunk of memory and need a simple API to
do this - pass in an object, get a void* back.
With the new interface, programmers will have to deal with an
PyObject_GetBuffer() API having 17 modification flags in order
to deal with many different corner cases and returning a Py_buffer
C struct with another 10 elements.
http://docs.python.org/dev/3.0/c-api/buffer.html#PyObject_GetBuffer
Can we please get something simple like PyObject_AsReadBuffer() back
into Python 3 ?
http://docs.python.org/c-api/objbuffer.html
(and ideally, this should also work on memoryview objects)
Thanks,
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, Nov 25 2008)
>>> Python/Zope Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
2008-11-12: Released mxODBC.Connect 0.9.3 http://python.egenix.com/
:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
More information about the Python-3000
mailing list