Commit eb3e1da1 authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

Fixed some typedef bugs with buffers

parent 5658d1f1
...@@ -149,6 +149,7 @@ class CTypedefType(BaseType): ...@@ -149,6 +149,7 @@ class CTypedefType(BaseType):
# typedef_base_type PyrexType # typedef_base_type PyrexType
is_typedef = 1 is_typedef = 1
typestring = None # Because typedefs are not known exactly
def __init__(self, cname, base_type): def __init__(self, cname, base_type):
self.typedef_cname = cname self.typedef_cname = cname
...@@ -1043,6 +1044,7 @@ class ErrorType(PyrexType): ...@@ -1043,6 +1044,7 @@ class ErrorType(PyrexType):
exception_check = 0 exception_check = 0
to_py_function = "dummy" to_py_function = "dummy"
from_py_function = "dummy" from_py_function = "dummy"
typestring = None
def declaration_code(self, entity_code, def declaration_code(self, entity_code,
for_display = 0, dll_linkage = None, pyrex = 0): for_display = 0, dll_linkage = None, pyrex = 0):
......
cimport e_bufaccess_pxd # was needed to provoke a bug involving ErrorType
def f():
cdef object[e_bufaccess_pxd.T] buf
_ERRORS = u"""
3:17: Syntax error in ctypedef statement
4:31: 'T' is not a type identifier
4:31: 'T' is not declared
"""
# See e_bufaccess2.pyx
ctypedef nothing T
...@@ -576,6 +576,76 @@ def printbuf_float(o, shape): ...@@ -576,6 +576,76 @@ def printbuf_float(o, shape):
print 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 = ( available_flags = (
('FORMAT', python_buffer.PyBUF_FORMAT), ('FORMAT', python_buffer.PyBUF_FORMAT),
('INDIRECT', python_buffer.PyBUF_INDIRECT), ('INDIRECT', python_buffer.PyBUF_INDIRECT),
...@@ -736,6 +806,13 @@ cdef class IntMockBuffer(MockBuffer): ...@@ -736,6 +806,13 @@ cdef class IntMockBuffer(MockBuffer):
cdef get_itemsize(self): return sizeof(int) cdef get_itemsize(self): return sizeof(int)
cdef get_default_format(self): return "=i" 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 class UnsignedShortMockBuffer(MockBuffer):
cdef int write(self, char* buf, object value) except -1: cdef int write(self, char* buf, object value) except -1:
(<unsigned short*>buf)[0] = <unsigned short>value (<unsigned short*>buf)[0] = <unsigned short>value
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment