From aa0ce98b3e7228a469fa11709fbd6864242079b4 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 24 Jan 2018 14:13:26 -0800 Subject: [PATCH] Fix the initial state and polish a couple comments. --- py/gc.c | 2 +- py/gc_long_lived.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/py/gc.c b/py/gc.c index ffdcbe5c02..2c2354e4c0 100644 --- a/py/gc.c +++ b/py/gc.c @@ -147,7 +147,7 @@ void gc_init(void *start, void *end) { #endif // Set first free ATB index to the start of the heap. - MP_STATE_MEM(gc_last_free_atb_index) = 0; + MP_STATE_MEM(gc_first_free_atb_index) = 0; // Set last free ATB index to the end of the heap. MP_STATE_MEM(gc_last_free_atb_index) = MP_STATE_MEM(gc_alloc_table_byte_len) - 1; // Set the lowest long lived ptr to the end of the heap to start. This will be lowered as long diff --git a/py/gc_long_lived.c b/py/gc_long_lived.c index bd0e63d9be..c50bbcd836 100644 --- a/py/gc_long_lived.c +++ b/py/gc_long_lived.c @@ -46,7 +46,6 @@ mp_obj_fun_bc_t *make_fun_bc_long_lived(mp_obj_fun_bc_t *fun_bc, uint8_t max_dep mp_raw_code_t* raw_code = MP_OBJ_TO_PTR(fun_bc->const_table[i]); if (raw_code->kind == MP_CODE_BYTECODE) { raw_code->data.u_byte.bytecode = gc_make_long_lived((byte*) raw_code->data.u_byte.bytecode); - // TODO(tannewt): Do we actually want to recurse here? raw_code->data.u_byte.const_table = gc_make_long_lived((byte*) raw_code->data.u_byte.const_table); } ((mp_uint_t *) fun_bc->const_table)[i] = (mp_uint_t) make_obj_long_lived( @@ -56,6 +55,8 @@ mp_obj_fun_bc_t *make_fun_bc_long_lived(mp_obj_fun_bc_t *fun_bc, uint8_t max_dep fun_bc->const_table = gc_make_long_lived((mp_uint_t*) fun_bc->const_table); // extra_args stores keyword only argument default values. size_t words = gc_nbytes(fun_bc) / sizeof(mp_uint_t*); + // Functions (mp_obj_fun_bc_t) have four pointers (base, globals, bytecode and const_table) + // before the variable length extra_args so remove them from the length. for (size_t i = 0; i < words - 4; i++) { if (fun_bc->extra_args[i] == NULL) { continue;