From: Lisandro Dalcin Date: Wed, 10 Mar 2010 20:03:40 +0000 (-0300) Subject: casting to typedef pointer/array types (ticket #518) X-Git-Tag: 0.13.beta0~324 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=bd587ae54b66f76d61c62c79698b9f9e566fe6fc;p=cython.git casting to typedef pointer/array types (ticket #518) --- diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index cf7b8b7b..3d6a011f 100755 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -228,8 +228,9 @@ class CTypedefType(BaseType): def cast_code(self, expr_code): # If self is really an array (rather than pointer), we can't cast. # For example, the gmp mpz_t. - if self.typedef_base_type.is_ptr: - return self.typedef_base_type.cast_code(expr_code) + if self.typedef_base_type.is_array: + base_type = self.typedef_base_type.base_type + return CPtrType(base_type).cast_code(expr_code) else: return BaseType.cast_code(self, expr_code) diff --git a/tests/compile/cast_ctypedef_array_T518.pyx b/tests/compile/cast_ctypedef_array_T518.pyx new file mode 100644 index 00000000..5d105611 --- /dev/null +++ b/tests/compile/cast_ctypedef_array_T518.pyx @@ -0,0 +1,15 @@ +cdef extern from "cast_ctypedef_array_T518_helper.h": + cdef struct __foo_struct: + int i, j + ctypedef __foo_struct foo_t[1] + + void foo_init(foo_t) + void foo_clear(foo_t) + +cdef foo_t value +foo_init(value) +foo_clear(value) + +cdef void *pointer = value +foo_init(pointer) +foo_clear(pointer) diff --git a/tests/compile/cast_ctypedef_array_T518_helper.h b/tests/compile/cast_ctypedef_array_T518_helper.h new file mode 100644 index 00000000..6989227c --- /dev/null +++ b/tests/compile/cast_ctypedef_array_T518_helper.h @@ -0,0 +1,5 @@ +struct __foo_struct { int i, j; }; +typedef struct __foo_struct foo_t[1]; + +static void foo_init (foo_t v) { v[0].i = 0; v[0].j = 0; } +static void foo_clear (foo_t v) { v[0].i = 0; v[0].j = 0; }