Use an unmodified PyFrameObject structure and simplify ceval.c #270
Description
Currently PyFrameObject
and PyCFrameObject
share the fields f_back
and f_execute
. The files f_execute
is an Stackless specific addition to PyFrameObject
.
I propose to remove the field f_execute
from PyFrameObject
and store the information previously held in f_execute
in the field f_executing
.
Rationale
The only possible values of PyFrameObject.f_execute
are PyEval_EvalFrameEx_slp
, slp_eval_frame_value
,
slp_eval_frame_noval
, slp_eval_frame_setup_with
, slp_eval_frame_with_cleanup
, slp_eval_frame_yield_from
and - in case of unpickling invalid frames - corresponding cannot_*
functions.
Of these slp_eval_frame_noval
, slp_eval_frame_setup_with
, slp_eval_frame_with_cleanup
and slp_eval_frame_yield_from
are trivial wrappers around slp_eval_frame_value
with an completely identical body.
Lines 3840 to 3913 in 74f33db
PyEval_EvalFrameEx_slp
is also a fairly simple wrapper around slp_eval_frame_value
. Differences in behavior between the five execution functions slp_eval_frame*
is not caused by their body, but only by an if
-block in slp_eval_frame_value
:
Lines 1090 to 1116 in 74f33db
That is,
PyFrameObject.f_execute
is already used as a flag and not as a dispatch pointer. We can replace it with the already existing field f_executing
. This field is a boolean flag field:
- 0: frame is not executing
- !0: frame is executing
C-Python stores only 0 and 1 in f_executing
. Because C-Python makes no difference between various non-zero values of f_executing
, it is possible to use values other than 1 to store the information currently encoded by different values of f_execute
.
Now, if we drop the field f_execute
from PyFrameObject
we get the following benefits:
- Unmodified
PyFrameObject
: better compatibility with C-Python. Eventually we can even support the frame evaluation API "eval_frame" defined in PEP 523 (see PyCharm pydevd debug crash #240). - Unmodified
PyFrameObject
: better maintainability. - We can remove the functions
slp_eval_frame_noval
,slp_eval_frame_setup_with
,slp_eval_frame_with_cleanup
,slp_eval_frame_yield_from
- Probably it is possible to merge
PyEval_EvalFrameEx_slp
andslp_eval_frame_value
. This would remove duplicated code in ceval.c and greatly improve maintainability.
Today I made a quick test implementation to prove, that the idea works. I'm going to create pull requests for the implementation.