@@ -134,6 +134,21 @@ _PyFrame_SetStackPointer(_PyInterpreterFrame *frame, PyObject **stack_pointer)
134
134
frame -> stacktop = (int )(stack_pointer - frame -> localsplus );
135
135
}
136
136
137
+ /* Determine whether a frame is incomplete.
138
+ * A frame is incomplete if it is part way through
139
+ * creating cell objects or a generator or coroutine.
140
+ *
141
+ * Frames on the frame stack are incomplete until the
142
+ * first RESUME instruction.
143
+ * Frames owned by a generator are always complete.
144
+ */
145
+ static inline bool
146
+ _PyFrame_IsIncomplete (_PyInterpreterFrame * frame )
147
+ {
148
+ return frame -> owner != FRAME_OWNED_BY_GENERATOR &&
149
+ frame -> prev_instr < _PyCode_CODE (frame -> f_code ) + frame -> f_code -> _co_firsttraceable ;
150
+ }
151
+
137
152
/* For use by _PyFrame_GetFrameObject
138
153
Do not call directly. */
139
154
PyFrameObject *
@@ -145,6 +160,8 @@ _PyFrame_MakeAndSetFrameObject(_PyInterpreterFrame *frame);
145
160
static inline PyFrameObject *
146
161
_PyFrame_GetFrameObject (_PyInterpreterFrame * frame )
147
162
{
163
+
164
+ assert (!_PyFrame_IsIncomplete (frame ));
148
165
PyFrameObject * res = frame -> frame_obj ;
149
166
if (res != NULL ) {
150
167
return res ;
@@ -210,16 +227,6 @@ PyGenObject *_PyFrame_GetGenerator(_PyInterpreterFrame *frame)
210
227
return (PyGenObject * )(((char * )frame ) - offset_in_gen );
211
228
}
212
229
213
- /* Determine whether a frame is incomplete.
214
- * A frame is incomplete until the first RESUME instruction
215
- * as it may be part way through creating cell objects or a
216
- * generator or coroutine. */
217
- static inline bool
218
- _PyFrame_IsIncomplete (_PyInterpreterFrame * frame )
219
- {
220
- return frame -> prev_instr < _PyCode_CODE (frame -> f_code ) + frame -> f_code -> _co_firsttraceable ;
221
- }
222
-
223
230
#ifdef __cplusplus
224
231
}
225
232
#endif
0 commit comments