From 7ee3f30c174fd7143c1dcccb5ec3c9e1bdd4ede2 Mon Sep 17 00:00:00 2001 From: MicroDev <70126934+MicroDev1@users.noreply.github.com> Date: Tue, 21 Mar 2023 07:06:46 +0530 Subject: [PATCH] rewrite `allocate_pystack` logic --- locale/circuitpython.pot | 12 ++++-------- main.c | 22 +++++++--------------- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 560dffe6a4..0c7f823b5a 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -28,14 +28,6 @@ msgid "" "Code stopped by auto-reload. Reloading soon.\n" msgstr "" -#: main.c -msgid "" -"\n" -"Invalid CIRCUITPY_PYSTACK_SIZE\n" -"\n" -"\r" -msgstr "" - #: supervisor/shared/safe_mode.c msgid "" "\n" @@ -1252,6 +1244,10 @@ msgstr "" msgid "Invalid BSSID" msgstr "" +#: main.c +msgid "Invalid CIRCUITPY_PYSTACK_SIZE\n" +msgstr "" + #: shared-bindings/wifi/Radio.c msgid "Invalid MAC address" msgstr "" diff --git a/main.c b/main.c index 002c97c167..7b805b57b0 100644 --- a/main.c +++ b/main.c @@ -134,26 +134,18 @@ static void reset_devices(void) { #if MICROPY_ENABLE_PYSTACK STATIC supervisor_allocation *allocate_pystack(safe_mode_t safe_mode) { - mp_int_t pystack_size = CIRCUITPY_PYSTACK_SIZE; #if CIRCUITPY_OS_GETENV && CIRCUITPY_SETTABLE_PYSTACK - // Fetch value if exists from settings.toml - // Leaves size to build default on any failure - if (safe_mode == SAFE_MODE_NONE || safe_mode == SAFE_MODE_USER) { + if (safe_mode == SAFE_MODE_NONE) { + mp_int_t pystack_size = CIRCUITPY_PYSTACK_SIZE; (void)common_hal_os_getenv_int("CIRCUITPY_PYSTACK_SIZE", &pystack_size); - // Check if value is valid - pystack_size = pystack_size - pystack_size % sizeof(size_t); // Round down to multiple of 4. - if ((pystack_size < 384) || (pystack_size > 900000)) { - serial_write_compressed(translate("\nInvalid CIRCUITPY_PYSTACK_SIZE\n\n\r")); - pystack_size = CIRCUITPY_PYSTACK_SIZE; // Reset + supervisor_allocation *pystack = allocate_memory(pystack_size >= 384 ? pystack_size : 0, false, false); + if (pystack) { + return pystack; } + serial_write_compressed(translate("Invalid CIRCUITPY_PYSTACK_SIZE\n")); } #endif - supervisor_allocation *pystack = allocate_memory(pystack_size, false, false); - if (pystack == NULL) { - serial_write_compressed(translate("\nInvalid CIRCUITPY_PYSTACK_SIZE\n\n\r")); - pystack = allocate_memory(CIRCUITPY_PYSTACK_SIZE, false, false); - } - return pystack; + return allocate_memory(CIRCUITPY_PYSTACK_SIZE, false, false); } #endif