Skip to content

C API for the frame stack #309

Open
Open
@markshannon

Description

@markshannon

Cython wants to introspect and modify frames. greenlet wants to create and switch stacks.

Doing this piecemeal and with an out-of-date, and thus incorrect, model of how the CPython frame stack works is going to lead to endless breakage, and nothing ever working correctly.

We want to make it easier for Cython, greenlet and other third parties to use our API and do the right thing, rather than hack it and do it wrong.

Of course, there is no guarantee that they will, but if they don't then it will be clear where the blame lies.

Required features:

  • Create and destroy a frame stack (greenlet needs this)
  • Swap the frame stack for a thread (greenlet needs this)
  • Introspect frames on the stack without forcing the creation of a frame object.
  • Create and push a frame to the stack (Cython needs this, to make its functions look like Python ones)
  • Pop and clear a frame from the stack (ditto)
  • Initialize a frame as part of a heap object (Cython needs this to implement its own generators and coroutines).
  • Push and pop a heap frame to the stack (ditto).

We should limit pushing and popping frames to frame stacks that are active (attached to the thread-state).

We already have all this functionality, we just need to expose it in a way that we are willing to maintain.
We should also be able to implement the API on top of older versions. That way we can be confident it will be portable and it will make it easier to make Cython and greenlet work on both 3.10 and 3.11.

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