Buffers: Allow repeat count of 1 on single item format strings
authorDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Wed, 6 Aug 2008 23:13:53 +0000 (01:13 +0200)
committerDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Wed, 6 Aug 2008 23:13:53 +0000 (01:13 +0200)
Cython/Compiler/Buffer.py
tests/run/bufaccess.pyx

index 1e3df3ec9969272becd402bfcfea715af5aa273b..6361e6196a75e303aed7b958e7790b30ed6d700f 100644 (file)
@@ -450,6 +450,7 @@ def get_ts_check_item(dtype, writer):
         if char is not None:
                 # Can use direct comparison
             code = dedent("""\
+                if (*ts == '1') ++ts;
                 if (*ts != '%s') {
                   PyErr_Format(PyExc_ValueError, "Buffer datatype mismatch (rejecting on '%%s')", ts);
                   return NULL;
@@ -461,6 +462,7 @@ def get_ts_check_item(dtype, writer):
             ctype = dtype.declaration_code("")
             code = dedent("""\
                 int ok;
+                if (*ts == '1') ++ts;
                 switch (*ts) {""", 2)
             if dtype.is_int:
                 types = [
index c2b20e31bef103cd7543f556c9f083e02b5985ae..45050fcb4d7031ed106220f603a154a44cb612ce 100644 (file)
@@ -944,14 +944,14 @@ cdef class ShortMockBuffer(MockBuffer):
         (<short*>buf)[0] = <short>value
         return 0
     cdef get_itemsize(self): return sizeof(short)
-    cdef get_default_format(self): return "=h"
+    cdef get_default_format(self): return "h" # Try without endian specifier
 
 cdef class UnsignedShortMockBuffer(MockBuffer):
     cdef int write(self, char* buf, object value) except -1:
         (<unsigned short*>buf)[0] = <unsigned short>value
         return 0
     cdef get_itemsize(self): return sizeof(unsigned short)
-    cdef get_default_format(self): return "=H"
+    cdef get_default_format(self): return "=1H" # Try with repeat count
 
 cdef extern from *:
     void* addr_of_pyobject "(void*)"(object)