On Nov 12, 2008, at 6:04 PM, Hoyt Koepke wrote:
> Hello,
>
> In trying to understand what is going on at the c level with some
> cython code, I found that the html code generated with cython -a
> doesn't always match the code in the c file.
It should always match, but sometimes there's some C extra code
hanging off.
> I attached a rather
> confusing case I found. It's line 125 in the html file and line 1720
> in the c code.
>
> In essence, I'm trying to do buffer access; the cython code is
>
> p1.y = y_edges[yi]
>
> where y_edges is a buffer and p1 is an extension type with y defined
> as an attribute. The (sensible) c code generated in gridworld.c is:
>
> __pyx_t_9 = __pyx_v_yi;
> __pyx_v_p1->y = (*__Pyx_BufPtrCContig1d(float *,
> __pyx_bstruct_y_edges.buf, __pyx_t_9, __pyx_bstride_0_y_edges
>
> However, the html file shows this plus a ton of junk:
>
> 125: p1.y = y_edges[yi]
> __pyx_t_9 = __pyx_v_yi;
> __pyx_v_p1->y = (*__Pyx_BufPtrCContig1d(float *,
> __pyx_bstruct_y_edges.buf, __pyx_t_9, __pyx_bstride_0_y_edges));
>
> __pyx_2 = PyObject_GetAttr(__pyx_v_iterator,
> __pyx_kp_next); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[1];
> __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L13_error;}
> __pyx_3 = PyObject_Call(__pyx_2, ((PyObject
> *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_3)) {__pyx_filename =
> __pyx_f[1]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto
> __pyx_L13_error;}
> Py_DECREF(__pyx_2); __pyx_2 = 0;
> __pyx_2 = __Pyx_GetItemInt(__pyx_3, 1, 0); if (!__pyx_2)
> {__pyx_filename = __pyx_f[1]; __pyx_lineno = 125; __pyx_clineno =
> __LINE__; goto __pyx_L13_error;}
> Py_DECREF(__pyx_3); __pyx_3 = 0;
> __pyx_3 = __Pyx_GetItemInt(__pyx_2, 0, 0); if (!__pyx_3)
> {__pyx_filename = __pyx_f[1]; __pyx_lineno = 125; __pyx_clineno =
> __LINE__; goto __pyx_L13_error;}
> Py_DECREF(__pyx_2); __pyx_2 = 0;
> if (!(__Pyx_TypeTest(__pyx_3, __pyx_ptype_5numpy_dtype)))
> {__pyx_filename = __pyx_f[1]; __pyx_lineno = 125; __pyx_clineno =
> __LINE__; goto __pyx_L13_error;}
> Py_DECREF(((PyObject *)__pyx_v_descr));
> __pyx_v_descr = ((PyArray_Descr *)__pyx_3);
> __pyx_3 = 0;
> }
> goto __pyx_L17_try;
> __pyx_L13_error:;
> Py_XDECREF(__pyx_2); __pyx_2 = 0;
> Py_XDECREF(__pyx_3); __pyx_3 = 0;
>
> 126: ....
It looks like your line is just before a loop? What is going on here
is that the compiler periodically emmits something that says "I'm at
this spot now" and the annotator tries to make correspondences
between the Cython and C code based on that. If you finish a line,
but the compiler doesn't explicitly say it's working on the next
line, then all the extra stuff gets appended to the end. This also
happens at the end of functions, etc. where there is cleanup code
that gets tagged onto the last line.
> If you'd like me to file a bug report, I'd be happy to. I'm using the
> latest version of cython from the repo, 1321:6e8c09631af4.
Yes, please do. Try and get it down to the smallest example that
generates this behavior, if possible.
- Robert
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev