@@ -406,6 +406,51 @@ frame_stack_pop(PyFrameObject *f)
406406 Py_DECREF (v );
407407}
408408
409+ typedef enum _framestate {
410+ FRAME_CREATED = -2 ,
411+ FRAME_SUSPENDED = -1 ,
412+ FRAME_EXECUTING = 0 ,
413+ FRAME_COMPLETED = 1 ,
414+ FRAME_CLEARED = 4
415+ } PyFrameState ;
416+
417+
418+ static PyFrameState
419+ _PyFrame_GetState (PyFrameObject * frame )
420+ {
421+ if (frame -> f_frame -> stacktop == 0 ) {
422+ return FRAME_CLEARED ;
423+ }
424+ switch (frame -> f_frame -> owner ) {
425+ case FRAME_OWNED_BY_GENERATOR :
426+ {
427+ PyGenObject * gen = _PyFrame_GetGenerator (frame -> f_frame );
428+ return gen -> gi_frame_state ;
429+ }
430+ case FRAME_OWNED_BY_THREAD :
431+ {
432+ if (frame -> f_frame -> f_lasti < 0 ) {
433+ return FRAME_CREATED ;
434+ }
435+ int opcode = PyBytes_AS_STRING (frame -> f_frame -> f_code -> co_code )
436+ [frame -> f_frame -> f_lasti * sizeof (_Py_CODEUNIT )];
437+ switch (opcode ) {
438+ case COPY_FREE_VARS :
439+ case MAKE_CELL :
440+ case RETURN_GENERATOR :
441+ /* Frame not fully initialized */
442+ return FRAME_CREATED ;
443+ default :
444+ return FRAME_EXECUTING ;
445+ }
446+ }
447+ case FRAME_OWNED_BY_FRAME_OBJECT :
448+ return FRAME_COMPLETED ;
449+ }
450+ Py_UNREACHABLE ();
451+ }
452+
453+
409454/* Setter for f_lineno - you can set f_lineno from within a trace function in
410455 * order to jump to a given line of code, subject to some restrictions. Most
411456 * lines are OK to jump to because they don't make any assumptions about the
@@ -1091,38 +1136,3 @@ _PyEval_BuiltinsFromGlobals(PyThreadState *tstate, PyObject *globals)
10911136}
10921137
10931138
1094- PyFrameState
1095- PyFrame_GetState (PyFrameObject * frame )
1096- {
1097- if (frame -> f_frame -> stacktop == 0 ) {
1098- return FRAME_CLEARED ;
1099- }
1100- switch (frame -> f_frame -> owner ) {
1101- case FRAME_OWNED_BY_GENERATOR :
1102- {
1103- PyGenObject * gen = _PyFrame_GetGenerator (frame -> f_frame );
1104- return gen -> gi_frame_state ;
1105- }
1106- case FRAME_OWNED_BY_THREAD :
1107- {
1108- if (frame -> f_frame -> f_lasti < 0 ) {
1109- return FRAME_CREATED ;
1110- }
1111- int opcode = PyBytes_AS_STRING (frame -> f_frame -> f_code -> co_code )
1112- [frame -> f_frame -> f_lasti * sizeof (_Py_CODEUNIT )];
1113- switch (opcode ) {
1114- case COPY_FREE_VARS :
1115- case MAKE_CELL :
1116- case RETURN_GENERATOR :
1117- /* Frame not fully initialized */
1118- return FRAME_CREATED ;
1119- default :
1120- return FRAME_EXECUTING ;
1121- }
1122- }
1123- case FRAME_OWNED_BY_FRAME_OBJECT :
1124- return FRAME_COMPLETED ;
1125- }
1126- Py_UNREACHABLE ();
1127- }
1128-
0 commit comments