[Cython] Control Flow

Stefan Behnel stefan_ml at behnel.de
Sat May 28 17:36:11 CEST 2011


Vitja Makarov, 28.05.2011 16:58:
> 2011/5/28 Stefan Behnel:
>> Vitja Makarov, 28.05.2011 14:12:
>>>
>>> 2011/5/28 Stefan Behnel:
>>>>
>>>> Ok, I think we're done then, right? Anything else to do before merging it
>>>> back?
>>>
>>> I hope so ;)
>>
>> I gave your branch a test with lxml and it spit out a couple of missing
>> initialisation warnings. Most of them were due to the usage of C out
>> arguments, e.g.
>>
>>     cdef Py_ssize_t step
>>     ...
>>     _PyEval_SliceIndex(sliceobject.step,&step)
>>
>> Here, it doesn't matter that "step" isn't initialised. I guess it's still ok
>> to get a warning, since it's not obvious that "step" will always be set by
>> the function call.
>>
>> Similarly:
>>
>>     cdef void _receiveXSLTError(void* c_log_handler, char* msg, ...) nogil:
>>         cdef cstd.va_list args
>>         ...
>>         cstd.va_start(args, msg)
>>
>> Cython now tells me that "args" isn't initialised. That's true again,
>> although this is an even more special case here. I guess I'll have to live
>> with that as well for now, maybe until there's dedicated va_list support in
>> Cython.
>>
>> Next, I got a crash in a part of code where I was manually releasing the
>> GIL, but only conditionally, and Cython figured out that a variable wasn't
>> initialised in one case and injected an exception. I would have liked to get
>> a compile time warning here, but didn't. I assume that's because it was only
>> a "may be used uninitialised", not a "is used uninitialised"?
>>
>> I'm currently looking through the other issues. A major problem is that I
>> often relied on Cython setting uninitialised variables to None, especially
>> in performance critical code where I wanted to avoid double initialisations.
>> Cython is smarter now, so this needs fixing in the code. I'm sure I'm not
>> the only one who'll run into that, so more warnings would be very helpful.
>
> Do you run cython as "cython -Wextra"?
>   -Wextra enables "maybe uninitialized" warning and unused entry.
> By default error is generated for uninitialized pyobject variables and
> warning for ctypes.

No, I was setting the warning level to 0. That should give me all warnings 
and that, IMHO, includes this one.

Stefan


More information about the cython-devel mailing list