Skip to content

Please add PyObject_CallFinalizer (& FromDealloc variant) to stable ABI #146063

@davidhewitt

Description

@davidhewitt

Feature or enhancement

Proposal:

Please add PyObject_CallFinalizer and PyObject_CallFinalizerFromDealloc to the stable ABI.

The documentation for PyObject_CallFinalizer and PyObject_CallFinalizerFromDealloc state:

Call this function (or PyObject_CallFinalizerFromDealloc()) instead of calling tp_finalize directly because this function may deduplicate multiple calls to tp_finalize. Currently, calls are only deduplicated if the type supports garbage collection (i.e., the Py_TPFLAGS_HAVE_GC flag is set); this may change in the future.

These functions are not yet in the stable ABI. I believe it is possible to approximate their current behavior using PyObject_GC_IsFinalized (which is stable ABI) to decide whether to call the finalizer. Given the documentation states that the logic for deduplicating calls may change in future, it seems better to just add the functions to the stable ABI rather than leave downstream users to recreate their logic.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions