summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-07-04 18:43:12 (GMT)
committerGitHub <noreply@github.com>2022-07-04 18:43:12 (GMT)
commit68f5fa668343341b79ce1e23f1d9e773b98fd312 (patch)
treebc9b4ab897d1addc94ebf52c643e720fb75944d7 /Include
parent8fe0b1d8fa3451e923d7632263be6145a0734468 (diff)
downloadcpython-68f5fa668343341b79ce1e23f1d9e773b98fd312.zip
cpython-68f5fa668343341b79ce1e23f1d9e773b98fd312.tar.gz
cpython-68f5fa668343341b79ce1e23f1d9e773b98fd312.tar.bz2
[3.11] GH-94262: Don't create frame objects for frames that aren't yet complete. (GH-94371) (#94482)
Co-authored-by: Mark Shannon <mark@hotpy.org>
Diffstat (limited to 'Include')
-rw-r--r--Include/internal/pycore_frame.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h
index 405afd6..efdcdbc 100644
--- a/Include/internal/pycore_frame.h
+++ b/Include/internal/pycore_frame.h
@@ -133,6 +133,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 *
@@ -144,6 +159,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;