|
122 | 122 | uint8_t value_out = 0; |
123 | 123 | #endif |
124 | 124 |
|
125 | | -#if MICROPY_ENABLE_PYSTACK |
| 125 | +#if MICROPY_ENABLE_PYSTACK && CIRCUITPY_OS_GETENV |
126 | 126 | #include "shared-module/os/__init__.h" |
127 | 127 | #endif |
128 | 128 |
|
@@ -160,9 +160,7 @@ STATIC void start_mp(supervisor_allocation *heap, supervisor_allocation *pystack |
160 | 160 | readline_init0(); |
161 | 161 |
|
162 | 162 | #if MICROPY_ENABLE_PYSTACK |
163 | | - if (pystack_size > 0) { |
164 | | - mp_pystack_init(pystack->ptr, pystack->ptr + (pystack_size / sizeof(size_t))); |
165 | | - } |
| 163 | + mp_pystack_init(pystack->ptr, pystack->ptr + (pystack_size / sizeof(size_t))); |
166 | 164 | #endif |
167 | 165 |
|
168 | 166 | #if MICROPY_ENABLE_GC |
@@ -995,19 +993,19 @@ int __attribute__((used)) main(void) { |
995 | 993 | // Leaves size to build default on any failure |
996 | 994 | (void)common_hal_os_getenv_int("CIRCUITPY_PYSTACK_SIZE", &pystack_size); |
997 | 995 | free_memory(heap); |
| 996 | + // Convert frame count to allocation size, 384 is the default for 1536 bytes |
| 997 | + pystack_size = pystack_size * sizeof(size_t); |
998 | 998 |
|
999 | | - // Check if value is valid multiple of size_t else revert |
1000 | | - if ((CIRCUITPY_PYSTACK_SIZE != pystack_size) && (pystack_size > 0) && (pystack_size % sizeof(size_t) != 0)) { |
| 999 | + // Check if value is valid |
| 1000 | + if ((CIRCUITPY_PYSTACK_SIZE != pystack_size) && (pystack_size < 1)) { |
1001 | 1001 | pystack_size = CIRCUITPY_PYSTACK_SIZE; // Reset to build default |
1002 | 1002 | // TODO: Find a way to inform the user about it. |
1003 | 1003 | // Perhaps safemode? |
1004 | 1004 | } |
1005 | 1005 |
|
1006 | 1006 | if (CIRCUITPY_PYSTACK_SIZE != pystack_size) { |
1007 | 1007 | free_memory(pystack); // Free the temporary |
1008 | | - if (pystack_size > 0) { // Allocate new if needed |
1009 | | - pystack = allocate_memory(pystack_size, false, false); |
1010 | | - } |
| 1008 | + pystack = allocate_memory(pystack_size, false, false); // Allocate new pystack |
1011 | 1009 | } |
1012 | 1010 | #endif |
1013 | 1011 | #endif |
|
0 commit comments