• Chris Toshok's avatar
    get weakrefs in and working for functions/instancemethods · 52d1d182
    Chris Toshok authored
    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.
    52d1d182
weakrefobject.h 3.04 KB