"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;
  <error>;
  <error>;
...

ctypedef void * pointer

cdef extern from "nonexistant.h":
  cdef pointer to_pointer(object)

cdef pointer bug(o):
  return o is not None and to_pointer(o) or NULL

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.

--
Dieter
_______________________________________________
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel

Reply via email to