bpo-38500: Add _PyInterpreterState_SetEvalFrameFunc() (GH-17340)
PyInterpreterState.eval_frame function now requires a tstate (Python
thread state) parameter.
Add private functions to the C API to get and set the frame
evaluation function:
* Add tstate parameter to _PyFrameEvalFunction function type.
* Add _PyInterpreterState_GetEvalFrameFunc() and
_PyInterpreterState_SetEvalFrameFunc() functions.
* Add tstate parameter to _PyEval_EvalFrameDefault().
diff --git a/Include/cpython/ceval.h b/Include/cpython/ceval.h
index e601304..f03b53a 100644
--- a/Include/cpython/ceval.h
+++ b/Include/cpython/ceval.h
@@ -21,7 +21,7 @@
flag was set, else return 0. */
PyAPI_FUNC(int) PyEval_MergeCompilerFlags(PyCompilerFlags *cf);
-PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(struct _frame *f, int exc);
+PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(PyThreadState *tstate, struct _frame *f, int exc);
PyAPI_FUNC(void) _PyEval_SetSwitchInterval(unsigned long microseconds);
PyAPI_FUNC(unsigned long) _PyEval_GetSwitchInterval(void);
diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h
index d179257..fbb0899 100644
--- a/Include/cpython/pystate.h
+++ b/Include/cpython/pystate.h
@@ -186,6 +186,16 @@
typedef struct _frame *(*PyThreadFrameGetter)(PyThreadState *self_);
+/* Frame evaluation API */
+
+typedef PyObject* (*_PyFrameEvalFunction)(PyThreadState *tstate, 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;
diff --git a/Include/internal/pycore_ceval.h b/Include/internal/pycore_ceval.h
index 70ce0ee..23d8091 100644
--- a/Include/internal/pycore_ceval.h
+++ b/Include/internal/pycore_ceval.h
@@ -40,7 +40,7 @@
static inline PyObject*
_PyEval_EvalFrame(PyThreadState *tstate, struct _frame *f, int throwflag)
{
- return tstate->interp->eval_frame(f, throwflag);
+ return tstate->interp->eval_frame(tstate, f, throwflag);
}
extern PyObject *_PyEval_EvalCode(
diff --git a/Include/internal/pycore_pystate.h b/Include/internal/pycore_pystate.h
index b5f5095..0a83546 100644
--- a/Include/internal/pycore_pystate.h
+++ b/Include/internal/pycore_pystate.h
@@ -54,8 +54,6 @@
/* interpreter state */
-typedef PyObject* (*_PyFrameEvalFunction)(struct _frame *, int);
-
#define _PY_NSMALLPOSINTS 257
#define _PY_NSMALLNEGINTS 5