[Pyrex] bad del code generation
Eric Huss
e-huss at netmeridian.com
Fri Dec 22 22:23:16 UTC 2006
I'm having a hard time figuring out how to fix this problem in the
compiler. It seems that temporarily allocated objects in a del statement
generate the wrong deletion code. The following is an example:
def foo():
bar = [47]
del bar[0]
return
The snippet of C code it generates is:
/* del bar[0]
*/
__pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; goto __pyx_L1;}
if (PyObject_DelItem(__pyx_v_bar, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; goto __pyx_L1;}
Py_DECREF(__pyx_1); __pyx_1 = 0;
/* return
*/
Py_DECREF(__pyx_1); __pyx_1 = 0;
__pyx_r = Py_None; Py_INCREF(Py_None);
goto __pyx_L0;
You can see that it allocates the number 0 as __pyx_1, calls delitem, then
decref's it and sets it to zero. Unfortunately a return statement will
attempt to call DECREF on __pyx_1 even though it is NULL.
I'll work around it for now by putting the index value into a local
variable, but it would be nice to fix the problem.
-Eric
More information about the Pyrex
mailing list