[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: Functions that steal references (Re: [pygame] [patch] minor memory leaks...)



Greg Ewing wrote:

Lenard Lindstrom wrote:

I assumed that since PyModule_AddObject is documented as stealing a reference, it always stole a reference. But in reality it only does so conditionally, when it succeeds.

As an aside, is this a general feature of functions
that steal references, or is PyModule_AddObject an
oddity?

I ask because I've been thinking about adding features
to Pyrex for dealing with stolen references, and it
could be important to know things like this.

Also, if it's an oddity, it would be a good idea
to mention this behaviour in the docs.

Hi Greg,

What a function that steals a reference does with an error is undocumented. PyModule_AddObject only steals a referenece when it succeeds. PyList_SetItem and PyTuple_SetItem always steals a reference. The only way to find out which is the case is to examine the Python source code.

Lenard