Closed robertwb closed 8 years ago
Comment by robertwb on 3 Aug 2008 05:42 UTC Note that Pyx_PyBool_FromLong and Pyx_PyObject_IsTrue are macros, and the compiler should be able to unwind the definitions to do the right thing here.
However, the reason this happens is that your "and" has a Python expression on the right, so the left operand is converted to a Python expression as well. You can cast the right to a bint to get what you want.
Comment by anonymous on 10 Aug 2008 20:59 UTC I'm not at all convinced that it is a safe assumption to assume that gcc will optimize this away under all circumstances. (In particular note that PyBool_FromLong increments true or false, but is true does not undo this, so not all of the effects will get optimized away). There is a workaround so this is not a high priority either way (if the compiler does not optimize it away, we can use bints, and if it does, additions are quick).
Modified by robertwb on 19 Aug 2008 04:36 UTC
Comment by Stefan Behnel on 5 Sep 2008 09:30 UTC I agree that a boolean statement should stay in C space as long as possible. So, instead of emitting a type conversion depending on any of the subexpressions being Python expressions, we should look at each side of a boolean operator separately, as that's the way it's evaluated in the C code anyway.
Comment by robertwb on 29 Oct 2008 00:23 UTC This has been done: http://hg.cython.org/cython-devel/rev/c2374c45d350
Reported by gfurnish on 2 Aug 2008 12:17 UTC Consider:
Note it is converting the result of a C boolean compare to a Python boolean object, then converting it back to a C boolean.
Migrated-From: http://trac.cython.org/ticket/38