Christian Heimes 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?
IIRC, It's an oddity.
But it is a convenient oddity nonetheless.
Stealing references is sometimes convenient, but Greg was referring to functions that steal references *conditionally*, which is indeed an oddity. Most functions and macros that steal references do so unconditionally, typically because they can't fail anyway. Conditional stealing of references requires very careful thinking on the side of callers that care about not leaking references in the face of exceptions. See http://bugs.python.org/issue1782 for an example.