This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author arigo
Recipients arigo
Date 2010-04-30.13:58:18
SpamBayes Score 0.006274419
Marked as misclassified No
Message-id <1272635901.2.0.350528689181.issue8578@psf.upfronthosting.co.za>
In-reply-to
Content
PyWeakref_GetObject(wref) returns a borrowed reference, but that's rather dangerous.  The fact that wref stays alive does not prevent the returned object from being collected (by definition -- wref is a weak reference).  That means that either we must explicitly and immediately do a Py_INCREF() (and later Py_DECREF()) on the result of the function, or we must use it for a very short time.

As an example of why this interface encourages buggy behavior, the sole user of PyWeakref_GetObject() in Module/* is Module/_sqlite/connection.c, which does

    statement = PyWeakref_GetObject(weakref);

and then call some functions passing 'statement' as argument.  The called functions can do anything (because they release the GIL).  So in particular they can cause 'statement' to be freed while still in use, either directly or indirectly via the cycle-GC.

This should be fixed; I suggest deprecating PyWeakref_GetObject() and adding another C API function that does not return a borrowed reference.
History
Date User Action Args
2010-04-30 13:58:21arigosetrecipients: + arigo
2010-04-30 13:58:21arigosetmessageid: <1272635901.2.0.350528689181.issue8578@psf.upfronthosting.co.za>
2010-04-30 13:58:19arigolinkissue8578 messages
2010-04-30 13:58:18arigocreate