Repository navigation
Add "unstable" frame stack api #91371
Description
Activity
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:
- Starts with an underscore
- Gets PyAPI_FUNC annotations, so we don't strip the symbols from the executable
- 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);- addedtype-featureA feature request or enhancementA feature request or enhancement3.11only security fixesonly security fixes
on Apr 4, 2022 - addedtype-featureA feature request or enhancementA feature request or enhancement
on Apr 4, 2022 greenlet code to save the Python thread state (C++): https://github.com/python-greenlet/greenlet/blob/937f150e07823ee03344aeeb5111c0bb371a831d/src/greenlet/TPythonState.cpp#L111
greenlet is used by eventlet and gevent projects.
PyOdide has similar code (in C): https://github.com/pyodide/pyodide/blob/d317e66d174efa203c59f094eb7714c0b90f7613/src/core/stack_switching/pystate.c#L161-L187
cc @hoodmane
Reacted by Donghee NaExperimental greenlet change extracting the "save/restore" logic into a C API: python-greenlet/greenlet#407
Members which should be saved/restored per Python version.
Python 3.10 (4):
tstate->cframetstate->cframe->use_tracingtstate->recursion_depthtstate->trash_delete_nesting
Python 3.11 (8):
tstate->cframetstate->cframe->current_frametstate->cframe->use_tracingtstate->datastack_chunktstate->datastack_limittstate->datastack_toptstate->recursion_remainingtstate->trash_delete_nesting
Python 3.12 (8):
tstate->c_recursion_remainingtstate->cframe->current_frametstate->cframetstate->datastack_chunktstate->datastack_limittstate->datastack_toptstate->py_recursion_remainingtstate->trash.delete_nesting
For Python 3.13, I'm not sure. I found 8 members:
tstate->c_recursion_remainingtstate->contexttstate->current_frame(UPDATE)tstate->datastack_chunktstate->datastack_limittstate->datastack_toptstate->delete_latertstate->py_recursion_remaining
Reacted by Hood Chatham
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:
bugs.python.org fields:
Linked PRs