extern "C" {
#endif
+#include <stdbool.h>
+
/* runtime lifecycle */
int f_lasti; /* Last instruction if called */
int stacktop; /* Offset of TOS from localsplus */
PyFrameState f_state; /* What state the frame is in */
- int depth; /* Depth of the frame in a ceval loop */
+ bool is_entry; // Whether this is the "root" frame for the current CFrame.
PyObject *localsplus[1];
} InterpreterFrame;
frame->generator = NULL;
frame->f_lasti = -1;
frame->f_state = FRAME_CREATED;
- frame->depth = 0;
+ frame->is_entry = false;
}
/* Gets the pointer to the locals array
def func():
return sys._getframe()
x = func()
- check(x, size('3Pi3c8P2iciP'))
+ check(x, size('3Pi3c8P2ic?P'))
# function
def func(): pass
check(func, size('14Pi'))
check(bar, size('PP'))
# generator
def get_gen(): yield 1
- check(get_gen(), size('P2P4P4c8P2iciP'))
+ check(get_gen(), size('P2P4P4c8P2ic?P'))
# iterator
check(iter('abc'), size('lP'))
# callable-iterator
cframe.previous = prev_cframe;
tstate->cframe = &cframe;
- assert(frame->depth == 0);
+ frame->is_entry = true;
/* Push frame */
frame->previous = prev_cframe->current_frame;
cframe.current_frame = frame;
_PyFrame_SetStackPointer(frame, stack_pointer);
new_frame->previous = frame;
frame = cframe.current_frame = new_frame;
- new_frame->depth = frame->depth + 1;
goto start_frame;
}
TRACE_FUNCTION_EXIT();
DTRACE_FUNCTION_EXIT();
_Py_LeaveRecursiveCall(tstate);
- if (frame->depth) {
+ if (!frame->is_entry) {
frame = cframe.current_frame = pop_frame(tstate, frame);
_PyFrame_StackPush(frame, retval);
goto resume_frame;
}
TARGET(SEND) {
- assert(frame->depth == 0);
+ assert(frame->is_entry);
assert(STACK_LEVEL() >= 2);
PyObject *v = POP();
PyObject *receiver = TOP();
}
TARGET(YIELD_VALUE) {
- assert(frame->depth == 0);
+ assert(frame->is_entry);
PyObject *retval = POP();
if (frame->f_code->co_flags & CO_ASYNC_GENERATOR) {
_PyFrame_SetStackPointer(frame, stack_pointer);
new_frame->previous = frame;
cframe.current_frame = frame = new_frame;
- new_frame->depth = frame->depth + 1;
goto start_frame;
}
}
_PyFrame_SetStackPointer(frame, stack_pointer);
new_frame->previous = frame;
frame = cframe.current_frame = new_frame;
- new_frame->depth = frame->depth + 1;
goto start_frame;
}
exit_unwind:
assert(_PyErr_Occurred(tstate));
_Py_LeaveRecursiveCall(tstate);
- if (frame->depth == 0) {
+ if (frame->is_entry) {
/* Restore previous cframe and exit */
tstate->cframe = cframe.previous;
tstate->cframe->use_tracing = cframe.use_tracing;
def _f_lasti(self):
return self._f_special("f_lasti", int_from_int)
- def depth(self):
- return self._f_special("depth", int_from_int)
+ def is_entry(self):
+ return self._f_special("is_entry", bool)
def previous(self):
return self._f_special("previous", PyFramePtr)
line = interp_frame.current_line()
if line is not None:
sys.stdout.write(' %s\n' % line.strip())
- if interp_frame.depth() == 0:
+ if interp_frame.is_entry():
break
else:
sys.stdout.write('#%i (unable to read python frame information)\n' % self.get_index())
line = interp_frame.current_line()
if line is not None:
sys.stdout.write(' %s\n' % line.strip())
- if interp_frame.depth() == 0:
+ if interp_frame.is_entry():
break
else:
sys.stdout.write(' (unable to read python frame information)\n')
% (pyop_name.proxyval(set()),
pyop_value.get_truncated_repr(MAX_OUTPUT_LEN)))
- if pyop_frame.depth() == 0:
+ if pyop_frame.is_entry():
break
pyop_frame = pyop_frame.previous()