This is the mail archive of the
mailing list for the Archer project.
Re: [RFC][2/5] Event and event registry
Tom Tromey wrote:
"Oguz" == Oguz Kayral <email@example.com> writes:
Oguz> Py_INCREF (func);
Oguz> PyList_Append (callback_list, func);
I always forget whether the list APIs incref themselves, or not.
As a general rule, The list/dict/tupe functions do their own
incrementing (so the Py_INCREF above is not needed).
The main Exceptions are Py(List|Tuple)_SetItem, which steal a reference.
The idea being if you create a sequence with Py(List|Tuple)_New(length)
with length>0, you are probably going to create a bunch of objects to
put in the list. The stealing of references mean you don't have to call
Py_DECREF after each Py(List|Tuple)_SetItem (but you must own a `spare'
reference when you do it).
FWIW there seem to be a fair few places in gdb where Py_INCREF is used
over-zealously. Sometimes this is just extra increments to python's
None, True and False values, which I suppose won't cause any leaks, but
there are a few places that will.