PEP 442 undocumented C API functions
Hi, PEP 442 says "Two new C API functions are provided to ease calling of tp_finalize, especially from custom deallocators." This includes PyObject_CallFinalizerFromDealloc. However, no documentation of these functions appears to exist (https://bugs.python. org/issue31276). As far as I understand, if you have a custom tp_dealloc, you *have* to call PyObject_CallFinalizerFromDealloc in order to get your tp_finalize called. Is this correct? However, since the necessary functions are undocumented, it's unclear if they were intended to be public Python API functions. So are they actually public functions that 3rd party extensions can call? If not, how is tp_finalize supposed to be used? I'd be happy if someone can clarify the issue. -- Pauli Virtanen
Hi, thanks to your report.
As far as I understand, if you have a custom tp_dealloc, you *have* to call PyObject_CallFinalizerFromDealloc in order to get your tp_finalize called. Is this correct?
Sorry, I'm not expert of Object finalization process. But If my understanding is correct, you're almost right. When a type has custom *tp_finalize*, it have to call `PyObject_CallFinalizerFromDealloc`. And to allow subclass, it should be like this: https://github.com/python/cpython/blob/ed94a8b2851914bcda3a77b28b25517b8baa9...
However, since the necessary functions are undocumented, it's unclear if they were intended to be public Python API functions. So are they actually public functions that 3rd party extensions can call? If not, how is tp_finalize supposed to be used?
While I don't want tp_finalize is used widely (like `__del__`), I
agree with you.
But I'm not good English writer.
Contribution is welcome.
Regards,
INADA Naoki
participants (2)
-
INADA Naoki
-
Pauli Virtanen