Skip to content

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

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

Activity

  1. added a commit that references this issue on Sep 13, 2024
  2. vstinner commented on Sep 17, 2024

    @vstinner
    MemberAuthor

    I abandon this approach: #124076 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions