[Python-checkins] TRUNK IS UNFROZEN, available for 2.6 work if you are so inclined
Georg Brandl
g.brandl at gmx.net
Thu Aug 17 21:07:53 CEST 2006
Jack Diederich wrote:
> Looks good to me. While you are on that page do you want to change
>
> l = PyList_New(3);
> x = PyInt_FromLong(1L);
> PySequence_SetItem(l, 0, x); Py_DECREF(x);
> x = PyInt_FromLong(2L);
> PySequence_SetItem(l, 1, x); Py_DECREF(x);
> x = PyString_FromString("three");
> PySequence_SetItem(l, 2, x); Py_DECREF(x);
>
> to
>
> l = PyList_New(3);
> x = PyInt_FromLong(1L);
> PyList_SetItem(l, 0, x);
> x = PyInt_FromLong(2L);
> PyList_SetItem(l, 1, x);
> x = PyString_FromString("three");
> PyList_SetItem(l, 2, x);
>
> The example code causes segfaults and probably always has (at last to 2.2)
Interesting! From a naive POV, the docs' example is quite right.
The segfault occurs because list_ass_item Py_DECREFs the old item (which
segfaults because the old items are NULL in a newly created list).
PyList_SetItem does a Py_XDECREF.
The docs to PyList_New, however, do not explicitly say that the new list
must only be filled using PyList_SetItem.
So please, someone, decide what's broken here!
Georg
More information about the Python-checkins
mailing list