cython-devel
changeset 3080:982665cb1a01
casting to typedef pointer/array types (ticket #518)
| author | Lisandro Dalcin <dalcinl@gmail.com> |
|---|---|
| date | Wed Mar 10 17:03:40 2010 -0300 (23 months ago) |
| parents | 3345e2713fcb |
| children | 6098efe6c0028375dde09078 |
| files | Cython/Compiler/PyrexTypes.py tests/compile/cast_ctypedef_array_T518.pyx tests/compile/cast_ctypedef_array_T518_helper.h |
line diff
1.1 --- a/Cython/Compiler/PyrexTypes.py Wed Mar 10 10:46:44 2010 -0800
1.2 +++ b/Cython/Compiler/PyrexTypes.py Wed Mar 10 17:03:40 2010 -0300
1.3 @@ -228,8 +228,9 @@
1.4 def cast_code(self, expr_code):
1.5 # If self is really an array (rather than pointer), we can't cast.
1.6 # For example, the gmp mpz_t.
1.7 - if self.typedef_base_type.is_ptr:
1.8 - return self.typedef_base_type.cast_code(expr_code)
1.9 + if self.typedef_base_type.is_array:
1.10 + base_type = self.typedef_base_type.base_type
1.11 + return CPtrType(base_type).cast_code(expr_code)
1.12 else:
1.13 return BaseType.cast_code(self, expr_code)
1.14
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/tests/compile/cast_ctypedef_array_T518.pyx Wed Mar 10 17:03:40 2010 -0300
2.3 @@ -0,0 +1,15 @@
2.4 +cdef extern from "cast_ctypedef_array_T518_helper.h":
2.5 + cdef struct __foo_struct:
2.6 + int i, j
2.7 + ctypedef __foo_struct foo_t[1]
2.8 +
2.9 + void foo_init(foo_t)
2.10 + void foo_clear(foo_t)
2.11 +
2.12 +cdef foo_t value
2.13 +foo_init(value)
2.14 +foo_clear(value)
2.15 +
2.16 +cdef void *pointer = <void*> value
2.17 +foo_init(<foo_t>pointer)
2.18 +foo_clear(<foo_t>pointer)
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/tests/compile/cast_ctypedef_array_T518_helper.h Wed Mar 10 17:03:40 2010 -0300
3.3 @@ -0,0 +1,5 @@
3.4 +struct __foo_struct { int i, j; };
3.5 +typedef struct __foo_struct foo_t[1];
3.6 +
3.7 +static void foo_init (foo_t v) { v[0].i = 0; v[0].j = 0; }
3.8 +static void foo_clear (foo_t v) { v[0].i = 0; v[0].j = 0; }
