Skip to content

Commit de37eba

Browse files
committed
pythongh-141518: Add PyUnstable_InterpreterState_SetEvalFrameFunc()
Add PyUnstable API or PEP 523: * PyUnstable_FrameEvalFunction type * PyUnstable_InterpreterState_GetEvalFrameFunc() * PyUnstable_InterpreterState_SetEvalFrameFunc() Keep the old names as deprecated aliases to new names: * _PyFrameEvalFunction * _PyInterpreterState_GetEvalFrameFunc * _PyInterpreterState_SetEvalFrameFunc
1 parent cc6b62a commit de37eba

File tree

6 files changed

+28
-21
lines changed

6 files changed

+28
-21
lines changed

Doc/c-api/init.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,7 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
14381438
.. versionadded:: 3.8
14391439
14401440
1441-
.. c:type:: PyObject* (*_PyFrameEvalFunction)(PyThreadState *tstate, _PyInterpreterFrame *frame, int throwflag)
1441+
.. c:type:: PyObject* (*PyUnstable_FrameEvalFunction)(PyThreadState *tstate, _PyInterpreterFrame *frame, int throwflag)
14421442
14431443
Type of a frame evaluation function.
14441444
@@ -1451,21 +1451,21 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
14511451
.. versionchanged:: 3.11
14521452
The *frame* parameter changed from ``PyFrameObject*`` to ``_PyInterpreterFrame*``.
14531453
1454-
.. c:function:: _PyFrameEvalFunction _PyInterpreterState_GetEvalFrameFunc(PyInterpreterState *interp)
1454+
.. c:function:: PyUnstable_FrameEvalFunction PyUnstable_InterpreterState_GetEvalFrameFunc(PyInterpreterState *interp)
14551455
14561456
Get the frame evaluation function.
14571457
14581458
See the :pep:`523` "Adding a frame evaluation API to CPython".
14591459
1460-
.. versionadded:: 3.9
1460+
.. versionadded:: next
14611461
1462-
.. c:function:: void _PyInterpreterState_SetEvalFrameFunc(PyInterpreterState *interp, _PyFrameEvalFunction eval_frame)
1462+
.. c:function:: void PyUnstable_InterpreterState_SetEvalFrameFunc(PyInterpreterState *interp, PyUnstable_FrameEvalFunction eval_frame)
14631463
14641464
Set the frame evaluation function.
14651465
14661466
See the :pep:`523` "Adding a frame evaluation API to CPython".
14671467
1468-
.. versionadded:: 3.9
1468+
.. versionadded:: next
14691469
14701470
14711471
.. c:function:: PyObject* PyThreadState_GetDict()

Include/cpython/pystate.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,15 @@ PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void);
302302

303303
/* Frame evaluation API */
304304

305-
typedef PyObject* (*_PyFrameEvalFunction)(PyThreadState *tstate, struct _PyInterpreterFrame *, int);
305+
typedef PyObject* (*PyUnstable_FrameEvalFunction)(PyThreadState *tstate, struct _PyInterpreterFrame *, int);
306306

