Skip to content

Handles / Opaque linear references #7

@encukou

Description

@encukou

Reference counting (incref/decref) is replaced by what HPy calls handles, and Mark's proposal Opaque, linear references:

  • Each handle has exctly one owner.
  • Handles are destroyed by PyRef_Close.
  • Handles are duplicated using PyRef_Dup. Each must be destroyed (i.e. you can't Close one of them twice).
  • There can be multiple handles for a single object.
  • Object identity is compared using PyRef_Is, not by a pointer comparison

HPy shows that this enables a moving GC.
It does need all users to update all their code, so CPython probably can't ever require this. But we could provide PyRef_Dup/PyRef_Close/PyRef_Is (implemented as Py_INCREF/Py_DECREF/Py_Is) to allow users to signal that they're using handle semantics, and are (theoretically) compatible with implementations that use a moving GC.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions