Check destructors and weakrefs for extension objects
Add a new allocation type CONSERVATIVE_PYTHON for extensions objects, for which we don't have heap maps, but should still have Python finalization semantics (ie destructors and weakrefs). Previously we were just marking them as CONSERVATIVE and skipping them during the sweep phase, and not running destructors or handling weakrefs. It's a bit tricky to figure out when to mark an allocation as conservative vs conservative-python; the approach in this commit is to mark all capi-originated allocations as conservative, and then when we call PyObject_Init or PyObject_InitVar, switch them from conservative to conservative-python. I think this is more expensive but safer than assuming that certain apis will always/never be used as object memory. Unfortunately there are quite a few extension classes that request a custom tp_dealloc, and this commit just keeps the old (bad) behavior of ignoring those. I tried to verify as many as I could and they all seem benign, but it will be nice to have real destructor support :)
Showing
Please register or sign in to comment