C extensions should not use private functions (functions prefixed by _Py), but PEP 523 only added private functions:
_PyFrameEvalFunction type
_PyInterpreterState_GetEvalFrameFunc()
_PyInterpreterState_SetEvalFrameFunc()
I propose promoting these APIs as public functions/types (use PyUnstable_ prefix):
PyUnstable_FrameEvalFunction type
PyUnstable_InterpreterState_GetEvalFrameFunc()
PyUnstable_InterpreterState_SetEvalFrameFunc()
API:
typedef struct _PyInterpreterFrame PyUnstable_InterpreterFrame;
PyFrameObject* PyUnstable_InterpreterFrame_GetFrameObject(PyUnstable_InterpreterFrame *frame);
PyObject* (*PyUnstable_FrameEvalFunction)(PyThreadState *tstate, PyUnstable_InterpreterFrame *frame, int throwflag)
PyUnstable_FrameEvalFunction PyUnstable_InterpreterState_GetEvalFrameFunc(PyInterpreterState *interp)
int PyUnstable_InterpreterState_SetEvalFrameFunc(PyInterpreterState *interp, PyUnstable_FrameEvalFunction eval_frame)
UPDATE: Add PyUnstable_InterpreterFrame and PyUnstable_InterpreterFrame_GetFrameObject.
UPDATE 2: PyUnstable_InterpreterState_SetEvalFrameFunc() can now fail, its return type is int (instead of void).
These functions are already documented at: https://docs.python.org/dev/c-api/init.html#c._PyFrameEvalFunction
I hesitate to change PyUnstable_InterpreterState_SetEvalFrameFunc() return type from void to int to allow reporting an error. What do yo think? The implementation is non trivial but it cannot fail currently:
void
PyUnstable_InterpreterState_SetEvalFrameFunc(PyInterpreterState *interp,
PyUnstable_FrameEvalFunction eval_frame)
{
if (eval_frame == _PyEval_EvalFrameDefault) {
eval_frame = NULL;
}
if (eval_frame == interp->eval_frame) {
return;
}
#ifdef _Py_TIER2
if (eval_frame != NULL) {
_Py_Executors_InvalidateAll(interp, 1);
}
#endif
RARE_EVENT_INC(set_eval_frame_func);
_PyEval_StopTheWorld(interp);
interp->eval_frame = eval_frame;
_PyEval_StartTheWorld(interp);
}
C extensions should not use private functions (functions prefixed by
_Py), but PEP 523 only added private functions:_PyFrameEvalFunctiontype_PyInterpreterState_GetEvalFrameFunc()_PyInterpreterState_SetEvalFrameFunc()I propose promoting these APIs as public functions/types (use
PyUnstable_prefix):PyUnstable_FrameEvalFunctiontypePyUnstable_InterpreterState_GetEvalFrameFunc()PyUnstable_InterpreterState_SetEvalFrameFunc()API:
UPDATE: Add
PyUnstable_InterpreterFrameandPyUnstable_InterpreterFrame_GetFrameObject.UPDATE 2:
PyUnstable_InterpreterState_SetEvalFrameFunc()can now fail, its return type isint(instead ofvoid).These functions are already documented at: https://docs.python.org/dev/c-api/init.html#c._PyFrameEvalFunction
I hesitate to change
PyUnstable_InterpreterState_SetEvalFrameFunc()return type fromvoidtointto allow reporting an error. What do yo think? The implementation is non trivial but it cannot fail currently: