mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[python] Fixed infinite recursion bug.
When running a script with infinite recursion, micropython now throws an error instead of aborting and rebooting the device. Change-Id: Icd409e56de58a48b25b6bdb30eea1e70b344cc14
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#define MICROPY_DEBUG_PRINTERS (0)
|
||||
#define MICROPY_ENABLE_GC (1)
|
||||
#define MICROPY_GC_ALLOC_THRESHOLD (0)
|
||||
#define MICROPY_STACK_CHECK (1)
|
||||
#define MICROPY_REPL_EVENT_DRIVEN (0)
|
||||
#define MICROPY_HELPER_REPL (1)
|
||||
#define MICROPY_HELPER_LEXER_UNIX (0)
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include "port.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
@@ -23,8 +22,6 @@ extern "C" {
|
||||
#include "py/stackctrl.h"
|
||||
}
|
||||
|
||||
static char * python_stack_top = NULL;
|
||||
|
||||
static MicroPython::ScriptProvider * sScriptProvider = nullptr;
|
||||
static MicroPython::ExecutionEnvironment * sCurrentExecutionEnvironment = nullptr;
|
||||
|
||||
@@ -113,10 +110,20 @@ void MicroPython::ExecutionEnvironment::runCode(const char * str) {
|
||||
sCurrentExecutionEnvironment = nullptr;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
extern const void * _stack_start;
|
||||
extern const void * _stack_end;
|
||||
}
|
||||
|
||||
void MicroPython::init(void * heapStart, void * heapEnd) {
|
||||
mp_stack_set_limit(40000);
|
||||
char dummy;
|
||||
python_stack_top = &dummy;
|
||||
#if MP_PORT_USE_STACK_SYMBOLS
|
||||
mp_stack_set_top(&_stack_start);
|
||||
mp_stack_set_limit(&_stack_start - &_stack_end);
|
||||
#else
|
||||
volatile int stackTop;
|
||||
mp_stack_set_top((void *)(&stackTop));
|
||||
mp_stack_set_limit(4000);
|
||||
#endif
|
||||
gc_init(heapStart, heapEnd);
|
||||
mp_init();
|
||||
}
|
||||
@@ -130,7 +137,7 @@ void MicroPython::registerScriptProvider(ScriptProvider * s) {
|
||||
}
|
||||
|
||||
void gc_collect(void) {
|
||||
assert(python_stack_top != NULL);
|
||||
assert(MP_STATE_THREAD(stack_top) != NULL);
|
||||
gc_collect_start();
|
||||
|
||||
/* get the registers.
|
||||
@@ -145,10 +152,10 @@ void gc_collect(void) {
|
||||
* the case on a computer. We thus have to take the absolute value of the
|
||||
* addresses difference. */
|
||||
size_t stackLength;
|
||||
if ((uintptr_t)python_stack_top > (uintptr_t)(®s)) {
|
||||
stackLength = (((uintptr_t)python_stack_top - (uintptr_t)(®s)) / sizeof(uintptr_t));
|
||||
if ((uintptr_t)MP_STATE_THREAD(stack_top) > (uintptr_t)(®s)) {
|
||||
stackLength = (((uintptr_t)(MP_STATE_THREAD(stack_top)) - (uintptr_t)(®s)) / sizeof(uintptr_t));
|
||||
} else {
|
||||
stackLength = (((uintptr_t)(®s) - (uintptr_t)python_stack_top) / sizeof(uintptr_t));
|
||||
stackLength = (((uintptr_t)(®s) - (uintptr_t)(MP_STATE_THREAD(stack_top))) / sizeof(uintptr_t));
|
||||
}
|
||||
gc_collect_root(regs_ptr, stackLength);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user