Skip to content

Simplify PyStackRef_FromPyObjectSteal #127022

Closed

Description

@colesbury

Feature or enhancement

Currently, PyStackRef_FromPyObjectSteal checks if the object is immortal in order to set the Py_TAG_DEFERRED bit.

static inline _PyStackRef
_PyStackRef_FromPyObjectSteal(PyObject *obj)
{
assert(obj != NULL);
// Make sure we don't take an already tagged value.
assert(((uintptr_t)obj & Py_TAG_BITS) == 0);
unsigned int tag = _Py_IsImmortal(obj) ? (Py_TAG_DEFERRED) : Py_TAG_PTR;
return ((_PyStackRef){.bits = ((uintptr_t)(obj)) | tag});
}
# define PyStackRef_FromPyObjectSteal(obj) _PyStackRef_FromPyObjectSteal(_PyObject_CAST(obj))

This check isn't necessary and has a performance cost that's not made up for by the slightly faster PyStackRef_CLOSE() calls or PyStackRef_Is() checks.

We should simplify PyStackRef_FromPyObjectSteal so that it creates _PyStackRef directly from the PyObject * without setting any tag bits.

Linked PRs

Activity

  1. added 2 commits that reference this issue on Nov 19, 2024
  2. colesbury commented on Nov 19, 2024

    @colesbury
    ContributorAuthor

    I think this will also allow us to simplify or remove _PyEvalFramePushAndInit_UnTagged.

  3. added 3 commits that reference this issue on Nov 22, 2024
  4. added 2 commits that reference this issue on Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions