This may be know to some of you, anyway I post this here for future
reference (and perhaps better ways to avoid the warnings)
Consider the following snippet:
# ---------------------------------------
# file: tmp.pyx
cdef enum Truth:
FALSE=0
TRUE=1
cdef inline Truth obj2truth_v1(object flag) except *:
if flag is None: return FALSE
else: return flag
cdef inline Truth obj2truth_v2(object flag) except <Truth>(-1):
if flag is None: return FALSE
else: return flag
def foo(flag):
cdef Truth t = obj2truth_v1(flag)
print (t)
def bar(flag):
cdef Truth t = obj2truth_v2(flag)
print (t)
# ---------------------------------------
GCC 4.1.1 generates this warning:
tmp.c: In function '__pyx_pf_3tmp_foo':
tmp.c:219: warning: '__pyx_r' may be used uninitialized in this function
As you see, the warning is a bit extrange. After looking at the
generated code, the problem actually resides in obj2truth_v1(). If an
exception occurs, then garbage is returned. Of couse, the call to
PyErr_Occured() will correctly catch the problem, and all just work as
expected. However, the warning is annoying :-(
The vile hackery in obj2truth_v2() (also works in C++) seems to remove
the warning, but in general is not safe as for 'cdef extern'
enumerations '-1' could be a valid value. So the safest way is to use
'except?' in those cases.
--
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev