get weakrefs in and working for functions/instancemethods
bring in the cpython implementation of weakrefs, and post init_weakref() overwrite some fields in the BoxedClass's for weakref.ref/proxy/callableproxy so that they participate in our GC (we also make use of their tp_traverse functions for scanning and tp_clear functions as their simple_destructor.) as we sweep the heap: 1) any unreachable objects that have weakreferences are kept alive and placed in an std::list called weakly_referenced. 2) any unreachable weakref.ref objects are cleared and removed from their referent's list. After sweeping the entire heap, we then loop over the objects in weakly_referenced. If an object in the list still has weak references, we loop over them clearing their target (setting it to None), and calling their callback if they have one. test/tests/weakref1.py tests this.
Showing
test/tests/weakref1.py
0 → 100644
test/tests/weakrefs.py
0 → 100644
Please register or sign in to comment