Skip to content

Commit 53e5e0f

Browse files
committed
py: Make old_globals part of mp_code_state structure.
Conceptually it is part of code state, so let it be allocated in the same way as the rest of state.
1 parent e5039c6 commit 53e5e0f

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

py/bc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ typedef struct _mp_code_state {
4545
mp_obj_t *sp;
4646
// bit 0 is saved currently_in_except_block value
4747
mp_exc_stack_t *exc_sp;
48+
mp_obj_dict_t *old_globals;
4849
mp_uint_t n_state;
4950
// Variable-length
5051
mp_obj_t state[0];

py/objfun.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ STATIC void dump_args(const mp_obj_t *a, mp_uint_t sz) {
137137
// With this macro you can tune the maximum number of function state bytes
138138
// that will be allocated on the stack. Any function that needs more
139139
// than this will use the heap.
140-
#define VM_MAX_STATE_ON_STACK (10 * sizeof(mp_uint_t))
140+
#define VM_MAX_STATE_ON_STACK (11 * sizeof(mp_uint_t))
141141

142142
// Set this to enable a simple stack overflow check.
143143
#define VM_DETECT_STACK_OVERFLOW (0)
@@ -183,10 +183,10 @@ STATIC mp_obj_t fun_bc_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw,
183183
mp_setup_code_state(code_state, self_in, n_args, n_kw, args);
184184

185185
// execute the byte code with the correct globals context
186-
mp_obj_dict_t *old_globals = mp_globals_get();
186+
code_state->old_globals = mp_globals_get();
187187
mp_globals_set(self->globals);
188188
mp_vm_return_kind_t vm_return_kind = mp_execute_bytecode(code_state, MP_OBJ_NULL);
189-
mp_globals_set(old_globals);
189+
mp_globals_set(code_state->old_globals);
190190

191191
#if VM_DETECT_STACK_OVERFLOW
192192
if (vm_return_kind == MP_VM_RETURN_NORMAL) {

0 commit comments

Comments
 (0)