New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid code generated with array typedef #1984

Open
jdemeyer opened this Issue Nov 7, 2017 · 0 comments

Comments

Projects
None yet
1 participant
@jdemeyer
Contributor

jdemeyer commented Nov 7, 2017

The following generates invalid C code with Cython 0.27.2:

ctypedef int int_arr[100]

cdef class X:
    cdef int_arr arr
    cdef foo(self):
        cdef int* ptr = self.arr

The assignment ptr = self.arr is compiled with an extra temporary (why?) of type int_arr which is not legal. The relevant part of the generated C code:

static PyObject *__pyx_f_6cytest_1X_foo(struct __pyx_obj_6cytest_X *__pyx_v_self) {
  int *__pyx_v_ptr;
  __pyx_t_6cytest_int_arr __pyx_t_1;

  __pyx_t_1 = __pyx_v_self->arr;
  __pyx_v_ptr = __pyx_t_1;

Interestingly, with an explicit cast cdef int* ptr = <int*>self.arr, no temporary is used:

__pyx_v_ptr = ((int *)__pyx_v_self->arr);

vbraun added a commit to vbraun/sage that referenced this issue Dec 13, 2017

Trac #24259: Declare Integer.value as array
Work around cython/cython#1984

URL: https://trac.sagemath.org/24259
Reported by: jdemeyer
Ticket author(s): Jeroen Demeyer
Reviewer(s): Marc Mezzarobba
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment