From a4e06bd998a1fb2d2dd209524d8ccd69b18712e6 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 5 Jun 2018 22:04:30 -0500 Subject: [PATCH] main: Explicitly set the stack top based on _estack .. setting it based on the ad-hoc stack pointer calculation of mp_stack_ctrl_init() meant that the stack used above main() counts against the 1KiB safety factor that the mp_stack_set_limit call tries to establish. It turns out, at least on M4, that over half of the safety factor is used up by stack-above-main()! In the case of the basics/gen_stack_overflow.py test, which blows the stack on purpose, it turns out that gc would be called while handling the "maximum recursion depth exceeded" error, and this needed more stack than was left. Closes: #900 --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index 4402ebe328..4ed4f5d7cb 100644 --- a/main.c +++ b/main.c @@ -241,7 +241,7 @@ int __attribute__((used)) main(void) { // Stack limit should be less than real stack size, so we have a chance // to recover from limit hit. (Limit is measured in bytes.) - mp_stack_ctrl_init(); + mp_stack_set_top((char*)&_estack); mp_stack_set_limit((char*)&_estack - (char*)&_ebss - 1024); #if MICROPY_MAX_STACK_USAGE