GCC complains about uninitialized variables when compiling the
generated C sources in some cases like the below:

cdef int CHKERR(int ierr) except -1:
    if ierr==0: return 0
    raise RuntimeError

cdef int obj2int(object ob) except *:
    return ob

def foo(a):
    cdef int i = obj2int(a)
    CHKERR(i)

The warning is something like :

retval.c: In function '__pyx_pf_6retval_foo':
retval.c:244: warning: '__pyx_r' may be used uninitialized in this function


Then I noticed that Cython does not initializes '__pyx_r' to NULL and
that's the source of the problem. IMHO, we should initialize it to
NULL. Iff it even happens that (because of a bug) Cython generates bad
code, It's far easier to discover it from a SystemError exception
(because function returned NULL and an exception was not raised) than
a segfault because of the return is just garbage.

Whould a patch for this be accepted (well, it would be just one line
patch) ?? Iff it is accepted, what do you prefer for the generted C
code:

PyObject __pyx_r = 0;

or

PyObject __pyx_r = NULL;

-- 
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

Reply via email to