Message104634
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. |
|
Date |
User |
Action |
Args |
2010-04-30 13:58:21 | arigo | set | recipients:
+ arigo |
2010-04-30 13:58:21 | arigo | set | messageid: <1272635901.2.0.350528689181.issue8578@psf.upfronthosting.co.za> |
2010-04-30 13:58:19 | arigo | link | issue8578 messages |
2010-04-30 13:58:18 | arigo | create | |
|