Buffer: Cleanup. There are no unsigned floats.
authorDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Sun, 19 Apr 2009 21:16:05 +0000 (23:16 +0200)
committerDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Sun, 19 Apr 2009 21:16:05 +0000 (23:16 +0200)
Cython/Compiler/Buffer.py
tests/run/bufaccess.pyx

index 2d72c56f8d13136abe60721820f0facebd792dec..04a721c04184c7a80d04d67e18272e972140acf2 100644 (file)
@@ -567,18 +567,21 @@ def create_typestringchecker(protocode, defcode, name, dtype):
                     ('b', 'char'), ('h', 'short'), ('i', 'int'),
                     ('l', 'long'), ('q', 'long long')
                 ]
+                if dtype.signed == 0:
+                    for char, against in types:
+                        defcode.putln("case '%s': ok = (sizeof(%s) == sizeof(%s) && (%s)-1 > 0); break;" %
+                                      (char.upper(), ctype, against, ctype))
+                else:
+                    for char, against in types:
+                        defcode.putln("case '%s': ok = (sizeof(%s) == sizeof(%s) && (%s)-1 < 0); break;" %
+                                      (char, ctype, against, ctype))
             elif dtype.is_float:
                 types = [('f', 'float'), ('d', 'double'), ('g', 'long double')]
-            else:
-                assert False
-            if dtype.signed == 0:
                 for char, against in types:
-                    defcode.putln("case '%s': ok = (sizeof(%s) == sizeof(unsigned %s) && (%s)-1 > 0); break;" %
-                                  (char.upper(), ctype, against, ctype))
+                    defcode.putln("case '%s': ok = (sizeof(%s) == sizeof(%s)); break;" %
+                                  (char, ctype, against))
             else:
-                for char, against in types:
-                    defcode.putln("case '%s': ok = (sizeof(%s) == sizeof(%s) && (%s)-1 < 0); break;" %
-                                  (char, ctype, against, ctype))
+                assert False
             defcode.putln("default: ok = 0;")
             defcode.putln("}")
         put_assert("ok", "expected %s, got %%s" % dtype)
@@ -670,11 +673,6 @@ 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);
@@ -690,6 +688,11 @@ def get_getbuffer_code(dtype, code):
               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 (buf->suboffsets == NULL) buf->suboffsets = __Pyx_minusones;
           return 0;
         fail:;
index 81d2238dd980a0ff6f81d5424f806caf18dceb8e..155e9e181ca28fc62ec27ae521fbee786fd3d846 100644 (file)
@@ -1033,7 +1033,7 @@ def buffer_cast_fails(object[char, cast=True] buf):
     >>> buffer_cast_fails(IntMockBuffer(None, [0]))
     Traceback (most recent call last):
         ...
-    ValueError: Attempted cast of buffer to datatype of different size.
+    ValueError: Item size of buffer does not match size of 'char'
     """
     return buf[0]