On Sep 20, 2009, at 6:32 PM, Greg Ewing wrote:

> Tan Swee Heng wrote:
>
>> Looking at app.c:
>>
>>   //    if expensive(i, 0) and expensive(i, 1):             #  
>> <<<<<<<<<<<<<<
>>       if (__pyx_f_3app_expensive(__pyx_v_i, 0)) {
>>         __pyx_t_2 = __pyx_f_3app_expensive(__pyx_v_i, 1);
>>       } else {
>>         __pyx_t_2 = __pyx_f_3app_expensive(__pyx_v_i, 0);
>>       }
>
>> Q: For the short-circuit, would the right behaviour be to store the
>> result of the first evaluation in a temporary variable instead?
>
> I'd say so. Pyrex generates this:
>
>      __pyx_5 = __pyx_f_3app_expensive(__pyx_v_i,0);
>      if (__pyx_5) {
>        __pyx_5 = __pyx_f_3app_expensive(__pyx_v_i,1);
>      }

Yep, a bug for sure. Not just optimization, but if expensive() has  
side effects than it disobeys Python semantics.

- Robert

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to