You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
gh-75459: Doc: C API: Improve object life cycle documentation
* Add "cyclic isolate" to the glossary.
* Add a new "Object Life Cycle" page.
* Illustrate the order of life cycle functions.
* Document `PyObject_CallFinalizer` and
`PyObject_CallFinalizerFromDealloc`.
* `PyObject_Init` does not call `tp_init`.
* `PyObject_New`:
* also initializes the memory
* does not call `tp_alloc`, `tp_new`, or `tp_init`
* should not be used for GC-enabled objects
* memory must be freed by `PyObject_Free`
* `PyObject_GC_New` memory must be freed by `PyObject_GC_Del`.
* Warn that garbage collector functions can be called from any
thread.
* `tp_finalize` and `tp_clear`:
* Only called when there's a cyclic isolate.
* Only one object in the cyclic isolate is finalized/cleared at a
time.
* Clearly warn that they might not be called.
* They can optionally be manually called from `tp_dealloc` (via
`PyObject_CallFinalizerFromDealloc` in the case of
`tp_finalize`).
* `tp_finalize`:
* Reference `object.__del__`.
* The finalizer can resurrect the object.
* Suggest `PyErr_GetRaisedException` and
`PyErr_SetRaisedException` instead of the deprecated
`PyErr_Fetch` and `PyErr_Restore` functions.
* Add links to `PyErr_GetRaisedException` and
`PyErr_SetRaisedException`.
* Suggest using `PyErr_WriteUnraisable` if an exception is raised
during finalization.
* Rename the example function from `local_finalize` to
`foo_finalize` for consistency with the `tp_dealloc`
documentation and as a hint that the name isn't special.
* Minor wording and sylistic tweaks.
* Warn that `tp_finalize` can be called during shutdown.
0 commit comments