[Pyrex] is this an "if" bug?

Greg Ewing greg at cosc.canterbury.ac.nz
Thu Nov 27 00:44:51 CET 2003


Bryan Weingarten <bryan.weingarten at pobox.com>:

> the following pyrex code:
> if callback:
> 
> generates this c code.  notice the if (__pyx_2 < 0).  shouldn't that be 
> if (__pyx_2 != 0) ?  this is failing for me.

It's checking for errors. Compiling this:

  cdef foo():
    cdef object x
    cdef int y
    if x:
      y = 42

gives this (reformatted a little for readability):

  __pyx_1 = PyObject_IsTrue(__pyx_v_x); 
  if (__pyx_1 < 0) {
    __pyx_filename = __pyx_f[0]; 
    __pyx_lineno = 4; 
    goto __pyx_L1;
  }
  if (__pyx_1) {
    __pyx_v_y = 42;
    goto __pyx_L2;
  }

The "if (__pyx_1 < 0)" is testing whether an error occurred in
the PyObject_IsTrue call. The "if (__pyx_1)" is where it's
testing for a true/false result.

If you still think there's something wrong with the code
you're getting, send me the all of it (and the Pyrex code
which generated it) and I'll take a look.

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg at cosc.canterbury.ac.nz	   +--------------------------------------+




More information about the Pyrex mailing list