rewrite `allocate_pystack` logic
This commit is contained in:
parent
c600429df7
commit
7ee3f30c17
|
@ -28,14 +28,6 @@ msgid ""
|
||||||
"Code stopped by auto-reload. Reloading soon.\n"
|
"Code stopped by auto-reload. Reloading soon.\n"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: main.c
|
|
||||||
msgid ""
|
|
||||||
"\n"
|
|
||||||
"Invalid CIRCUITPY_PYSTACK_SIZE\n"
|
|
||||||
"\n"
|
|
||||||
"\r"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: supervisor/shared/safe_mode.c
|
#: supervisor/shared/safe_mode.c
|
||||||
msgid ""
|
msgid ""
|
||||||
"\n"
|
"\n"
|
||||||
|
@ -1252,6 +1244,10 @@ msgstr ""
|
||||||
msgid "Invalid BSSID"
|
msgid "Invalid BSSID"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: main.c
|
||||||
|
msgid "Invalid CIRCUITPY_PYSTACK_SIZE\n"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
#: shared-bindings/wifi/Radio.c
|
#: shared-bindings/wifi/Radio.c
|
||||||
msgid "Invalid MAC address"
|
msgid "Invalid MAC address"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
22
main.c
22
main.c
|
@ -134,26 +134,18 @@ static void reset_devices(void) {
|
||||||
|
|
||||||
#if MICROPY_ENABLE_PYSTACK
|
#if MICROPY_ENABLE_PYSTACK
|
||||||
STATIC supervisor_allocation *allocate_pystack(safe_mode_t safe_mode) {
|
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
|
#if CIRCUITPY_OS_GETENV && CIRCUITPY_SETTABLE_PYSTACK
|
||||||
// Fetch value if exists from settings.toml
|
if (safe_mode == SAFE_MODE_NONE) {
|
||||||
// Leaves size to build default on any failure
|
mp_int_t pystack_size = CIRCUITPY_PYSTACK_SIZE;
|
||||||
if (safe_mode == SAFE_MODE_NONE || safe_mode == SAFE_MODE_USER) {
|
|
||||||
(void)common_hal_os_getenv_int("CIRCUITPY_PYSTACK_SIZE", &pystack_size);
|
(void)common_hal_os_getenv_int("CIRCUITPY_PYSTACK_SIZE", &pystack_size);
|
||||||
// Check if value is valid
|
supervisor_allocation *pystack = allocate_memory(pystack_size >= 384 ? pystack_size : 0, false, false);
|
||||||
pystack_size = pystack_size - pystack_size % sizeof(size_t); // Round down to multiple of 4.
|
if (pystack) {
|
||||||
if ((pystack_size < 384) || (pystack_size > 900000)) {
|
return pystack;
|
||||||
serial_write_compressed(translate("\nInvalid CIRCUITPY_PYSTACK_SIZE\n\n\r"));
|
|
||||||
pystack_size = CIRCUITPY_PYSTACK_SIZE; // Reset
|
|
||||||
}
|
}
|
||||||
|
serial_write_compressed(translate("Invalid CIRCUITPY_PYSTACK_SIZE\n"));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
supervisor_allocation *pystack = allocate_memory(pystack_size, false, false);
|
return allocate_memory(CIRCUITPY_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;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue