[Pyrex] Bad code generation in Pyrex 0.9.4.1
Konrad Hinsen
konrad.hinsen at laposte.net
Thu Sep 28 14:54:43 UTC 2006
I think I found a bug in Pyrex; it generates bad C code for one of my
modules. Reduced to the bare minimum, my Pyrex module becomes
cdef class vector:
def __div__(vector self, double factor):
result = vector()
return result
When __div__ is called with an argument that is not a float, it
should raise an exception, which is what it does on my Mac. However,
under Linux it causes a segmentation fault. A look at the generated
code reveals the reason:
static PyObject *__pyx_f_5debug_6vector___div__(PyObject
*__pyx_v_self, PyObject *__pyx_arg_factor); /*proto*/
static PyObject *__pyx_f_5debug_6vector___div__(PyObject
*__pyx_v_self, PyObject *__pyx_arg_factor) {
double __pyx_v_factor;
PyObject *__pyx_v_result;
PyObject *__pyx_r;
PyObject *__pyx_1 = 0;
PyObject *__pyx_2 = 0;
Py_INCREF(__pyx_v_self);
__pyx_v_factor = PyFloat_AsDouble(__pyx_arg_factor); if
(PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3;
goto __pyx_L1;}
/* some lines ommitted */
__pyx_L1:;
Py_XDECREF(__pyx_1);
Py_XDECREF(__pyx_2);
__Pyx_AddTraceback("debug.vector.__div__");
__pyx_r = 0;
__pyx_L0:;
Py_DECREF(__pyx_v_result);
Py_DECREF(__pyx_v_self);
return __pyx_r;
}
If the conversion of "factor" to double fails, the variable
__pyx_v_result remains unitialized but is passed to Py_DECREF. It
should instead be treated just like the temporaries __pyx_1 and
__pyx_2: it should be initialized to null and passed to Py_XDECREF.
Konrad.
--
---------------------------------------------------------------------
Konrad Hinsen
Centre de Biophysique Moléculaire, CNRS Orléans
Synchrotron Soleil - Division Expériences
Saint Aubin - BP 48
91192 Gif sur Yvette Cedex, France
Tel. +33-1 69 35 97 15
E-Mail: hinsen at cnrs-orleans.fr
---------------------------------------------------------------------
More information about the Pyrex
mailing list