Commit 459d3f38 authored by George Wort's avatar George Wort

Don't always allocate code_state on the heap.

parent 0083d049
...@@ -276,15 +276,17 @@ STATIC mp_obj_t fun_bc_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const ...@@ -276,15 +276,17 @@ STATIC mp_obj_t fun_bc_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const
// allocate state for locals and stack // allocate state for locals and stack
size_t state_size = n_state * sizeof(mp_obj_t) + n_exc_stack * sizeof(mp_exc_stack_t); size_t state_size = n_state * sizeof(mp_obj_t) + n_exc_stack * sizeof(mp_exc_stack_t);
mp_code_state_t *code_state = NULL; mp_code_state_t *code_state = NULL;
code_state = m_new_obj_var_maybe(mp_code_state_t, byte, state_size); if (state_size > VM_MAX_STATE_ON_STACK) {
if (code_state != NULL) { code_state = m_new_obj_var_maybe(mp_code_state_t, byte, state_size);
m_rs_push_ptr(code_state);
} }
if (code_state == NULL) { if (code_state == NULL) {
code_state = alloca(sizeof(mp_code_state_t) + state_size); code_state = alloca(sizeof(mp_code_state_t) + state_size);
RETURN_ON_EXCEPTION(MP_OBJ_NULL) RETURN_ON_EXCEPTION(MP_OBJ_NULL)
state_size = 0; // indicate that we allocated using alloca state_size = 0; // indicate that we allocated using alloca
} }
else {
m_rs_push_ptr(code_state);
}
code_state->fun_bc = self; code_state->fun_bc = self;
code_state->ip = 0; code_state->ip = 0;
......
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