refcounting

Simon Dahlbacka sdahlbacSPAMSUX at abo.fi
Tue Apr 13 13:39:15 EDT 2004


I'm making a C extension where I'm wrapping a C function like follows

void MyFunction(/*[in,out]*/ ArrayType array)

to

a python function taking a list as inparameter and returning a list (for
consistency with other pointer arguments)

Now to the question..

I'm a little confused about the reference counting..

static PyObject* MyFunction(PyObject * /*self*/, PyObject *args) {

PyObject *list;
PyArg_ParseTuple(args, &PyList_Type, &list);

//do stuff with list elements

// XXX do I need Py_INCREF(list); here ???
return list;
}

obviously error checking is omitted for brevity.

PS. are there any documentation explaining the reference counting issues in
more detail than the docs @ python.org ?





More information about the Python-list mailing list