[Python-3000] Using memoryviews
M.-A. Lemburg
mal at egenix.com
Fri Nov 21 20:41:51 CET 2008
On 2008-11-21 17:30, Josiah Carlson wrote:
> On Thu, Nov 20, 2008 at 2:12 AM, M.-A. Lemburg <mal at egenix.com> wrote:
>> I've had a look at the new memoryview and associated buffer API
>> and have a question: how is a C extension supposed to use the buffer
>> API without going directly into the C struct Py_buffer ?
>>
>> I have not found any macros for accessing Py_buffer internals and
>> the docs mention the struct members directly (which is a bit unusual
>> for the Python C API).
>>
>> Shouldn't there be a set of macros providing some form of abstraction
>> for the struct members ?
>>
>> BTW: I was looking for a suitable replacement for the buffer object
>> which isn't available in Python 3 anymore.
>>
>> Thanks,
>> --
>> Marc-Andre Lemburg
>> eGenix.com
>
>>From what I understand of the memoryview when I tried to do the same
> thing a few months ago (use memoryview to replace buffer in
> asyncore/asynchat), memoryview is incomplete. It didn't support
> character buffer slicing (you know, the 'offset' and 'size' arguments
> that were in buffer), and at least a handful of other things (that I
> can't remember at the moment).
True, memoryview objects aren't as useful in Python as the underlying
Py_buffer "C" objects are in the C API.
But then I only need it to signal "this is binary data" for the purpose
of using the memoryview in DB-API extensions.
However, this would only be of effective use if there's a documented way
of accessing the actual C char* buffer behind the object, instead of
having to allocate a new buffer and copy the data over - only to reference
it like that.
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.
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, Nov 21 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