bpo-38644: Add _PyEval_EvalFrame() with tstate (GH-17131) · python/cpython@b9e6812

4 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -11,6 +11,9 @@ extern "C" {

1111

/* Forward declarations */

1212

struct pyruntimestate;

1313

struct _ceval_runtime_state;

14+

struct _frame;

15+
16+

#include "pycore_pystate.h" /* PyInterpreterState.eval_frame */

1417
1518

PyAPI_FUNC(void) _Py_FinishPendingCalls(struct pyruntimestate *runtime);

1619

PyAPI_FUNC(void) _PyEval_Initialize(struct _ceval_runtime_state *);

@@ -34,6 +37,12 @@ PyAPI_FUNC(void) _PyEval_SetCoroutineOriginTrackingDepth(

3437

/* Private function */

3538

void _PyEval_Fini(void);

3639
40+

static inline PyObject*

41+

_PyEval_EvalFrame(PyThreadState *tstate, struct _frame *f, int throwflag)

42+

{

43+

return tstate->interp->eval_frame(f, throwflag);

44+

}

45+
3746

#ifdef __cplusplus

3847

}

3948

#endif

Original file line numberDiff line numberDiff line change

@@ -1,4 +1,5 @@

11

#include "Python.h"

2+

#include "pycore_ceval.h" /* _PyEval_EvalFrame() */

23

#include "pycore_object.h"

34

#include "pycore_pyerrors.h"

45

#include "pycore_pystate.h"

@@ -303,7 +304,7 @@ function_code_fastcall(PyCodeObject *co, PyObject *const *args, Py_ssize_t nargs

303304

Py_INCREF(*args);

304305

fastlocals[i] = *args++;

305306

}

306-

PyObject *result = PyEval_EvalFrameEx(f, 0);

307+

PyObject *result = _PyEval_EvalFrame(tstate, f, 0);

307308
308309

if (Py_REFCNT(f) > 1) {

309310

Py_DECREF(f);

Original file line numberDiff line numberDiff line change

@@ -1,6 +1,7 @@

11

/* Generator object implementation */

22
33

#include "Python.h"

4+

#include "pycore_ceval.h" /* _PyEval_EvalFrame() */

45

#include "pycore_object.h"

56

#include "pycore_pystate.h"

67

#include "frameobject.h"

@@ -219,7 +220,7 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc, int closing)

219220

gen->gi_running = 1;

220221

gen->gi_exc_state.previous_item = tstate->exc_info;

221222

tstate->exc_info = &gen->gi_exc_state;

222-

result = PyEval_EvalFrameEx(f, exc);

223+

result = _PyEval_EvalFrame(tstate, f, exc);

223224

tstate->exc_info = gen->gi_exc_state.previous_item;

224225

gen->gi_exc_state.previous_item = NULL;

225226

gen->gi_running = 0;

Original file line numberDiff line numberDiff line change

@@ -722,18 +722,20 @@ PyEval_EvalCode(PyObject *co, PyObject *globals, PyObject *locals)

722722

/* Interpreter main loop */

723723
724724

PyObject *

725-

PyEval_EvalFrame(PyFrameObject *f) {

725+

PyEval_EvalFrame(PyFrameObject *f)

726+

{

726727

/* This is for backward compatibility with extension modules that

727728

used this API; core interpreter code should call

728729

PyEval_EvalFrameEx() */

729-

return PyEval_EvalFrameEx(f, 0);

730+

PyThreadState *tstate = _PyThreadState_GET();

731+

return _PyEval_EvalFrame(tstate, f, 0);

730732

}

731733
732734

PyObject *

733735

PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)

734736

{

735-

PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();

736-

return interp->eval_frame(f, throwflag);

737+

PyThreadState *tstate = _PyThreadState_GET();

738+

return _PyEval_EvalFrame(tstate, f, throwflag);

737739

}

738740
739741

PyObject* _Py_HOT_FUNCTION

@@ -4295,7 +4297,7 @@ _PyEval_EvalCodeWithName(PyObject *_co, PyObject *globals, PyObject *locals,

42954297

return gen;

42964298

}

42974299
4298-

retval = PyEval_EvalFrameEx(f,0);

4300+

retval = _PyEval_EvalFrame(tstate, f, 0);

42994301
43004302

fail: /* Jump here from prelude on failure */

43014303