From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 735 invoked by alias); 23 Sep 2009 23:28:14 -0000 Mailing-List: contact archer-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: List-Id: Received: (qmail 721 invoked by uid 22791); 23 Sep 2009 23:28:14 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00,SPF_PASS X-Spam-Check-By: sourceware.org Message-ID: <4ABAAF04.4020608@googlemail.com> Date: Wed, 23 Sep 2009 23:28:00 -0000 From: Richard Ward User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: archer@sourceware.org Subject: Re: [RFC][2/5] Event and event registry References: <36a35d480908230835s661fdbc2r3844a95c212a8fb@mail.gmail.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2009-q3/txt/msg00247.txt.bz2 Tom Tromey wrote: >>>>>> "Oguz" == Oguz Kayral 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. Richard.