Exposing buffer interface for non-extension types?

Ken Watford kwatford+python at gmail.com
Tue Jul 20 20:38:27 EDT 2010


On Tue, Jul 20, 2010 at 6:58 PM, Stefan Behnel <stefan_ml at behnel.de> wrote:
> Ken Watford, 21.07.2010 00:09:
>>
>> Is there any way to expose the PEP 3118 buffer interface for objects
>> that aren't extension types?
>
> Given that it's a pure C-level interface, I don't think there would be much
> use for that.

Perhaps, but *why* is it only a pure C-level interface? It's based
on/inspired by the array interface, which was not a pure C-level
interface. Did they simply neglect to provide the functionality due to
lack of obvious use cases, or did they consciously decide to drop that
functionality?

>> Currently, I can expose the NumPy array interface (using either
>> __array_interface__ or __array_struct__) for any class, extension or
>> otherwise. But I can't find any reference to python-side interfacing
>> for PEP 3118. SWIG makes an extension module for your wrapped code,
>> but not extension *types*, so the classes it produces are pure-python
>> with methods added in from the extension module.
>
> Try using Cython instead, it has native support for the buffer protocol.

I've used Cython before, and I generally like it. But its purpose is
slightly different than SWIG's, and does not particularly meet my
current project's needs.



More information about the Python-list mailing list