On 27 June 2012 13:48, Stefan Behnel <stefan...@behnel.de> wrote: > mark florisson, 27.06.2012 14:17: >> On 27 June 2012 12:59, Stefan Behnel wrote: >>> mark florisson, 27.06.2012 11:54: >>>> I can't test it right now, but I don't understand the following in the >>>> release notes (regarding array.array): "Note that only the buffer >>>> syntax is supported for these arrays. To use memoryviews with them, >>>> use the buffer syntax to unpack the buffer first.". Why is that, it >>>> implements __getbuffer__ right? So it shouldn't matter whether you use >>>> memoryviews or buffer syntax, both use __Pyx_GetBuffer(). >>> >>> The problem is that arrayarray.pxd is only used when the exporter is typed. >>> This means that you can't do this: >>> >>> def func(int[:] arr): pass >>> >>> func(array.array('i', [1,2,3])) >> >> That works for me, as long and array is cimported from cpython (as >> 'array' or some other name). It will patch __Pyx_GetBuffer with a >> typecheck and a call to its __getbuffer__ method. > > Hmm, interesting. I keep learning. I'll add tests for that. > > For the memoryview_type and array_type checks, wouldn't a type identity > test be enough instead of a PyObject_TypeCheck() ? > > Stefan > _______________________________________________ > cython-devel mailing list > cython-devel@python.org > http://mail.python.org/mailman/listinfo/cython-devel
Well, you want it to work for subclasses as well. I think the only thing that doesn't work (pre-2.6), is overriding __getbuffer__ in a subclass outside of the module or pxd. For memoryviews, since each module has a different memoryview type, I inject a capsule in tp_dict, which __Pyx_GetBuffer checks for (it's called __pyx_getbuffer and __pyx_releasebuffer). _______________________________________________ cython-devel mailing list cython-devel@python.org http://mail.python.org/mailman/listinfo/cython-devel