Added test case and fixed bug with unsigned indexing
authorDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Fri, 25 Jul 2008 13:48:30 +0000 (15:48 +0200)
committerDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Fri, 25 Jul 2008 13:48:30 +0000 (15:48 +0200)
Cython/Compiler/Buffer.py
tests/run/bufaccess.pyx

index 9f318a68158b777c9e522da0c56709b7194bbe1c..a4f1068275e6c25dfa6ca40d326f7f0492c0740e 100644 (file)
@@ -128,7 +128,7 @@ def put_access(entry, index_types, index_cnames, tmp_cname, pos, code):
                     code.unlikely("%s < 0" % cname), tmp_cname, idx))
             code.put("} else ")
         else:
-            if idx > 0: code.put("else ")
+            if idx > 0: code.put("else ")
         if boundscheck:
             # check bounds in positive direction
             code.putln("if (%s) %s = %d;" % (
index a0bff64848332d27e2533a49e8ccac00ee1dcb78..33db4f09c6e222f7b9be3e696873d95cf368bdde 100644 (file)
@@ -91,7 +91,15 @@ Out-of-bounds errors:
         ...
     IndexError: Out of bounds on buffer access (axis 1)
 
-    
+Unsigned indexing:
+    >>> get_int_2d_uintindex(C, 0, 0)
+    acquired C
+    released C
+    0
+    >>> get_int_2d_uintindex(C, 1, 2)
+    acquired C
+    released C
+    5
      
 """
 
@@ -154,7 +162,13 @@ def printbuf_int_2d(o, shape):
 
 def get_int_2d(object[int, 2] buf, int i, int j):
     return buf[i, j]
+
+
+def get_int_2d_uintindex(object[int, 2] buf, unsigned int i, unsigned int j):
+    # This is most interesting with regards to the C code
+    # generated.
+    return buf[i, j]
+
 cdef class MockBuffer:
     cdef object format
     cdef char* buffer