Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bpo-38500: Add PyInterpreterState_SetEvalFrameFunc()
Add a public API to get and set the frame evaluation function:

* Rename the internal _PyFrameEvalFunction type to
  PyFrameEvalFunction and make it public
* Add PyInterpreterState_GetEvalFrameFunc() and
  PyInterpreterState_SetEvalFrameFunc() functions
  • Loading branch information
vstinner committed Nov 24, 2019
commit 826b4c5477be035be68b561ec968a0df86bd357a
25 changes: 25 additions & 0 deletions Doc/c-api/init.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,31 @@ All of the following functions must be called after :c:func:`Py_Initialize`.

.. versionadded:: 3.8

.. c:type:: PyObject* (*PyFrameEvalFunction)(PyFrameObject *frame, int throwflag)

Type of a frame evaluation function.

The *throwflag* parameter is used by the ``throw()`` method of generators:
if non-zero, handle the current exception.

.. versionadded:: 3.8.1

.. c:function:: PyFrameEvalFunction PyInterpreterState_GetEvalFrameFunc(PyInterpreterState *interp)

Get the frame evaluation function.

See the :pep:`523` "Adding a frame evaluation API to CPython".

.. versionadded:: 3.8.1

.. c:function:: void PyInterpreterState_SetEvalFrameFunc(PyInterpreterState *interp, PyFrameEvalFunction eval_frame);

Set the frame evaluation function.

See the :pep:`523` "Adding a frame evaluation API to CPython".

.. versionadded:: 3.8.1


.. c:function:: PyObject* PyThreadState_GetDict()

Expand Down
10 changes: 10 additions & 0 deletions Include/cpython/pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void);

typedef struct _frame *(*PyThreadFrameGetter)(PyThreadState *self_);

/* Frame evaluation API */

typedef PyObject* (*PyFrameEvalFunction)(struct _frame *, int);

PyAPI_FUNC(PyFrameEvalFunction) PyInterpreterState_GetEvalFrameFunc(
PyInterpreterState *interp);
PyAPI_FUNC(void) PyInterpreterState_SetEvalFrameFunc(
PyInterpreterState *interp,
PyFrameEvalFunction eval_frame);

/* cross-interpreter data */

struct _xid;
Expand Down
4 changes: 1 addition & 3 deletions Include/internal/pycore_pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ struct _ceval_runtime_state {

/* interpreter state */

typedef PyObject* (*_PyFrameEvalFunction)(struct _frame *, int);

// The PyInterpreterState typedef is in Include/pystate.h.
struct _is {

Expand Down Expand Up @@ -113,7 +111,7 @@ struct _is {
PyObject *builtins_copy;
PyObject *import_func;
/* Initialized to PyEval_EvalFrameDefault(). */
_PyFrameEvalFunction eval_frame;
PyFrameEvalFunction eval_frame;

Py_ssize_t co_extra_user_count;
freefunc co_extra_freefuncs[MAX_CO_EXTRA_USERS];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Add a public API to get and set the frame evaluation function: add
:c:func:`PyInterpreterState_GetEvalFrameFunc` and
:c:func:`PyInterpreterState_SetEvalFrameFunc` C functions
14 changes: 14 additions & 0 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,20 @@ _register_builtins_for_crossinterpreter_data(struct _xidregistry *xidregistry)
}


PyFrameEvalFunction
PyInterpreterState_GetEvalFrameFunc(PyInterpreterState *interp)
{
return interp->eval_frame;
}


void
PyInterpreterState_SetEvalFrameFunc(PyInterpreterState *interp,
PyFrameEvalFunction eval_frame)
{
interp->eval_frame = eval_frame;
}

#ifdef __cplusplus
}
#endif