# typedef_base_type PyrexType
is_typedef = 1
+ typestring = None # Because typedefs are not known exactly
def __init__(self, cname, base_type):
self.typedef_cname = cname
exception_check = 0
to_py_function = "dummy"
from_py_function = "dummy"
+ typestring = None
def declaration_code(self, entity_code,
for_display = 0, dll_linkage = None, pyrex = 0):
print
+#
+# Typedefs
+#
+ctypedef int cytypedef_int
+cdef extern from "bufaccess.h":
+ ctypedef cytypedef_int htypedef_short # Defined as short, but Cython doesn't know this!
+ctypedef htypedef_short cytypedef2
+
+@testcase
+def printbuf_cytypedef_int(object[cytypedef_int] buf, shape):
+ """
+ >>> printbuf_cytypedef_int(IntMockBuffer("A", range(3)), (3,))
+ acquired A
+ 0 1 2
+ released A
+ >>> printbuf_cytypedef_int(ShortMockBuffer("B", range(3)), (3,))
+ Traceback (most recent call last):
+ ...
+ ValueError: Buffer datatype mismatch (rejecting on 'h')
+
+ """
+ cdef int i
+ for i in range(shape[0]):
+ print buf[i],
+ print
+
+@testcase
+def printbuf_htypedef_short(object[htypedef_short] buf, shape):
+ """
+ >>> printbuf_htypedef_short(ShortMockBuffer("A", range(3)), (3,))
+ acquired A
+ 0 1 2
+ released A
+ >>> printbuf_htypedef_short(IntMockBuffer("B", range(3)), (3,))
+ Traceback (most recent call last):
+ ...
+ ValueError: Buffer datatype mismatch (rejecting on 'i')
+ """
+
+ cdef int i
+ for i in range(shape[0]):
+ print buf[i],
+ print
+
+@testcase
+def printbuf_cytypedef2(object[cytypedef2] buf, shape):
+ """
+ >>> printbuf_cytypedef2(ShortMockBuffer("A", range(3)), (3,))
+ acquired A
+ 0 1 2
+ released A
+ >>> printbuf_cytypedef2(IntMockBuffer("B", range(3)), (3,))
+ Traceback (most recent call last):
+ ...
+ ValueError: Buffer datatype mismatch (rejecting on 'i')
+ """
+
+ cdef int i
+ for i in range(shape[0]):
+ print buf[i],
+ print
+
+
+
+
+#
+# Testcase support code
+#
+
+
available_flags = (
('FORMAT', python_buffer.PyBUF_FORMAT),
('INDIRECT', python_buffer.PyBUF_INDIRECT),
cdef get_itemsize(self): return sizeof(int)
cdef get_default_format(self): return "=i"
+cdef class ShortMockBuffer(MockBuffer):
+ cdef int write(self, char* buf, object value) except -1:
+ (<short*>buf)[0] = <short>value
+ return 0
+ cdef get_itemsize(self): return sizeof(short)
+ cdef get_default_format(self): return "=h"
+
cdef class UnsignedShortMockBuffer(MockBuffer):
cdef int write(self, char* buf, object value) except -1:
(<unsigned short*>buf)[0] = <unsigned short>value