From: Dag Sverre Seljebotn Date: Sun, 19 Apr 2009 21:06:10 +0000 (+0200) Subject: Buffer: Always do item size check X-Git-Tag: 0.11.2.rc1~54 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=5ba1940251836645eb6a21d573a0d0763f5cf4c9;p=cython.git Buffer: Always do item size check --- diff --git a/Cython/Compiler/Buffer.py b/Cython/Compiler/Buffer.py index 7934ea34..2d72c56f 100644 --- a/Cython/Compiler/Buffer.py +++ b/Cython/Compiler/Buffer.py @@ -670,6 +670,11 @@ def get_getbuffer_code(dtype, code): __Pyx_BufferNdimError(buf, nd); goto fail; } + if (buf->itemsize != sizeof(%(dtype_cname)s)) { + PyErr_SetString(PyExc_ValueError, + "Item size of buffer does not match size of %(dtype)s."); + goto fail; + } if (!cast) { ts = buf->format; ts = __Pyx_ConsumeWhitespace(ts); @@ -684,12 +689,6 @@ def get_getbuffer_code(dtype, code): __Pyx_DescribeTokenInFormatString(ts)); goto fail; } - } else { - if (buf->itemsize != sizeof(%(dtype_cname)s)) { - PyErr_SetString(PyExc_ValueError, - "Attempted cast of buffer to datatype of different size."); - goto fail; - } } if (buf->suboffsets == NULL) buf->suboffsets = __Pyx_minusones; return 0;