8000 Add "unstable" frame stack api · Issue #91371 · python/cpython · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "unstable" frame stack api #91371

Open
markshannon opened this issue Apr 4, 2022 · 5 comments
Open

Add "unstable" frame stack api #91371

markshannon opened this issue Apr 4, 2022 · 5 comments
Assignees
Labels
3.11 only security fixes topic-C-API type-feature A feature request or enhancement

Comments

@markshannon
Copy link
Member
markshannon commented Apr 4, 2022
BPO 47215
Nosy @markshannon, @brandtbucher
PRs
  • bpo-47215: Add undocumented, unstable FrameStack API for use by greenlets and similar libraries. #32303
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/markshannon'
    closed_at = None
    created_at = <Date 2022-04-04.11:59:07.553>
    labels = ['expert-C-API', 'type-feature', '3.11']
    title = 'Add "unstable" frame stack api'
    updated_at = <Date 2022-04-04.12:09:47.075>
    user = 'https://github.com/markshannon'

    bugs.python.org fields:

    activity = <Date 2022-04-04.12:09:47.075>
    actor = 'Mark.Shannon'
    assignee = 'Mark.Shannon'
    closed = False
    closed_date = None
    closer = None
    components = ['C API']
    creation = <Date 2022-04-04.11:59:07.553>
    creator = 'Mark.Shannon'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 47215
    keywords = ['patch']
    message_count = 1.0
    messages = ['416665']
    nosy_count = 2.0
    nosy_names = ['Mark.Shannon', 'brandtbucher']
    pr_nums = ['32303']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue47215'
    versions = ['Python 3.11']

    Linked PRs

    @markshannon
    Copy link
    Member Author

    We need to provide an API to create, swap and free frame stacks for greenlets.

    Since this is primarily for greenlets (and any other stackful coroutines libraries that want to use it) it will be "unstable".

    In this case, by "unstable" I mean:

    1. Starts with an underscore
    2. Gets PyAPI_FUNC annotations, so we don't strip the symbols from the executable
    3. Undocumented, except for comments that say it is unstable.

    The API will be:

    typedef struct _frame_stack {
        _PyStackChunk *current_chunk;
        PyObject **top;
        PyObject **limit;
        int chunk_size;
    } _PyFrameStack;
    
    PyAPI_FUNC(void) _PyFrameStack_Init(_PyFrameStack *fs, int chunk_size);
    PyAPI_FUNC(void) _PyFrameStack_Swap(_PyFrameStack *fs);
    PyAPI_FUNC(void) _PyFrameStack_Free(_PyFrameStack *fs);
    
    

    @markshannon markshannon added the 3.11 only security fixes label Apr 4, 2022
    @markshannon markshannon self-assigned this Apr 4, 2022
    @markshannon markshannon added topic-C-API type-feature A feature request or enhancement 3.11 only security fixes labels Apr 4, 2022
    @markshannon markshannon self-assigned this Apr 4, 2022
    @markshannon markshannon added topic-C-API type-feature A feature request or enhancement labels Apr 4, 2022
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @vstinner
    Copy link
    Member

    @vstinner
    Copy link
    Member

    cc @hoodmane

    vstinner added a commit to vstinner/cpython that referenced this issue May 27, 2024
    vstinner added a commit to vstinner/cpython that referenced this issue May 27, 2024
    vstinner added a commit to vstinner/greenlet that referenced this issue May 28, 2024
    Experimental change to move "save/restore the frame stack" into a
    dedicated C API in CPython upstream:
    python/cpython#91371
    @vstinner
    Copy link
    Member

    Experimental greenlet change extracting the "save/restore" logic into a C API: python-greenlet/greenlet#407

    @vstinner
    Copy link
    Member
    vstinner commented May 28, 2024

    Members which should be saved/restored per Python version.

    Python 3.10 (4):

    • tstate->cframe
    • tstate->cframe->use_tracing
    • tstate->recursion_depth
    • tstate->trash_delete_nesting

    Python 3.11 (8):

    • tstate->cframe
    • tstate->cframe->current_frame
    • tstate->cframe->use_tracing
    • tstate->datastack_chunk
    • tstate->datastack_limit
    • tstate->datastack_top
    • tstate->recursion_remaining
    • tstate->trash_delete_nesting

    Python 3.12 (8):

    • tstate->c_recursion_remaining
    • tstate->cframe->current_frame
    • tstate->cframe
    • tstate->datastack_chunk
    • tstate->datastack_limit
    • tstate->datastack_top
    • tstate->py_recursion_remaining
    • tstate->trash.delete_nesting

    For Python 3.13, I'm not sure. I found 8 members:

    • tstate->c_recursion_remaining
    • tstate->context
    • tstate->current_frame (UPDATE)
    • tstate->datastack_chunk
    • tstate->datastack_limit
    • tstate->datastack_top
    • tstate->delete_later
    • tstate->py_recursion_remaining

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes topic-C-API type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants
    0