[Python-Dev] The Amazing Unreferenced Weakref (original) (raw)
Gregory P. Smith greg at krypto.org
Tue Sep 6 20:19:36 EDT 2016
- Previous message (by thread): [Python-Dev] The Amazing Unreferenced Weakref
- Next message (by thread): [Python-Dev] PEP 447: Add __getdescriptor__ to metaclasses
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
This code appears to have been added to fix https://bugs.python.org/issue3100 - A crash involving a weakref subclass.
-gps
On Tue, Sep 6, 2016 at 3:51 PM Larry Hastings <larry at hastings.org> wrote:
This is all about current (3.6) trunk. In Objects/weakrefobject.c, we have the function PyObjectClearWeakRefs(). This is called when a generic object that supports weakrefs is destroyed; this is the code that calls the callbacks. Here's a little paragraph of code from the center: for (i = 0; i < count; ++i) {_ _PyWeakReference *next = current->wrnext; if (((PyObject *)current)->obrefcnt > 0) { PyINCREF(current); PyTupleSETITEM(tuple, i * 2, (PyObject *) current); PyTupleSETITEM(tuple, i * 2 + 1, current->wrcallback); } else { PyDECREF(current->wrcallback); } current->wrcallback = NULL; clearweakref(current); current = next; } "current" is the doubly-linked list of PyWeakReference objects stored inside the object that's getting destroyed. My question: under what circumstances would obrefcnt ever be 0? The tpdealloc handler for PyWeakReference * objects removes it from this list and frees the memory. How could the reference count reach 0 without tpdealloc being called and it being removed from the list? Scratching my head like crazy,
/arry p.s. If you're thinking "why does he care?", understanding this would maybe help with the Gilectomy. So yes there's a point to this question.
Python-Dev mailing list Python-Dev at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/greg%40krypto.org -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20160907/6defdfa7/attachment.html>
- Previous message (by thread): [Python-Dev] The Amazing Unreferenced Weakref
- Next message (by thread): [Python-Dev] PEP 447: Add __getdescriptor__ to metaclasses
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]