Skip to content

Commit 2077bb9

Browse files
committed
pystack_size as multiple of sizeof size_t, no more stackless via settings.toml
1 parent 0d5b400 commit 2077bb9

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

main.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
uint8_t value_out = 0;
123123
#endif
124124

125-
#if MICROPY_ENABLE_PYSTACK
125+
#if MICROPY_ENABLE_PYSTACK && CIRCUITPY_OS_GETENV
126126
#include "shared-module/os/__init__.h"
127127
#endif
128128

@@ -160,9 +160,7 @@ STATIC void start_mp(supervisor_allocation *heap, supervisor_allocation *pystack
160160
readline_init0();
161161

162162
#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)));
166164
#endif
167165

168166
#if MICROPY_ENABLE_GC
@@ -995,19 +993,19 @@ int __attribute__((used)) main(void) {
995993
// Leaves size to build default on any failure
996994
(void)common_hal_os_getenv_int("CIRCUITPY_PYSTACK_SIZE", &pystack_size);
997995
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);
998998

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)) {
10011001
pystack_size = CIRCUITPY_PYSTACK_SIZE; // Reset to build default
10021002
// TODO: Find a way to inform the user about it.
10031003
// Perhaps safemode?
10041004
}
10051005

10061006
if (CIRCUITPY_PYSTACK_SIZE != pystack_size) {
10071007
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
10111009
}
10121010
#endif
10131011
#endif

0 commit comments

Comments
 (0)