Commit 8f064e46 authored by Damien George's avatar Damien George

py/emitbc: Fix bug with BC emitter computing Python stack size.

Previous to this patch the mp_emit_bc_adjust_stack_size function would
adjust the current stack size but would not increase the maximum stack size
if the current size went above it.  This meant that certain Python code
(eg a try-finally block with no statements inside it) would not have enough
Python stack allocated to it.

This patch fixes the problem by always checking if the current stack size
goes above the maximum, and adjusting the latter if it does.
parent 04d05db2
......@@ -448,7 +448,19 @@ bool mp_emit_bc_last_emit_was_return_value(emit_t *emit) {
}
void mp_emit_bc_adjust_stack_size(emit_t *emit, mp_int_t delta) {
if (emit->pass == MP_PASS_SCOPE) {
return;
}
assert((mp_int_t)emit->stack_size + delta >= 0);
emit->stack_size += delta;
if (emit->stack_size > emit->scope->stack_size) {
emit->scope->stack_size = emit->stack_size;
}
emit->last_emit_was_return_value = false;
}
static inline void emit_bc_pre(emit_t *emit, mp_int_t stack_size_delta) {
mp_emit_bc_adjust_stack_size(emit, stack_size_delta);
}
void mp_emit_bc_set_source_line(emit_t *emit, mp_uint_t source_line) {
......@@ -471,18 +483,6 @@ void mp_emit_bc_set_source_line(emit_t *emit, mp_uint_t source_line) {
#endif
}
STATIC void emit_bc_pre(emit_t *emit, mp_int_t stack_size_delta) {
if (emit->pass == MP_PASS_SCOPE) {
return;
}
assert((mp_int_t)emit->stack_size + stack_size_delta >= 0);
emit->stack_size += stack_size_delta;
if (emit->stack_size > emit->scope->stack_size) {
emit->scope->stack_size = emit->stack_size;
}
emit->last_emit_was_return_value = false;
}
void mp_emit_bc_label_assign(emit_t *emit, mp_uint_t l) {
emit_bc_pre(emit, 0);
if (emit->pass == MP_PASS_SCOPE) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment