[Cython] Bug: bad C code generated for (some) "... and ... or ..." expressions

Dieter Maurer dieter at handshake.de
Thu Jun 7 10:44:09 CEST 2012

"cython 0.13" generates bad C code for the attached "pyx" file.

"cython" itself recognizes that it did something wrong and emits "<error>;"
to the generated file:

static  __pyx_t_12cybug_and_or_pointer __pyx_f_12cybug_and_or_bug(PyObject *__pyx_v_o) {
  __pyx_t_12cybug_and_or_pointer __pyx_r;
  int __pyx_t_1;
  __pyx_t_12cybug_and_or_pointer __pyx_t_2;

-------------- next part --------------
A non-text attachment was scrubbed...
Name: cybug_and_or.pyx
Type: text/x-cython
Size: 164 bytes
Desc: "cython" source file triggering bad C code generation
URL: <http://mail.python.org/pipermail/cython-devel/attachments/20120607/00c913e8/attachment.bin>
-------------- next part --------------

The error probably happens because it is difficult for "cython" to
determine the type for "and" and "or" expressions (if the operand types
differ). In an "cond and t or f" expression, however, the result type
is "type(t)" if "type(t) == type(f)", independent of "type(cond)".

It might not be worse to special case this type of expressions.
It would however be more friendly to output an instructive
error message instead of generating bad C code.


More information about the cython-devel mailing list