Re: PySequence_SetItem

2006-08-17 Thread Jack Diederich
On Thu, Aug 17, 2006 at 02:35:11PM +0200, Fredrik Lundh wrote: > John Machin wrote: > > > 1. It's also documented as being the recommended way of filling up a > > list after PyList_New. > > since it doesn't work in any existing Python release, it's hardly > "recommended". > > the Python documen

Re: PySequence_SetItem

2006-08-17 Thread Fredrik Lundh
John Machin wrote: > 1. It's also documented as being the recommended way of filling up a > list after PyList_New. since it doesn't work in any existing Python release, it's hardly "recommended". the Python documentation has never been formally binding; if the documentation doesn't match the cod

Re: PySequence_SetItem

2006-08-17 Thread John Machin
Fredrik Lundh wrote: > John Machin wrote: > > > Are you suggesting a rework of the manual instead of inserting a X in > > the offending py_DECREF? > > are you suggesting slowing things down just because of a bug in the > documentation ? Not explicitly; not intentionally. > you cannot return an

Re: PySequence_SetItem

2006-08-17 Thread Fredrik Lundh
Jack Diederich wrote: >> For avoidance of doubt: the change is to use Py_XDECREF, yes/no? > > Yes. not necessarily: the bug is that you're using an uninitialized object in a context that expects an initialized object. might be a better idea to raise a SystemError exception. -- http://mail

Re: PySequence_SetItem

2006-08-17 Thread Fredrik Lundh
Jack Diederich wrote: > It is handy for functions that take a mutable list as an argument. an *existing*, and properly *initialized*, mutable sequence. PyList_New doesn't give you such an object. -- http://mail.python.org/mailman/listinfo/python-list

Re: PySequence_SetItem

2006-08-17 Thread Fredrik Lundh
John Machin wrote: > Are you suggesting a rework of the manual instead of inserting a X in > the offending py_DECREF? are you suggesting slowing things down just because of a bug in the documentation ? you cannot return an uninitialized list object to Python anyway, so there's no need to add

Re: PySequence_SetItem

2006-08-16 Thread Jack Diederich
On Wed, Aug 16, 2006 at 05:13:23PM -0700, John Machin wrote: > > Jack Diederich wrote: > > On Wed, Aug 16, 2006 at 03:25:39PM -0700, John Machin wrote: > > > > > > > > > > > Not the OP's problem, but a bug in the manual: example in the chapter > > > > > that the OP was reading acts as though the

Re: PySequence_SetItem

2006-08-16 Thread John Machin
the pointer isn't null) because it expects > > > to be used that way. > > > > PyList_SetItem is not sentient. It expects nothing. Now tell us what > > the developer was thinking -- certainly not consistency with the > > documantation. If the Sequence API requires valid

Re: PySequence_SetItem

2006-08-16 Thread Jack Diederich
On Wed, Aug 16, 2006 at 03:25:39PM -0700, John Machin wrote: > > Jack Diederich wrote: > > On Wed, Aug 16, 2006 at 02:39:24PM -0700, John Machin wrote: > > > > > > Jack Diederich wrote: > > > > > > > Changing the PySequence_SetItem to PyList_S

Re: PySequence_SetItem

2006-08-16 Thread John Machin
Jack Diederich wrote: > On Wed, Aug 16, 2006 at 02:39:24PM -0700, 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

Re: PySequence_SetItem

2006-08-16 Thread John Machin
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 > >

Re: PySequence_SetItem

2006-08-16 Thread Jack Diederich
On Wed, Aug 16, 2006 at 02:39:24PM -0700, 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 le

Re: PySequence_SetItem

2006-08-16 Thread John Machin
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 whe

Re: PySequence_SetItem

2006-08-16 Thread Jack Diederich
On Wed, Aug 16, 2006 at 01:45:44PM -0700, John Machin wrote: > Bill Pursell wrote: > > Bill Pursell wrote: > > > > Also note that the problem goes away if I replace > > the call to PySequence_SetItem with: > > PySequence_SetItem(l, 0, PyInt_FromLong(1L));

Re: PySequence_SetItem

2006-08-16 Thread John Machin
Bill Pursell wrote: > Bill Pursell wrote: > > Also note that the problem goes away if I replace > the call to PySequence_SetItem with: > PySequence_SetItem(l, 0, PyInt_FromLong(1L)); Are you sure? It should make absolutely no difference. My experience so far: 1. cra

Re: PySequence_SetItem

2006-08-16 Thread Bill Pursell
New(3); > x = PyInt_FromLong(1L); > > if (l == NULL || x == NULL) { > PyErr_Print(); > exit (EXIT_FAILURE); > } > PySequence_SetItem(l, 0, x); > Py_DECREF(x); > > Py_Finalize(); > return EXIT_SUC

PySequence_SetItem

2006-08-16 Thread Bill Pursell
) { PyErr_Print(); exit (EXIT_FAILURE); } PySequence_SetItem(l, 0, x); Py_DECREF(x); Py_Finalize(); return EXIT_SUCCESS; } Unforunately, it doesn't work. It segfaults, and the error occurs in list_ass_item() when the Py_DECREF macro is appli