Adding the following to hello-embed.c:
Code: Select all
// heap exhaustion test
const char str_heaptest[] =
"import gc\n"
"for i in range(1000):\n"
" print(\"mem: %d / %d\"%(gc.mem_alloc(), gc.mem_free()))";
if (execute_from_str(str_heaptest)) {
printf("Error\n");
}
Code: Select all
[...]
mem: 15808 / 448
mem: 15904 / 352
mem: 16000 / 256
mem: 16096 / 160
Segmentation fault (core dumped)
Code: Select all
Program received signal SIGSEGV, Segmentation fault.
gc_collect_root (ptrs=ptrs@entry=0x7fffffffd410, len=2305825417027650942) at ../../py/gc.c:345
345 void *ptr = ptrs[i];
(gdb) backtrace
#0 gc_collect_root (ptrs=ptrs@entry=0x7fffffffd410, len=2305825417027650942) at ../../py/gc.c:345
#1 0x00000000004142f8 in gc_helper_collect_regs_and_stack () at ../../lib/utils/gchelper_generic.c:154
#2 0x0000000000414297 in gc_collect () at libmicropython.c:44
#3 0x0000000000401db5 in gc_alloc (n_bytes=n_bytes@entry=32, alloc_flags=alloc_flags@entry=0) at ../../py/gc.c:490
#4 0x0000000000414376 in m_malloc (num_bytes=num_bytes@entry=32) at ../../py/malloc.c:86
#5 0x000000000040ddc7 in mp_obj_new_str_from_vstr (type=0x419800 <mp_type_str>, vstr=0x7fffffffd550) at ../../py/objstr.c:2069
#6 0x000000000040efb7 in mp_obj_str_binary_op (op=<optimized out>, lhs_in=<optimized out>, rhs_in=<optimized out>) at ../../py/objstr.c:342
#7 0x000000000040a3eb in mp_binary_op (op=MP_BINARY_OP_MODULO, lhs=0x4266a0 <heap+1504>, rhs=0x42a080 <heap+16320>) at ../../py/runtime.c:570
#8 0x0000000000412aac in mp_execute_bytecode (code_state=code_state@entry=0x7fffffffd6f0, inject_exc=inject_exc@entry=0x0) at ../../py/vm.c:1346
#9 0x000000000040c06b in fun_bc_call (self_in=0x4262c0 <heap+512>, n_args=0, n_kw=<optimized out>, args=<optimized out>) at ../../py/objfun.c:283
#10 0x0000000000401290 in execute_from_str (str=0x7fffffffd850 "import gc\nfor i in range(1000):\n print(\"mem: %d / %d\"%(gc.mem_alloc(), gc.mem_free()))") at hello-embed.c:49
#11 0x0000000000401513 in main () at hello-embed.c:111
(gdb) print i
$3 = 894