307-
PyAPI_FUNC(_PyFrameEvalFunction) _PyInterpreterState_GetEvalFrameFunc(
307+
PyAPI_FUNC(PyUnstable_FrameEvalFunction) PyUnstable_InterpreterState_GetEvalFrameFunc(
308308
PyInterpreterState *interp);
309-
PyAPI_FUNC(void) _PyInterpreterState_SetEvalFrameFunc(
309+
PyAPI_FUNC(void) PyUnstable_InterpreterState_SetEvalFrameFunc(
310310
PyInterpreterState *interp,
311-
_PyFrameEvalFunction eval_frame);
311+
PyUnstable_FrameEvalFunction eval_frame);
312+
313+
// Deprecated aliases kept for backward compatibility
314+
#define _PyFrameEvalFunction PyUnstable_FrameEvalFunction
315+
#define _PyInterpreterState_GetEvalFrameFunc PyUnstable_InterpreterState_GetEvalFrameFunc
316+
#define _PyInterpreterState_SetEvalFrameFunc PyUnstable_InterpreterState_SetEvalFrameFunc

Include/internal/pycore_interp_structs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ struct _ceval_runtime_state {
8787
struct trampoline_api_st trampoline_api;
8888
FILE *map_file;
8989
Py_ssize_t persist_after_fork;
90-
_PyFrameEvalFunction prev_eval_frame;
90+
PyUnstable_FrameEvalFunction prev_eval_frame;
9191
#else
9292
int _not_used;
9393
#endif
@@ -860,7 +860,7 @@ struct _is {
860860
PyObject *sysdict_copy;
861861
PyObject *builtins_copy;
862862
// Initialized to _PyEval_EvalFrameDefault().
863-
_PyFrameEvalFunction eval_frame;
863+
PyUnstable_FrameEvalFunction eval_frame;
864864

865865
PyFunction_WatchCallback func_watchers[FUNC_MAX_WATCHERS];
866866
// One bit is set for each non-NULL entry in func_watchers

Modules/_testinternalcapi.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,8 @@ static PyObject *
657657
set_eval_frame_default(PyObject *self, PyObject *Py_UNUSED(args))
658658
{
659659
module_state *state = get_module_state(self);
660-
_PyInterpreterState_SetEvalFrameFunc(_PyInterpreterState_GET(), _PyEval_EvalFrameDefault);
660+
PyUnstable_InterpreterState_SetEvalFrameFunc(_PyInterpreterState_GET(),
661+
_PyEval_EvalFrameDefault);
661662
Py_CLEAR(state->record_list);
662663
Py_RETURN_NONE;
663664
}
@@ -689,7 +690,8 @@ set_eval_frame_record(PyObject *self, PyObject *list)
689690
return NULL;
690691
}
691692
Py_XSETREF(state->record_list, Py_NewRef(list));
692-
_PyInterpreterState_SetEvalFrameFunc(_PyInterpreterState_GET(), record_eval);
693+
PyUnstable_InterpreterState_SetEvalFrameFunc(_PyInterpreterState_GET(),
694+
record_eval);
693695
Py_RETURN_NONE;
694696
}
695697

Python/perf_trampoline.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,12 +486,12 @@ _PyPerfTrampoline_Init(int activate)
486486
#ifdef PY_HAVE_PERF_TRAMPOLINE
487487
PyThreadState *tstate = _PyThreadState_GET();
488488
if (!activate) {
489-
_PyInterpreterState_SetEvalFrameFunc(tstate->interp, prev_eval_frame);
489+
PyUnstable_InterpreterState_SetEvalFrameFunc(tstate->interp, prev_eval_frame);
490490
perf_status = PERF_STATUS_NO_INIT;
491491
}
492492
else if (tstate->interp->eval_frame != py_trampoline_evaluator) {
493-
prev_eval_frame = _PyInterpreterState_GetEvalFrameFunc(tstate->interp);
494-
_PyInterpreterState_SetEvalFrameFunc(tstate->interp, py_trampoline_evaluator);
493+
prev_eval_frame = PyUnstable_InterpreterState_GetEvalFrameFunc(tstate->interp);
494+
PyUnstable_InterpreterState_SetEvalFrameFunc(tstate->interp, py_trampoline_evaluator);
495495
extra_code_index = _PyEval_RequestCodeExtraIndex(NULL);
496496
if (extra_code_index == -1) {
497497
return -1;
@@ -517,7 +517,7 @@ _PyPerfTrampoline_Fini(void)
517517
}
518518
PyThreadState *tstate = _PyThreadState_GET();
519519
if (tstate->interp->eval_frame == py_trampoline_evaluator) {
520-
_PyInterpreterState_SetEvalFrameFunc(tstate->interp, NULL);
520+
PyUnstable_InterpreterState_SetEvalFrameFunc(tstate->interp, NULL);
521521
}
522522
if (perf_status == PERF_STATUS_OK) {
523523
trampoline_api.free_state(trampoline_api.state);

Python/pystate.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2896,8 +2896,8 @@ PyGILState_Release(PyGILState_STATE oldstate)
28962896
/* Other API */
28972897
/*************/
28982898

2899-
_PyFrameEvalFunction
2900-
_PyInterpreterState_GetEvalFrameFunc(PyInterpreterState *interp)
2899+
PyUnstable_FrameEvalFunction
2900+
PyUnstable_InterpreterState_GetEvalFrameFunc(PyInterpreterState *interp)
29012901
{
29022902
if (interp->eval_frame == NULL) {
29032903
return _PyEval_EvalFrameDefault;
@@ -2907,8 +2907,8 @@ _PyInterpreterState_GetEvalFrameFunc(PyInterpreterState *interp)
29072907

29082908

29092909
void
2910-
_PyInterpreterState_SetEvalFrameFunc(PyInterpreterState *interp,
2911-
_PyFrameEvalFunction eval_frame)
2910+
PyUnstable_InterpreterState_SetEvalFrameFunc(PyInterpreterState *interp,
2911+
PyUnstable_FrameEvalFunction eval_frame)
29122912
{
29132913
if (eval_frame == _PyEval_EvalFrameDefault) {
29142914
eval_frame = NULL;

0 commit comments

Comments
 (0)