[Cython] On GetBuffer/ReleaseBuffer (attn: Stefan)

Robert Bradshaw robertwb at math.washington.edu
Tue Jul 29 18:38:34 CEST 2008


On Jul 29, 2008, at 4:51 AM, Dag Sverre Seljebotn wrote:

> First, Stefan: In tests/run/buffer.pyx I saw references to "obj ==  
> NULL"
> for locking the buffer. I can't seem find any references to this
> anywhere, any hints?
>
> Secondly, Robert answered a question I noted down for "asking  
> later" on
> the wiki so I'll respond to his response here.
>
> Me: Does any exceptions ReleaseBuffer might set matter? Should I start
> calling PyErr_Occurred?
>
> Robert: Don't call PyErr_Occurred, check the return value for -1  
> (which
> is what it is supposed to return on failure).
>
> Me again:
>
> Note that PyObject_ReleaseBuffer is defined like this:
>
> PyAPI_FUNC(void) PyObject_ReleaseBuffer(PyObject *obj, Py_buffer  
> *view);

Ah, what I wrote was only relevant to PyObject_GetBuffer.

> Actually, it says in the PEP that the function "always succeeds".  
> But I
> would guess that we don't actually enforce that for Cython-implemented
> __releasebuffer__? So ideally one would raise a compiler error if  
> there
> was a chance that an exception would be propagated from ReleaseBuffer
> (much like Java does for some exceptions)...

I think the thing to do here is use write_unraisable (or whatever  
that method is called). Since the C/API assumes that the function  
always succeeds, setting an exception here wouldn't get cleaned up  
correctly in Python code.

- Robert




More information about the Cython-dev mailing list