mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	bpo-38644: Add _PyEval_EvalFrame() with tstate (GH-17131)
Add _PyEval_EvalFrame() static inline function to get eval_frame from tstate->interp.
This commit is contained in:
		
							parent
							
								
									3ccdd9b180
								
							
						
					
					
						commit
						b9e681261c
					
				
					 4 changed files with 20 additions and 7 deletions
				
			
		|  | @ -11,6 +11,9 @@ extern "C" { | ||||||
| /* Forward declarations */ | /* Forward declarations */ | ||||||
| struct pyruntimestate; | struct pyruntimestate; | ||||||
| struct _ceval_runtime_state; | struct _ceval_runtime_state; | ||||||
|  | struct _frame; | ||||||
|  | 
 | ||||||
|  | #include "pycore_pystate.h"   /* PyInterpreterState.eval_frame */ | ||||||
| 
 | 
 | ||||||
| PyAPI_FUNC(void) _Py_FinishPendingCalls(struct pyruntimestate *runtime); | PyAPI_FUNC(void) _Py_FinishPendingCalls(struct pyruntimestate *runtime); | ||||||
| PyAPI_FUNC(void) _PyEval_Initialize(struct _ceval_runtime_state *); | PyAPI_FUNC(void) _PyEval_Initialize(struct _ceval_runtime_state *); | ||||||
|  | @ -34,6 +37,12 @@ PyAPI_FUNC(void) _PyEval_SetCoroutineOriginTrackingDepth( | ||||||
| /* Private function */ | /* Private function */ | ||||||
| void _PyEval_Fini(void); | void _PyEval_Fini(void); | ||||||
| 
 | 
 | ||||||
|  | static inline PyObject* | ||||||
|  | _PyEval_EvalFrame(PyThreadState *tstate, struct _frame *f, int throwflag) | ||||||
|  | { | ||||||
|  |     return tstate->interp->eval_frame(f, throwflag); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| #ifdef __cplusplus | #ifdef __cplusplus | ||||||
| } | } | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  | @ -1,4 +1,5 @@ | ||||||
| #include "Python.h" | #include "Python.h" | ||||||
|  | #include "pycore_ceval.h"   /* _PyEval_EvalFrame() */ | ||||||
| #include "pycore_object.h" | #include "pycore_object.h" | ||||||
| #include "pycore_pyerrors.h" | #include "pycore_pyerrors.h" | ||||||
| #include "pycore_pystate.h" | #include "pycore_pystate.h" | ||||||
|  | @ -303,7 +304,7 @@ function_code_fastcall(PyCodeObject *co, PyObject *const *args, Py_ssize_t nargs | ||||||
|         Py_INCREF(*args); |         Py_INCREF(*args); | ||||||
|         fastlocals[i] = *args++; |         fastlocals[i] = *args++; | ||||||
|     } |     } | ||||||
|     PyObject *result = PyEval_EvalFrameEx(f, 0); |     PyObject *result = _PyEval_EvalFrame(tstate, f, 0); | ||||||
| 
 | 
 | ||||||
|     if (Py_REFCNT(f) > 1) { |     if (Py_REFCNT(f) > 1) { | ||||||
|         Py_DECREF(f); |         Py_DECREF(f); | ||||||
|  |  | ||||||
|  | @ -1,6 +1,7 @@ | ||||||
| /* Generator object implementation */ | /* Generator object implementation */ | ||||||
| 
 | 
 | ||||||
| #include "Python.h" | #include "Python.h" | ||||||
|  | #include "pycore_ceval.h"   /* _PyEval_EvalFrame() */ | ||||||
| #include "pycore_object.h" | #include "pycore_object.h" | ||||||
| #include "pycore_pystate.h" | #include "pycore_pystate.h" | ||||||
| #include "frameobject.h" | #include "frameobject.h" | ||||||
|  | @ -219,7 +220,7 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc, int closing) | ||||||
|     gen->gi_running = 1; |     gen->gi_running = 1; | ||||||
|     gen->gi_exc_state.previous_item = tstate->exc_info; |     gen->gi_exc_state.previous_item = tstate->exc_info; | ||||||
|     tstate->exc_info = &gen->gi_exc_state; |     tstate->exc_info = &gen->gi_exc_state; | ||||||
|     result = PyEval_EvalFrameEx(f, exc); |     result = _PyEval_EvalFrame(tstate, f, exc); | ||||||
|     tstate->exc_info = gen->gi_exc_state.previous_item; |     tstate->exc_info = gen->gi_exc_state.previous_item; | ||||||
|     gen->gi_exc_state.previous_item = NULL; |     gen->gi_exc_state.previous_item = NULL; | ||||||
|     gen->gi_running = 0; |     gen->gi_running = 0; | ||||||
|  |  | ||||||
|  | @ -722,18 +722,20 @@ PyEval_EvalCode(PyObject *co, PyObject *globals, PyObject *locals) | ||||||
| /* Interpreter main loop */ | /* Interpreter main loop */ | ||||||
| 
 | 
 | ||||||
| PyObject * | PyObject * | ||||||
| PyEval_EvalFrame(PyFrameObject *f) { | PyEval_EvalFrame(PyFrameObject *f) | ||||||
|  | { | ||||||
|     /* This is for backward compatibility with extension modules that
 |     /* This is for backward compatibility with extension modules that
 | ||||||
|        used this API; core interpreter code should call |        used this API; core interpreter code should call | ||||||
|        PyEval_EvalFrameEx() */ |        PyEval_EvalFrameEx() */ | ||||||
|     return PyEval_EvalFrameEx(f, 0); |     PyThreadState *tstate = _PyThreadState_GET(); | ||||||
|  |     return _PyEval_EvalFrame(tstate, f, 0); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| PyObject * | PyObject * | ||||||
| PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) | PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) | ||||||
| { | { | ||||||
|     PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE(); |     PyThreadState *tstate = _PyThreadState_GET(); | ||||||
|     return interp->eval_frame(f, throwflag); |     return _PyEval_EvalFrame(tstate, f, throwflag); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| PyObject* _Py_HOT_FUNCTION | PyObject* _Py_HOT_FUNCTION | ||||||
|  | @ -4295,7 +4297,7 @@ _PyEval_EvalCodeWithName(PyObject *_co, PyObject *globals, PyObject *locals, | ||||||
|         return gen; |         return gen; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     retval = PyEval_EvalFrameEx(f,0); |     retval = _PyEval_EvalFrame(tstate, f, 0); | ||||||
| 
 | 
 | ||||||
| fail: /* Jump here from prelude on failure */ | fail: /* Jump here from prelude on failure */ | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Victor Stinner
						Victor Stinner