dict: the gc can resurrect objects after dealloc
so object's can be resurrected even with a non-resurrecting tp_dealloc. The only thing that can happen at that point is that the gc_visit function will get called. This shows up in the new sqlalchemy tests: they use a subclass of dict (defaultdict), which defines a custom tp_dealloc. We call that, which ends up calling dict_cls->tp_dealloc, which calls ~DenseMap on the internal DenseMap. The GC will accidentally keep the object alive (via a stack reference or something similar), and call its visit function on the next GC. But ~DenseMap does not leave the map in a consistent state, so iterating over it will end up producing garbage values. To solve this, add a new function that does all the same memory-freeing, but does a tiny bit of extra work to keep the DenseMap in a valid state for future gc_visit calls.
Showing
Please register or sign in to comment