From 2077bb9da994c32008bf4b9ce14a7cf6a190b742 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Wed, 15 Feb 2023 17:54:52 +0200 Subject: [PATCH] pystack_size as multiple of sizeof size_t, no more stackless via settings.toml --- main.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/main.c b/main.c index 55f464bc00..ffd5b80610 100644 --- a/main.c +++ b/main.c @@ -122,7 +122,7 @@ uint8_t value_out = 0; #endif -#if MICROPY_ENABLE_PYSTACK +#if MICROPY_ENABLE_PYSTACK && CIRCUITPY_OS_GETENV #include "shared-module/os/__init__.h" #endif @@ -160,9 +160,7 @@ STATIC void start_mp(supervisor_allocation *heap, supervisor_allocation *pystack readline_init0(); #if MICROPY_ENABLE_PYSTACK - if (pystack_size > 0) { - mp_pystack_init(pystack->ptr, pystack->ptr + (pystack_size / sizeof(size_t))); - } + mp_pystack_init(pystack->ptr, pystack->ptr + (pystack_size / sizeof(size_t))); #endif #if MICROPY_ENABLE_GC @@ -995,9 +993,11 @@ int __attribute__((used)) main(void) { // Leaves size to build default on any failure (void)common_hal_os_getenv_int("CIRCUITPY_PYSTACK_SIZE", &pystack_size); free_memory(heap); + // Convert frame count to allocation size, 384 is the default for 1536 bytes + pystack_size = pystack_size * sizeof(size_t); - // Check if value is valid multiple of size_t else revert - if ((CIRCUITPY_PYSTACK_SIZE != pystack_size) && (pystack_size > 0) && (pystack_size % sizeof(size_t) != 0)) { + // Check if value is valid + if ((CIRCUITPY_PYSTACK_SIZE != pystack_size) && (pystack_size < 1)) { pystack_size = CIRCUITPY_PYSTACK_SIZE; // Reset to build default // TODO: Find a way to inform the user about it. // Perhaps safemode? @@ -1005,9 +1005,7 @@ int __attribute__((used)) main(void) { if (CIRCUITPY_PYSTACK_SIZE != pystack_size) { free_memory(pystack); // Free the temporary - if (pystack_size > 0) { // Allocate new if needed - pystack = allocate_memory(pystack_size, false, false); - } + pystack = allocate_memory(pystack_size, false, false); // Allocate new pystack } #endif #endif