Skip to content

[C API] Add _Py_NewImmortalRef() function to the internal C API #124074

@vstinner

Description

@vstinner

I propose adding the following static inline function to the internal C API:

static inline PyObject* _Py_NewImmortalRef(PyObject *obj)
{
    assert(_Py_IsImmortalLoose(obj));
    return obj;
}

It's a way to annotate the code to express that a strong reference is expected, but we also know that the object is immortal and so calling Py_INCREF() is not needed.

See also #103906 and #123972.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions