Hi,

Lisandro Dalcin wrote:
> 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)

I added that as test case under tests/run/exceptionpropagation.pyx.


> 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

GCC points to the wrong function here (maybe due to inlining), it actually
means obj2int(). Looking at the generated code:

"""
static  int __pyx_f_20exceptionpropagation_obj2int(PyObject *__pyx_v_ob) {
  int __pyx_r;
  int __pyx_1;

  __pyx_1 = __pyx_PyInt_int(__pyx_v_ob);
             if (unlikely((__pyx_1 == (int)-1) {...; goto __pyx_L1;}
  __pyx_r = __pyx_1;
  goto __pyx_L0;

  __pyx_r = 0;            /* sadly, this is unused code ... */
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("exceptionpropagation.obj2int");
  __pyx_L0:;
  return __pyx_r;
}
"""

In foo(), Cython correctly generates

"""
  __pyx_r = Py_None; Py_INCREF(Py_None); /* initialisation in normal case */
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("exceptionpropagation.foo");
  __pyx_r = NULL;                     /* initialisation in exception case */
  __pyx_L0:;
  return __pyx_r;
"""

I'm not sure how to fix this (I've never even used "except *"). Maybe an
initialisation in exactly that case makes sense?

Stefan

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

Reply via email to