Possible bug related to multiple assignment
Hi, I ran into some odd behavior when working on my cython-based project (h5py). The following cython code snippet is the culprit ("priv" is a function argument of type void**): cdef conv_size_t *sizes priv[0] = sizes = <conv_size_t*>malloc(sizeof(conv_size_t)) gets turned into this (with Cython 0.14.1): (__pyx_v_priv[0]) = ((__pyx_t_4h5py_5_conv_conv_size_t *)malloc((sizeof(__pyx_t_4h5py_5_conv_conv_size_t)))); __pyx_v_sizes = ((__pyx_t_4h5py_5_conv_conv_size_t *)malloc((sizeof(__pyx_t_4h5py_5_conv_conv_size_t)))); which leads to much head-scratching when one initializes "sizes", and then later tries to recover that value via "priv". Interestingly, Cython 0.13 correctly initializes both priv[0] and sizes to the same value: __pyx_t_5 = ((__pyx_t_4h5py_5_conv_conv_size_t *)malloc((sizeof(__pyx_t_4h5py_5_conv_conv_size_t)))); (__pyx_v_priv[0]) = __pyx_t_5; __pyx_v_sizes = __pyx_t_5; I wasn't able to find anything on this in the list archives or issue tracker. Right now I'm working around it by splitting the statement into multiple lines: sizes = <conv_size_t*>malloc(sizeof(conv_size_t)) priv[0] = sizes Andrew
Andrew Collette, 16.06.2011 04:51:
I ran into some odd behavior when working on my cython-based project (h5py). The following cython code snippet is the culprit ("priv" is a function argument of type void**):
cdef conv_size_t *sizes priv[0] = sizes =<conv_size_t*>malloc(sizeof(conv_size_t))
gets turned into this (with Cython 0.14.1):
(__pyx_v_priv[0]) = ((__pyx_t_4h5py_5_conv_conv_size_t *)malloc((sizeof(__pyx_t_4h5py_5_conv_conv_size_t)))); __pyx_v_sizes = ((__pyx_t_4h5py_5_conv_conv_size_t *)malloc((sizeof(__pyx_t_4h5py_5_conv_conv_size_t))));
This is fixed in the latest master branch. And, yes, we're long overdue for a release. Stefan
Stefan Behnel, 16.06.2011 09:46:
Andrew Collette, 16.06.2011 04:51:
I ran into some odd behavior when working on my cython-based project (h5py). The following cython code snippet is the culprit ("priv" is a function argument of type void**):
cdef conv_size_t *sizes priv[0] = sizes =<conv_size_t*>malloc(sizeof(conv_size_t))
gets turned into this (with Cython 0.14.1):
(__pyx_v_priv[0]) = ((__pyx_t_4h5py_5_conv_conv_size_t *)malloc((sizeof(__pyx_t_4h5py_5_conv_conv_size_t)))); __pyx_v_sizes = ((__pyx_t_4h5py_5_conv_conv_size_t *)malloc((sizeof(__pyx_t_4h5py_5_conv_conv_size_t))));
This is fixed in the latest master branch.
Ah, sorry. It was actually broken, even though my test run initially told me otherwise. Strange ... The problem was the C type cast, which was incorrectly considered a "simple" expression that didn't need a temporary assignment. Malloc is the most obvious case where this hits, as it's almost always used through a cast. It's fixed now. Thanks for report and example. Stefan
participants (2)
-
Andrew Collette -
Stefan Behnel