From 5ba1940251836645eb6a21d573a0d0763f5cf4c9 Mon Sep 17 00:00:00 2001 From: Dag Sverre Seljebotn Date: Sun, 19 Apr 2009 23:06:10 +0200 Subject: [PATCH] Buffer: Always do item size check --- Cython/Compiler/Buffer.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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; -- 2.26.2