Ticket #133 (closed defect: fixed)
Illegal casting caused by new PyDict_Next iteration with typed variables
|Reported by:||hoytak||Owned by:||scoder|
It seems that I've hit a bug in the new dictionary iteration stuff (which is quite awesome, BTW). I'm using revision 1374:85a5fdd79388 (new at time of writing).
In iteration over a dictionary, I'm declaring both the variables of iteration to have explicit types; i.e. my code is:
cdef int k cdef double v for k, v in d.iteritems(): # do things
However, in the c code, I find the following:
int __pyx_v_k; double __pyx_v_v; ... void *__pyx_t_2; void *__pyx_t_3; ... if (!PyDict_Next(__pyx_t_1, (&__pyx_5), ((PyObject**)(&__pyx_t_2)), ((PyObject **)(&__pyx_t_3)))) break; __pyx_v_k = ((int)__pyx_t_2); __pyx_v_v = ((double)__pyx_t_3);
In other words, it's trying to do a cast directly from a void* type, which isn't allowed by gcc (The void* to int cast seems problematic as well). Thus the code fails on compilation.
If I replace the above loop with
for k_o, v_o in d.iteritems(): k = k_o v = v_o # do things
It works fine.