Skip to content

Commit fe5696b

Browse files
committed
Works?
1 parent 4555ad6 commit fe5696b

6 files changed

Lines changed: 24 additions & 12 deletions

File tree

py/compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ static void mp_emit_common_start_pass(mp_emit_common_t *emit, pass_kind_t pass)
221221
if (emit->ct_cur_child == 0) {
222222
emit->children = NULL;
223223
} else {
224-
emit->children = m_new0(mp_raw_code_t *, emit->ct_cur_child);
224+
emit->children = m_malloc_helper(sizeof(mp_raw_code_t *) * (emit->ct_cur_child), M_MALLOC_ENSURE_ZEROED | M_MALLOC_RAISE_ERROR | M_MALLOC_COLLECT);
225225
}
226226
}
227227
emit->ct_cur_child = 0;

py/emitbc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct _emit_t {
7676
};
7777

7878
emit_t *emit_bc_new(mp_emit_common_t *emit_common) {
79-
emit_t *emit = m_new0(emit_t, 1);
79+
emit_t *emit = m_new_struct_with_collect(emit_t, 1);
8080
emit->emit_common = emit_common;
8181
return emit;
8282
}

py/emitglue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ mp_uint_t mp_verbose_flag = 0;
5454
#endif
5555

5656
mp_raw_code_t *mp_emit_glue_new_raw_code(void) {
57-
mp_raw_code_t *rc = m_new0(mp_raw_code_t, 1);
57+
mp_raw_code_t *rc = m_malloc_helper(sizeof(mp_raw_code_t), M_MALLOC_ENSURE_ZEROED | M_MALLOC_RAISE_ERROR | M_MALLOC_COLLECT);
5858
rc->kind = MP_CODE_RESERVED;
5959
#if MICROPY_PY_SYS_SETTRACE
6060
rc->line_of_definition = 0;

py/gc.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ void __attribute__ ((noinline)) gc_log_change(uint32_t start_block, uint32_t len
154154
#pragma GCC pop_options
155155
#endif
156156

157+
static bool debug_collect = false;
158+
157159
// TODO waste less memory; currently requires that all entries in alloc_table have a corresponding block in pool
158160
static void gc_setup_area(mp_state_mem_area_t *area, void *start, void *end) {
159161
// calculate parameters for GC (T=total, A=alloc table, F=finaliser table, L=leaf table, P=pool; all in bytes):
@@ -486,7 +488,7 @@ static void MP_NO_INSTRUMENT PLACE_IN_ITCM(gc_mark_subtree)(size_t block)
486488
#endif
487489

488490
// Only scan the block's children if it's not a leaf
489-
if (true || should_scan) {
491+
if (debug_collect || should_scan) {
490492
// console_uart_printf("scanning block %p[%d]\n", area, block);
491493
// check this block's children
492494
void **ptrs = (void **)PTR_FROM_BLOCK(area, block);
@@ -830,6 +832,8 @@ bool gc_alloc_possible(void) {
830832
return MP_STATE_MEM(area).gc_pool_start != 0;
831833
}
832834

835+
static size_t count9be0 = 0;
836+
833837
void *gc_alloc(size_t n_bytes, unsigned int alloc_flags) {
834838
bool has_finaliser = alloc_flags & GC_ALLOC_FLAG_HAS_FINALISER;
835839
size_t n_blocks = ((n_bytes + BYTES_PER_BLOCK - 1) & (~(BYTES_PER_BLOCK - 1))) / BYTES_PER_BLOCK;
@@ -1018,10 +1022,17 @@ void *gc_alloc(size_t n_bytes, unsigned int alloc_flags) {
10181022
memorymonitor_track_allocation(end_block - start_block + 1);
10191023
#endif
10201024

1021-
// if ((size_t)ret_ptr == 0x11024380) {
1022-
// console_uart_printf("gc_alloc(%d, %01x) = %p\n", n_bytes, alloc_flags, ret_ptr);
1023-
// asm("bkpt");
1024-
// }
1025+
if (debug_collect) {
1026+
if ((size_t)ret_ptr == 0x1101b490) {
1027+
if (count9be0 == 1) {
1028+
asm ("bkpt");
1029+
}
1030+
console_uart_printf("count9be0 = %d\n", count9be0);
1031+
count9be0++;
1032+
}
1033+
1034+
console_uart_printf("gc_alloc(%d, %01x) = %p\n", n_bytes, alloc_flags, ret_ptr);
1035+
}
10251036

10261037
return ret_ptr;
10271038
}
@@ -1347,7 +1358,9 @@ void *gc_realloc(void *ptr_in, size_t n_bytes, bool allow_move) {
13471358
// can't resize inplace; try to find a new contiguous chain
13481359
void *ptr_out = gc_alloc(n_bytes, alloc_flags);
13491360

1350-
console_uart_printf("gc_realloc: moving %p -> %p, %d -> %d bytes\n", ptr_in, ptr_out, n_blocks * BYTES_PER_BLOCK, n_bytes);
1361+
if (debug_collect) {
1362+
console_uart_printf("gc_realloc: moving %p -> %p, %d -> %d bytes\n", ptr_in, ptr_out, n_blocks * BYTES_PER_BLOCK, n_bytes);
1363+
}
13511364
// check that the alloc succeeded
13521365
if (ptr_out == NULL) {
13531366
return NULL;

py/objmodule.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ mp_obj_t mp_obj_new_module(qstr module_name) {
134134
}
135135

136136
// create new module object
137-
mp_module_context_t *o = m_new_obj(mp_module_context_t);
138-
o->module.base.type = &mp_type_module;
137+
mp_module_context_t *o = mp_obj_malloc(mp_module_context_t, &mp_type_module);
139138
o->module.globals = MP_OBJ_TO_PTR(mp_obj_new_dict(MICROPY_MODULE_DICT_SIZE));
140139

141140
// store __name__ entry in the module

py/scope.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ scope_t *scope_new(scope_kind_t kind, mp_parse_node_t pn, mp_uint_t emit_options
5151
MP_STATIC_ASSERT(MP_QSTR__lt_setcomp_gt_ <= UINT8_MAX);
5252
MP_STATIC_ASSERT(MP_QSTR__lt_genexpr_gt_ <= UINT8_MAX);
5353

54-
scope_t *scope = m_new0(scope_t, 1);
54+
scope_t *scope = m_new_struct_with_collect(scope_t, 1);
5555
scope->kind = kind;
5656
scope->pn = pn;
5757
if (kind == SCOPE_FUNCTION || kind == SCOPE_CLASS) {

0 commit comments

Comments
 (0)