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
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 2nd arg to PyObject_SetItem > > > > is a C int (as it is for the List and S

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_SetItem and dropping the > > > > DECREF works for me too

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). I also > > > tried setting the list t

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 > > version segs under 2.4 and 2.5.

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 length 1, still no dice. The PyS

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 when the Int is c

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)); > > Are you sure? It should make absolut

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. crashes in call to PySequence_Se

Re: PySequence_SetItem

2006-08-16 Thread Bill Pursell
Bill Pursell wrote: > The following code is pretty much straight out of > section 1.2.1.1 of the Python/C reference manual: > > #include > > int > main(void) > { > PyObject *l, *x; > > Py_Initialize(); > > l = PyList_New(3); > x = PyInt_FromLong(1L); > > if