Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Gregory Ewing Newsgroups: comp.lang.python Subject: Re: Py_INCREF() incomprehension Date: Mon, 02 May 2011 10:48:58 +1200 Lines: 17 Message-ID: <9266atF3vrU1@mid.individual.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: individual.net Z1iSTbEAO6ZJIBEUU8RdtAM9XVMQlTTrNvOowb7T8gSLU0zpeP Cancel-Lock: sha1:/502/HgDhrnN/sDcHg427NFCDw0= User-Agent: Mozilla Thunderbird 1.0.5 (Macintosh/20050711) X-Accept-Language: en-us, en In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:4424 Hegedüs Ervin wrote: > I've put it a Py_INCREF() after every PyModule_AddObject(), eg.: > > PyModule_AddObject(o, "error", cibcrypt_error_nokey); > Py_INCREF(cibcrypt_error_nokey); That looks correct, because PyModule_AddObject is documented as stealing a reference to the object. By the way, it probably doesn't make a difference here, but it's better style to do the Py_INCREF *before* calling a function that steals a reference, to be sure that the object can't get spuriously deallocated. -- Greg