[Bf-python] PYTHONPATH

Willian Padovani Germano wgermano at ig.com.br
Sat Sep 13 19:47:05 CEST 2003


From: "Stephen Swaney" <sswaney at swbell.net>
(...)
> > > +   item  = PyList_GetItem( p, index );  /* borrowed ref */
> >
> > here: Py_INCREF(item);
> > (or use PySequence_GetItem, instead of PyList_GetItem)
> >
> > > +   syspath_append( item );
>
> This is because, even though it's a borrowed reference, we pass it
> on to someone who hangs on to it, right?  It seems obvious now
> that you point it out!

Reference counting is quite tricky, specially because only in special
situations (like working on bpython) we get the "chance" to deal with it.
The idea here is the base of it: another object will reference an item ->
the reference count for that item should be increased, so that it won't get
deleted when discarded, unless its ref count reaches zero, you know.

> I confess I was not aware of the more generic PySequence_GetItem().

There are some functions that incref, some that don't...  I just keep the
Python/C reference's index, letter P, by my side whenever I start coding in
bpython, as I've written here a few times already.  And there's a lot of
other goodies there in the API.  That's what makes it fun : ).

--
Willian, wgermano at ig.com.br




More information about the Bf-python mailing list