[Python-checkins] TRUNK IS UNFROZEN, available for 2.6 work if you are so inclined

Jack Diederich jackdied at jackdied.com
Thu Aug 17 22:00:46 CEST 2006


On Thu, Aug 17, 2006 at 09:07:53PM +0200, Georg Brandl wrote:
> 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!

The docs, this is from a thread yesterday and today on c.l.py

http://groups.google.com/group/comp.lang.python/browse_frm/thread/158c8797ee2dccab/

-Jack


More information about the Python-checkins mailing list