Hi, I'm trying to understand what is the best/safest/recommended way to implement tp_dealloc on a heap type created by PyType_FromSpec.
The official docs don't say much on the topic. The only note I could find is this:
Finally, if the type is heap allocated (Py_TPFLAGS_HEAPTYPE), the
deallocator should decrement the reference count for its type object after calling the type deallocator.
My doubts came after reading the source code. If I don't specify a tp_dealloc, its default value depends on heap vs static types:
value is subtype_dealloc, which seems to do a lot of complex logic which I don't fully understand.  https://github.com/python/cpython/blob/main/Objects/typeobject.c#L3553-L3558
This means that if I create a heap type with a custom tp_dealloc, all the logic implemented by subtype_dealloc will not be executed and that my type will probably behave subtly differently. I also found BPO 26979  where Christian Tismer claims that "The default of PyType_FromSpec for tp_dealloc is wrong!", but it seems that nothing has been done for that.  https://bugs.python.org/issue26979
Another interesting data point is that PyType_FromSpec+tp_dealloc does not seem to be used a lot in the wild. I tried to grep for Py_tp_dealloc in the top4000 PyPI packages and I found only a match, in Cython-generated code ; but it's code which is behind an "#if CYTHON_COMPILING_IN_LIMITED_API", which makes me to suspect which is not actually used a lot in practice.
So, back to my original problem:
correctly? 3. If (2) is true, what is the simplest way to do it?