From bd587ae54b66f76d61c62c79698b9f9e566fe6fc Mon Sep 17 00:00:00 2001 From: Lisandro Dalcin Date: Wed, 10 Mar 2010 17:03:40 -0300 Subject: [PATCH] casting to typedef pointer/array types (ticket #518) --- Cython/Compiler/PyrexTypes.py | 5 +++-- tests/compile/cast_ctypedef_array_T518.pyx | 15 +++++++++++++++ tests/compile/cast_ctypedef_array_T518_helper.h | 5 +++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 tests/compile/cast_ctypedef_array_T518.pyx create mode 100644 tests/compile/cast_ctypedef_array_T518_helper.h 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; } -- 2.26.2