[New-bugs-announce] [issue6616] PyList_APPEND (append without incref)

Campbell Barton report at bugs.python.org
Sat Aug 1 22:43:47 CEST 2009

New submission from Campbell Barton <ideasman42 at gmail.com>:

This patch was made on python r74276

Often when writing in C/Python I want to append to a list within a C
loop of an unknown length.
When this is done for newly created PyObject (which is quite common) -
you need to assign each item to a variable and then decref it.

 PyObject *item= PyFloat_FromDouble(x);
 PyList_Append(list, item);

I have seen people make mistakes with this (in pygame code and
blender3d), and run  PyList_Append(list, PyFloat_FromDouble(x)),
ofcourse this is not the fault of python/c api that devs do not read
docs properly but I think it would be very convenient to have an append
that works in a similar way to PyList_SET_ITEM

This simple patch allows...
 PyList_APPEND(list, PyFloat_FromDouble(x))

doc included.

files: py3_APPEND.diff
keywords: patch
messages: 91167
nosy: ideasman42
severity: normal
status: open
title: PyList_APPEND (append without incref)
versions: Python 3.2
Added file: http://bugs.python.org/file14619/py3_APPEND.diff

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list