[Cython] Buffer API changed in Py3b3
Dag Sverre Seljebotn
dagss at student.matnat.uio.no
Mon Aug 25 21:47:34 CEST 2008
Andrew Straw wrote:
> Dag Sverre Seljebotn wrote:
>> Stefan Behnel wrote:
>>
>>> Dag Sverre Seljebotn wrote:
>>>
>>>> As for Python 2.6, it appears that we have the option to generate
>>>> objects using the new buffer slots, but we can also generate objects
>>>> without. Thoughts?
>>>>
>>>> Mine: At least as long as NumPy doesn't implement this for 2.6, I'd like
>>>> to stay with emulation. If I get the time then perhaps a "dual-mode"
>>>> where the slots are checked first, and if the object doesn't have the
>>>> slots (i.e. the flags of the type is set to not supporting the new
>>>> buffers) then emulation is used.
>>>>
>>> If I understand correctly, you only refer to /getting/ the buffer of a
>>> however implemented object, not about implementing the __getbuffer__()
>>> method, right? So Cython implemented buffer objects would have their
>>> __getbuffer__() in any case?
>>>
>> Not sure I understand this.
>>
>> The point anyway is that Cython currently does not fill the getbuffer
>> slot on Py2.6. However, if we added Py_TPFLAGS_HAVE_NEWBUFFER to the
>> type flags it seems we could do this, right? (I don't know much about
>> these things so I'll have to listen to you here.)
>>
>> So the real question is whether we should change things so that
>> bf_getbuffer is filled in under Py2.6; I suppose this calls for changing
>> tp_flags on the classes which has __getbuffer__ or __releasebuffer__
>> implemented.
>>
>>
> The whole reason I started using Cython and the PyObject_GetBuffer()
> stuff is to move my code (e.g.
> http://code.astraw.com/projects/motmot/browser/trunk/FastImage/src/FastImage.pyx
> ) away from the __array_interface__ and __array_struct__ conventions and
> move to the now standard Python mechanism. I'd much prefer to do this
> with 2.6 than 3.0. Two serious issues with not doing it:
(However, you still need those if you want to construct ndarrays from
them until NumPy grows PEP-3118 support.)
Thanks for the feedback, and you are absolutely right, I'll see if I can
get around to it sometime. This is now
http://trac.cython.org/cython_trac/ticket/62
(I don't think fixing the inheritance in the emulation is awfully
difficult if you suddenly have a desperate need for it, it is just a
matter of sorting a list by inheritance somewhere, but with everything
moving towards slots anyway I suppose I should spend my time elsewhere.)
--
Dag Sverre
More information about the Cython-dev
mailing list