[Pyrex] Borrowed references

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Jul 30 05:23:16 UTC 2006


Daniele Varrazzo wrote:

> when i import a Python API function returning a borrowed reference such as:
> 
>     PyObject* PyTuple_GetItem(PyObject *p, int pos)

Functions with nonstandard refcounting behaviour aren't really
supported yet. However, with

   cdef extern from "Python.h":
     object PyTuple_GetItem(object, int)
     void Py_INCREF(object)

you can supply the missing incref yourself:

   x = PyTuple_GetItem(t, i)
   Py_INCREF(x)

--
Greg



More information about the Pyrex mailing list