Skip to content

Commit f877b40

Browse files
authored
bpo-46850: Move _PyInterpreterState_SetEvalFrameFunc() to internal C API (GH-32054)
Move the private _PyFrameEvalFunction type, and private _PyInterpreterState_GetEvalFrameFunc() and _PyInterpreterState_SetEvalFrameFunc() functions to the internal C API. The _PyFrameEvalFunction callback function type now uses the _PyInterpreterFrame type which is part of the internal C API. Update the _PyFrameEvalFunction documentation.
1 parent b9a5522 commit f877b40

File tree

6 files changed

+38
-13
lines changed

6 files changed

+38
-13
lines changed

Doc/c-api/init.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1228,18 +1228,25 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
12281228
12291229
.. versionadded:: 3.8
12301230
1231-
.. c:type:: PyObject* (*_PyFrameEvalFunction)(PyThreadState *tstate, PyFrameObject *frame, int throwflag)
1231+
.. c:type:: PyObject* (*_PyFrameEvalFunction)(PyThreadState *tstate, _PyInterpreterFrame *frame, int throwflag)
1232+
1233+
Internal C API.
12321234
12331235
Type of a frame evaluation function.
12341236
12351237
The *throwflag* parameter is used by the ``throw()`` method of generators:
12361238
if non-zero, handle the current exception.
12371239
1240+
.. versionchanged:: 3.11
1241+
The second parameter type becomes ``_PyInterpreterFrame``.
1242+
12381243
.. versionchanged:: 3.9
12391244
The function now takes a *tstate* parameter.
12401245
12411246
.. c:function:: _PyFrameEvalFunction _PyInterpreterState_GetEvalFrameFunc(PyInterpreterState *interp)
12421247
1248+
Internal C API.
1249+
12431250
Get the frame evaluation function.
12441251
12451252
See the :pep:`523` "Adding a frame evaluation API to CPython".
@@ -1248,6 +1255,8 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
12481255
12491256
.. c:function:: void _PyInterpreterState_SetEvalFrameFunc(PyInterpreterState *interp, _PyFrameEvalFunction eval_frame)
12501257
1258+
Internal C API.
1259+
12511260
Set the frame evaluation function.
12521261
12531262
See the :pep:`523` "Adding a frame evaluation API to CPython".

Doc/whatsnew/3.11.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,12 @@ Porting to Python 3.11
11021102
is part of the internal C API.
11031103
(Contributed by Victor Stinner in :issue:`46850`.)
11041104

1105+
* Move the private ``_PyFrameEvalFunction`` type, and private
1106+
``_PyInterpreterState_GetEvalFrameFunc()`` and
1107+
``_PyInterpreterState_SetEvalFrameFunc()`` functions to the internal C API.
1108+
The ``_PyFrameEvalFunction`` callback function type now uses the
1109+
``_PyInterpreterFrame`` type which is part of the internal C API.
1110+
(Contributed by Victor Stinner in :issue:`46850`.)
11051111

11061112
Deprecated
11071113
----------

Include/cpython/pystate.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,6 @@ PyAPI_FUNC(PyThreadState *) PyInterpreterState_ThreadHead(PyInterpreterState *);
259259
PyAPI_FUNC(PyThreadState *) PyThreadState_Next(PyThreadState *);
260260
PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void);
261261

262-
/* Frame evaluation API */
263-
264-
typedef PyObject* (*_PyFrameEvalFunction)(PyThreadState *tstate, struct _PyInterpreterFrame *, int);
265-
266-
PyAPI_FUNC(_PyFrameEvalFunction) _PyInterpreterState_GetEvalFrameFunc(
267-
PyInterpreterState *interp);
268-
PyAPI_FUNC(void) _PyInterpreterState_SetEvalFrameFunc(
269-
PyInterpreterState *interp,
270-
_PyFrameEvalFunction eval_frame);
271-
272262
PyAPI_FUNC(const PyConfig*) _PyInterpreterState_GetConfig(PyInterpreterState *interp);
273263

274264
/* Get a copy of the current interpreter configuration.

Include/internal/pycore_interp.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ extern "C" {
1717
#include "pycore_dict.h" // struct _Py_dict_state
1818
#include "pycore_exceptions.h" // struct _Py_exc_state
1919
#include "pycore_floatobject.h" // struct _Py_float_state
20+
#include "pycore_gc.h" // struct _gc_runtime_state
2021
#include "pycore_genobject.h" // struct _Py_async_gen_state
2122
#include "pycore_gil.h" // struct _gil_runtime_state
22-
#include "pycore_gc.h" // struct _gc_runtime_state
2323
#include "pycore_list.h" // struct _Py_list_state
2424
#include "pycore_tuple.h" // struct _Py_tuple_state
2525
#include "pycore_typeobject.h" // struct type_cache
@@ -71,6 +71,20 @@ struct atexit_state {
7171
};
7272

7373

74+
/* Frame evaluation API (PEP 523) */
75+
76+
typedef PyObject* (*_PyFrameEvalFunction) (
77+
PyThreadState *tstate,
78+
struct _PyInterpreterFrame *frame,
79+
int throwflag);
80+
81+
PyAPI_FUNC(_PyFrameEvalFunction) _PyInterpreterState_GetEvalFrameFunc(
82+
PyInterpreterState *interp);
83+
PyAPI_FUNC(void) _PyInterpreterState_SetEvalFrameFunc(
84+
PyInterpreterState *interp,
85+
_PyFrameEvalFunction eval_frame);
86+
87+
7488
/* interpreter state */
7589

7690
/* PyInterpreterState holds the global state for one of the runtime's

Include/internal/pycore_pystate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11-
#include "pycore_runtime.h" /* PyRuntimeState */
11+
#include "pycore_runtime.h" // _PyRuntime
1212

1313

1414
/* Check if the current thread is the main thread.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Move the private ``_PyFrameEvalFunction`` type, and private
2+
``_PyInterpreterState_GetEvalFrameFunc()`` and
3+
``_PyInterpreterState_SetEvalFrameFunc()`` functions to the internal C API. The
4+
``_PyFrameEvalFunction`` callback function type now uses the
5+
``_PyInterpreterFrame`` type which is part of the internal C API. Patch by
6+
Victor Stinner.

0 commit comments

Comments
 (0)