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.
This commit is contained in:
parent
04d05db27e
commit
8f064e469d
24
py/emitbc.c
24
py/emitbc.c
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user