[Cython] CEP1000: Native dispatch through callables

Stefan Behnel stefan_ml at behnel.de
Sun Apr 15 13:40:31 CEST 2012


mark florisson, 15.04.2012 13:30:
> Finally, what are the semantics for Py_buffer? Will the callee own the
> buffer, or will it borrow it? If they will borrow, then the compiler
> will have to figure out whether it will need to own it (or be slower
> and always own it), and acquire the buffer through buf->obj. At least
> it won't have to validate the buffer, which is the most expensive
> part.
> I think in many cases you want to borrow though, but if you want to
> always own, the caller could do something more efficient if
> releasebuffer is not implemented, like simply incref buf->obj and pass
> in a pointer to a copy of the Py_buffer. I think borrowing is probably
> the easiest and most sane way though.

I think that's easy. If you request and unpack a buffer yourself, you own
it. If you receive an unpacked buffer from someone else as a call argument,
you borrow it, and you know that your caller (or the caller of your caller,
etc.) owns it and keeps it alive until you return. If you receive it as
return value of a function call, it's less clear, but my intuition tells me
that you'd normally either receive an owned Python object or a borrowed
unpacked buffer.

In the case at hand, you'd always receive a borrowed buffer from the caller
as argument.

Stefan


More information about the cython-devel mailing list