[issue40941] Merge generator.gi_running and frame executing flag into single frame state

Mark Shannon report at bugs.python.org
Thu Jun 11 09:27:24 EDT 2020


Mark Shannon <mark at hotpy.org> added the comment:

This change combines the explicit state in `PyFrameObject.f_excuting` and `PyGenObject.gi_running`, and the implicit state in `PyFrameObject.f_stacktop == NULL` and `PyFrameObject.f_last == -1` into a single enum field in `PyFrameObject`.

Since we no longer need to test `PyFrameObject.f_stacktop == NULL` , The `f_stacktop` pointer can be replaced with a `f_stackdepth` integer, which make for simpler code when iterating over the stack and avoids the potential hazard of NULL pointers.

There are  three benefits to these changes:

1. The code is more robust and, IMO, easier to understand, as all state is now explicit.
2. It carries additional information about the state of the frame. Information about whether a frame exiting by `return` or by `raise` is available.
3. A modest reduction in size of frame and generator objects.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40941>
_______________________________________


More information about the Python-bugs-list mailing list