mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
GH-94262: Don't create frame objects for frames that aren't yet complete. (GH-94371)
This commit is contained in:
parent
1df9449db2
commit
544531de23
7 changed files with 87 additions and 13 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue