[Python-Dev] Borrowed and Stolen References in API

Greg Ewing greg.ewing at canterbury.ac.nz
Thu May 5 00:04:51 CEST 2011


Mark Shannon wrote:

> The online documentation specifies which API function borrow and/or 
> steal references (as opposed to the default behaviour).
> Yet, I cannot find this information anywhere in the source.

There are comments in some places, e.g. in listobject.h:

   *** WARNING *** PyList_SetItem does not increment the new item's reference
   count, but does decrement the reference count of the item it replaces,
   if not nil.  It does *decrement* the reference count if it is *not*
   inserted in the list.  Similarly, PyList_GetItem does not increment the
   returned item's reference count.

If you're looking for evidence in the actual code, there's
nothing particular to look for -- it's implicit in the
way the function works overall.

-- 
Greg


More information about the Python-Dev mailing list