[Cython] Buffer API changed in Py3b3
Dag Sverre Seljebotn
dagss at student.matnat.uio.no
Sat Aug 23 13:30:28 CEST 2008
Stefan Behnel wrote:
> Hi,
>
> the buffer API changed in Py3b3, without updating the PEP. The reasoning
> behind the changes were discussed in full length here:
>
> http://bugs.python.org/issue3139
>
> Here's an incomplete patch that updates the struct, but that's definitely not
> enough, so I hope that Dag finds some time to fix things up.
Yes, I do; consider this assigned to me. Some issues needs discussion
though:
1) I didn't find an answer to: It is still assumed that the caller holds
a reference to the object that was the source of the buffer for the
lifetime of it? I've made this assumption for now (as Cython always does
it anyway). This didn't seem clear from the discussion. But at least
there are checks for info.obj being NULL so it seems to be optional,
i.e. if releasebuffer is not needed one does not need to set it?
2) How do we let people write their own __getbuffer__? I.e. one should
be able to fill in info.obj to an object (and perhaps NULL), but still
incref/decref it in a friendly Cython fashion.
I think one should type info.obj as "object" and insert code
automatically at the beginning of __getbuffer__ to initialize it
(without a decref to invalid memory).
If the answer to 1) is "it should always hold a reference to something",
just assigning None and then let the function assign something else is
enough.
But if the answer to 1) is that it can be NULL, we need to be more
creative. Two options:
a) Type it to some kind of "object-which-can-be-NULL" (not sure if we
have that, one would perhaps need to add that type), so that it gets
Py_XDECREF-ed on assignment and can be assigned NULL explicitly (and
initialize it to NULL).
b) Insert code when exiting __getbuffer__ and __releasebuffer__ which
converts None to NULL in the info.obj field.
--
Dag Sverre
More information about the Cython-dev
mailing list