Skip to content

Commit 818d1d4

Browse files
committed
Discard pystack_size
1 parent c3b9567 commit 818d1d4

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

main.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -133,24 +133,25 @@ static void reset_devices(void) {
133133
}
134134

135135
#if MICROPY_ENABLE_PYSTACK
136-
STATIC mp_int_t fetch_pystack_size(void) {
136+
STATIC supervisor_allocation __attribute__ ((noinline)) * alloc_pystack(void) {
137137
mp_int_t pystack_size = CIRCUITPY_PYSTACK_SIZE;
138138
#if CIRCUITPY_OS_GETENV
139139
// Fetch value if exists from settings.toml
140140
// Leaves size to build default on any failure
141141
(void)common_hal_os_getenv_int("CIRCUITPY_PYSTACK_SIZE", &pystack_size);
142142
// Check if value is valid
143-
if ((CIRCUITPY_PYSTACK_SIZE != pystack_size) && ((pystack_size < 1) || (pystack_size % sizeof(size_t) != 0))) {
143+
if ((CIRCUITPY_PYSTACK_SIZE != pystack_size) && ((pystack_size < 384) || (pystack_size % sizeof(size_t) != 0))) {
144144
pystack_size = CIRCUITPY_PYSTACK_SIZE; // Reset
145145
// TODO: Find a way to inform the user about it.
146146
// Perhaps safemode? Or is it too much?
147147
}
148148
#endif
149-
return pystack_size;
149+
supervisor_allocation *pystack = allocate_memory(pystack_size, false, false);
150+
return pystack;
150151
}
151152
#endif
152153

153-
STATIC void start_mp(supervisor_allocation *heap, supervisor_allocation *pystack, mp_int_t pystack_size) {
154+
STATIC void start_mp(supervisor_allocation *heap, supervisor_allocation *pystack) {
154155
supervisor_workflow_reset();
155156

156157
// Stack limit should be less than real stack size, so we have a chance
@@ -178,7 +179,7 @@ STATIC void start_mp(supervisor_allocation *heap, supervisor_allocation *pystack
178179
readline_init0();
179180

180181
#if MICROPY_ENABLE_PYSTACK
181-
mp_pystack_init(pystack->ptr, pystack->ptr + (pystack_size / sizeof(size_t)));
182+
mp_pystack_init(pystack->ptr, pystack->ptr + (get_allocation_length(pystack) / sizeof(size_t)));
182183
#endif
183184

184185
#if MICROPY_ENABLE_GC
@@ -419,11 +420,10 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) {
419420
#endif
420421

421422
#if MICROPY_ENABLE_PYSTACK
422-
mp_int_t pystack_size = fetch_pystack_size();
423-
supervisor_allocation *pystack = allocate_memory(pystack_size, false, false);
423+
supervisor_allocation *pystack = alloc_pystack();
424424
#endif
425425
supervisor_allocation *heap = allocate_remaining_memory();
426-
start_mp(heap, pystack, pystack_size);
426+
start_mp(heap, pystack);
427427

428428
#if CIRCUITPY_USB
429429
usb_setup_with_vm();
@@ -768,11 +768,10 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
768768
// Do USB setup even if boot.py is not run.
769769

770770
#if MICROPY_ENABLE_PYSTACK
771-
mp_int_t pystack_size = fetch_pystack_size();
772-
supervisor_allocation *pystack = allocate_memory(pystack_size, false, false);
771+
supervisor_allocation *pystack = alloc_pystack();
773772
#endif
774773
supervisor_allocation *heap = allocate_remaining_memory();
775-
start_mp(heap, pystack, pystack_size);
774+
start_mp(heap, pystack);
776775

777776
#if CIRCUITPY_USB
778777
// Set up default USB values after boot.py VM starts but before running boot.py.
@@ -874,11 +873,10 @@ STATIC int run_repl(void) {
874873
stack_resize();
875874
filesystem_flush();
876875
#if MICROPY_ENABLE_PYSTACK
877-
mp_int_t pystack_size = fetch_pystack_size();
878-
supervisor_allocation *pystack = allocate_memory(pystack_size, false, false);
876+
supervisor_allocation *pystack = alloc_pystack();
879877
#endif
880878
supervisor_allocation *heap = allocate_remaining_memory();
881-
start_mp(heap, pystack, pystack_size);
879+
start_mp(heap, pystack);
882880

883881
#if CIRCUITPY_USB
884882
usb_setup_with_vm();

0 commit comments

Comments
 (0)