diff options
author | Mark Shannon <mark@hotpy.org> | 2022-07-01 10:08:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-01 10:08:20 (GMT) |
commit | 544531de23d69f5b23883794fc7bb23a958a0fcb (patch) | |
tree | ad88c0a6543127cd89027843ab441aa29dbdbc75 /Include/internal/pycore_frame.h | |
parent | 1df9449db24f16c9c96bdd7dc283a5062bca68e6 (diff) | |
download | cpython-544531de23d69f5b23883794fc7bb23a958a0fcb.zip cpython-544531de23d69f5b23883794fc7bb23a958a0fcb.tar.gz cpython-544531de23d69f5b23883794fc7bb23a958a0fcb.tar.bz2 |
GH-94262: Don't create frame objects for frames that aren't yet complete. (GH-94371)
Diffstat (limited to 'Include/internal/pycore_frame.h')
-rw-r--r-- | Include/internal/pycore_frame.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h index eed26fb..994c205 100644 --- a/Include/internal/pycore_frame.h +++ b/Include/internal/pycore_frame.h @@ -134,6 +134,21 @@ _PyFrame_SetStackPointer(_PyInterpreterFrame *frame, PyObject **stack_pointer) frame->stacktop = (int)(stack_pointer - frame->localsplus); } +/* Determine whether a frame is incomplete. + * A frame is incomplete if it is part way through + * creating cell objects or a generator or coroutine. + * + * Frames on the frame stack are incomplete until the + * first RESUME instruction. + * Frames owned by a generator are always complete. + */ +static inline bool +_PyFrame_IsIncomplete(_PyInterpreterFrame *frame) +{ + return frame->owner != FRAME_OWNED_BY_GENERATOR && + frame->prev_instr < _PyCode_CODE(frame->f_code) + frame->f_code->_co_firsttraceable; +} + /* For use by _PyFrame_GetFrameObject Do not call directly. */ PyFrameObject * @@ -145,6 +160,8 @@ _PyFrame_MakeAndSetFrameObject(_PyInterpreterFrame *frame); static inline PyFrameObject * _PyFrame_GetFrameObject(_PyInterpreterFrame *frame) { + + assert(!_PyFrame_IsIncomplete(frame)); PyFrameObject *res = frame->frame_obj; if (res != NULL) { return res; |