[Python-Dev] [Python-checkins] TRUNK IS UNFROZEN, available for 2.6 work if you are so inclined (original) (raw)

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 = PyListNew(3); > x = PyIntFromLong(1L); > PySequenceSetItem(l, 0, x); PyDECREF(x); > x = PyIntFromLong(2L); > PySequenceSetItem(l, 1, x); PyDECREF(x); > x = PyStringFromString("three"); > PySequenceSetItem(l, 2, x); PyDECREF(x); > > to > > l = PyListNew(3); > x = PyIntFromLong(1L); > PyListSetItem(l, 0, x); > x = PyIntFromLong(2L); > PyListSetItem(l, 1, x); > x = PyStringFromString("three"); > PyListSetItem(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 listassitem PyDECREFs the old item (which segfaults because the old items are NULL in a newly created list). PyListSetItem does a PyXDECREF. The docs to PyListNew, however, do not explicitly say that the new list must only be filled using PyListSetItem. 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-Dev mailing list