[Pyrex] Borrowed references

Eric Huss e-huss at netmeridian.com
Sat Jul 29 23:22:59 UTC 2006


I would recommend writing a wrapper around PyTuple_GetItem that will call
Py_INCREF.  Optionally, you can just manually call Py_INCREF on the return
value after every time you call PyTuple_GetItem.

Also, PySequence_GetItem doesn't require this magic, and is pretty fast in
this situation.

-Eric

On Sun, 30 Jul 2006, Daniele Varrazzo wrote:

> Just a question:
>
> when i import a Python API function returning a borrowed reference such as:
>
>     PyObject* PyTuple_GetItem(PyObject *p, int pos)
>
> do i have to import  it as:
>
> cdef extern from "Python.h":
>     void *PyTuple_GetItem(object, int)
>
> or
>
> cdef extern from "Python.h":
>     object PyTuple_GetItem(object, int)
>
> ???
>
> Reading the generated C code, the latter form seems to leave an extra
> refcount, doesn't it?
>
> If so, maybe the issue deserves more attention in the documentation.
> Or did i miss it?
>
> Daniele
>
> P.S. Pyrex is white magic...
>
> _______________________________________________
> Pyrex mailing list
> Pyrex at lists.copyleft.no
> http://lists.copyleft.no/mailman/listinfo/pyrex
>



More information about the Pyrex mailing list