From a19e36ee5d2a6b230498a15503dcb47cf4d62742 Mon Sep 17 00:00:00 2001 From: Dag Sverre Seljebotn Date: Thu, 7 Aug 2008 01:13:53 +0200 Subject: [PATCH] Buffers: Allow repeat count of 1 on single item format strings --- Cython/Compiler/Buffer.py | 2 ++ tests/run/bufaccess.pyx | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Cython/Compiler/Buffer.py b/Cython/Compiler/Buffer.py index 1e3df3ec..6361e619 100644 --- a/Cython/Compiler/Buffer.py +++ b/Cython/Compiler/Buffer.py @@ -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 = [ diff --git a/tests/run/bufaccess.pyx b/tests/run/bufaccess.pyx index c2b20e31..45050fcb 100644 --- a/tests/run/bufaccess.pyx +++ b/tests/run/bufaccess.pyx @@ -944,14 +944,14 @@ cdef class ShortMockBuffer(MockBuffer): (buf)[0] = 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: (buf)[0] = 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) -- 2.26.2