John Machin wrote: > Jack Diederich wrote: > > > Changing the PySequence_SetItem to PyList_SetItem and dropping the > > DECREF works for me too (PyList functions steal a reference). I also > > tried setting the list to length 1, still no dice. The PySequence > > version segs under 2.4 and 2.5. It segs even when the Int is changed > > to a String. > > > > Yikes, I'll poke around some more. > > Yikes indeed. > > Not the OP's problem, but a bug in the manual: example in the chapter > that the OP was reading acts as though the 2nd arg to PyObject_SetItem > is a C int (as it is for the List and Sequence varieties) -- it is in > fact a (PyObject *), which explains the SystemError that I got. >
OK, here's the story: PyList_New fills the list with NULLs. PyList_SetItem applies Py_XDECREF to the previous contents. PySequence_SetItem calls the function in the object's sq_ass_item slot. This is list_ass_item, which as the OP noted, applies Py_DECREF to the previous contents. Splat when NULL. I wonder how long it's been like that? FYI, the buggy manual section is http://docs.python.org/api/refcountDetails.html Cheers, John -- http://mail.python.org/mailman/listinfo/python-list