File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5353// detect untraced object still in use
5454#define CLEAR_ON_SWEEP (0)
5555
56- #define WORDS_PER_BLOCK ((MICROPY_BYTES_PER_GC_BLOCK) / BYTES_PER_WORD)
57- #define BYTES_PER_BLOCK (MICROPY_BYTES_PER_GC_BLOCK)
58-
5956// ATB = allocation table byte
6057// 0b00 = FREE -- free block
6158// 0b01 = HEAD -- head of a chain of blocks
@@ -209,13 +206,6 @@ bool gc_is_locked(void) {
209206 return MP_STATE_MEM (gc_lock_depth ) != 0 ;
210207}
211208
212- // ptr should be of type void*
213- #define VERIFY_PTR (ptr ) ( \
214- ((uintptr_t)(ptr) & (BYTES_PER_BLOCK - 1)) == 0 /* must be aligned on a block */ \
215- && ptr >= (void*)MP_STATE_MEM(gc_pool_start) /* must be above start of pool */ \
216- && ptr < (void*)MP_STATE_MEM(gc_pool_end) /* must be below end of pool */ \
217- )
218-
219209#ifndef TRACE_MARK
220210#if DEBUG_PRINT
221211#define TRACE_MARK (block , ptr ) DEBUG_printf("gc_mark(%p)\n", ptr)
Original file line number Diff line number Diff line change 2929#include <stdint.h>
3030
3131#include "py/mpconfig.h"
32+ #include "py/mpstate.h"
3233#include "py/misc.h"
3334
35+ #define WORDS_PER_BLOCK ((MICROPY_BYTES_PER_GC_BLOCK) / BYTES_PER_WORD)
36+ #define BYTES_PER_BLOCK (MICROPY_BYTES_PER_GC_BLOCK)
37+
38+ // ptr should be of type void*
39+ #define VERIFY_PTR (ptr ) ( \
40+ ((uintptr_t)(ptr) & (BYTES_PER_BLOCK - 1)) == 0 /* must be aligned on a block */ \
41+ && ptr >= (void*)MP_STATE_MEM(gc_pool_start) /* must be above start of pool */ \
42+ && ptr < (void*)MP_STATE_MEM(gc_pool_end) /* must be below end of pool */ \
43+ )
44+
3445void gc_init (void * start , void * end );
3546void gc_deinit (void );
3647
Original file line number Diff line number Diff line change @@ -126,6 +126,11 @@ mp_obj_t make_obj_long_lived(mp_obj_t obj, uint8_t max_depth){
126126 if (obj == NULL ) {
127127 return obj ;
128128 }
129+ // If not in the GC pool, do nothing. This can happen (at least) when
130+ // there are frozen mp_type_bytes objects in ROM.
131+ if (!VERIFY_PTR ((void * )obj )) {
132+ return obj ;
133+ }
129134 if (MP_OBJ_IS_TYPE (obj , & mp_type_fun_bc )) {
130135 mp_obj_fun_bc_t * fun_bc = MP_OBJ_TO_PTR (obj );
131136 return MP_OBJ_FROM_PTR (make_fun_bc_long_lived (fun_bc , max_depth ));
You can’t perform that action at this time.
0 commit comments