py: __del__ special method not implemented for user-defined classes
Example:
import gc
class Foo():
def __del__(self):
print('__del__')
f = Foo()
del f
gc.collect()
According to this post #1802, gc.collect() should collect the object after the del and call the finaliser, but the finaliser is never called, any ideas?
I know that a good programming practice is to assume that __del__ may never be called, but hey, this still should work :)
Implement `weakref` module from `__del__` only.
Summary
This PR demonstrates an alternate concept to #18822 for a, implementation of the weakref module that relies more heavily on python-language code atop the __del__ method plus a much simpler c-language "weak pointer" primitive.
This is built on #18005, though in theory any implementation of __del__ that handles cyclic isolates correctly would also work.
Testing
I've pulled in all tests from #18822 for comparison. Note that few of the tests pass as written, but for many of them the distinction is down to just sequential ordering. There's also one lingering exception-handling issue but I'm confident I'll be able to resolve it.
I've flat-enabled this feature on all ports for the sake of size comparison --- this is not intended to be merged as such.
Trade-offs and Alternatives
This is an alternative proposal to #18822, aimed at a much smaller code size suitable for all ports, but likely with much worse runtime performance.