Stefan Krah <stefan-use...@bytereef.org> added the comment:

Here's a completely restructured memoryview implementation that I believe
is quite robust. Both memoryobject.c (the parts I worked on, which is 91%)
and _testbuffer.c have 100% code coverage, including all error conditions [1].

memoryview is tested against the struct module (via _testbuffer's ndarray),
array.array and bytearray. To deal with the case explosions inherent to the
specification test_buffer.py resorts to brute force in some cases (most
notably in testing getbuffer() flags).

PyMemoryViewObject is now a PyVarObject with private arrays. Unless ndim = 0,
shape and strides are always present after initialization.

Memoryview now has support for all native single-value struct module
specifiers. I abandoned the idea of using the struct module for
packing/unpacking. New benchmarks (See #10227) indicate that _testbuffer's
tolist() is over 1000x slower that the optimized versions of memoryview.

The cast function from #5231 is completely implemented.


Review would be much appreciated. Perhaps it would be possible to
do a mini PEP-3118 sprint? Usually I'm never on IRC, but I could
dust off irssi for the occasion.


These are the main changes in detail:
-------------------------------------

o Restructure memoryobject.c into sections.

o Use struct hack in PyMemoryViewObject for the dynamic arrays.

o Rework initialization.

o Add a couple of invariants: A new memoryview will always have complete
  shape/strides/format information, unless ndim = 0.

o Add buffer flags: A new memoryview will always have flag information
  that determines whether it is a scalar (ndim = 0), C/Fortran contiguous,
  NumPY or PIL style, released or active. This eliminates the need for
  expensive re-computations during a getbuffer() request.

o Add support for all native struct module formats in indexing, assigning
  and tolist().

o Add memoryview.cast(format=x, shape=y), where x is a native format specifier
  and y is any multidimensional shape.

o Add PEP-3118 compliant getbuffer() method.

o Slice assignments now support non-contiguous 1-D slices.

o Comparisons now support non-contiguous 1-D buffers.

o Representation of empty shape etc. is now an empty tuple (O.K.
  with Mark Dickinson and Travis Oliphant).


[1] 100% coverage requires a patch for systematically triggering failures
    of Python API functions.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue10181>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to