Skip to content

Commit 54ae7ce

Browse files
committed
Updated to requested changes
1 parent 6dc179d commit 54ae7ce

File tree

2 files changed

+48
-45
lines changed

2 files changed

+48
-45
lines changed

locale/circuitpython.pot

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,19 @@ msgid ""
2828
"Code stopped by auto-reload. Reloading soon.\n"
2929
msgstr ""
3030

31-
#: supervisor/shared/safe_mode.c
32-
msgid ""
33-
"\n"
34-
"Please file an issue with the contents of your CIRCUITPY drive at \n"
35-
"https://github.com/adafruit/circuitpython/issues\n"
36-
msgstr ""
37-
3831
#: main.c
3932
msgid ""
4033
"\n"
41-
"WARNING: Allocating pystack failed, defaulting back to build value.\n"
34+
"Invalid CIRCUITPY_PYSTACK_SIZE\n"
4235
"\n"
36+
"\r"
4337
msgstr ""
4438

45-
#: main.c
39+
#: supervisor/shared/safe_mode.c
4640
msgid ""
4741
"\n"
48-
"WARNING: Invalid CIRCUITPY_PYSTACK_SIZE, defaulting back to build value.\n"
49-
"\n"
42+
"Please file an issue with the contents of your CIRCUITPY drive at \n"
43+
"https://github.com/adafruit/circuitpython/issues\n"
5044
msgstr ""
5145

5246
#: py/obj.c

main.c

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -126,45 +126,36 @@ uint8_t value_out = 0;
126126
#include "shared-module/os/__init__.h"
127127
#endif
128128

129-
typedef struct {
130-
#if MICROPY_ENABLE_PYSTACK
131-
supervisor_allocation *pystack;
132-
#endif
133-
supervisor_allocation *heap;
134-
} vm_memory_t;
135-
136129
static void reset_devices(void) {
137130
#if CIRCUITPY_BLEIO_HCI
138131
bleio_reset();
139132
#endif
140133
}
141134

142-
STATIC vm_memory_t allocate_vm_memory(void) {
143-
vm_memory_t res;
144-
#if MICROPY_ENABLE_PYSTACK
135+
#if MICROPY_ENABLE_PYSTACK
136+
STATIC supervisor_allocation *allocate_pystack(void) {
145137
mp_int_t pystack_size = CIRCUITPY_PYSTACK_SIZE;
146-
#if CIRCUITPY_OS_GETENV
138+
#if CIRCUITPY_OS_GETENV && CIRCUITPY_SETTABLE_PYSTACK
147139
// Fetch value if exists from settings.toml
148140
// Leaves size to build default on any failure
149141
(void)common_hal_os_getenv_int("CIRCUITPY_PYSTACK_SIZE", &pystack_size);
150142
// Check if value is valid
151143
pystack_size = pystack_size - pystack_size % sizeof(size_t); // Round down to multiple of 4.
152144
if (pystack_size < 384) {
153-
serial_write_compressed(translate("\nWARNING: Invalid CIRCUITPY_PYSTACK_SIZE, defaulting back to build value.\n\n"));
145+
serial_write_compressed(translate("\nInvalid CIRCUITPY_PYSTACK_SIZE\n\n\r"));
154146
pystack_size = CIRCUITPY_PYSTACK_SIZE; // Reset
155147
}
156148
#endif
157-
res.pystack = allocate_memory(pystack_size, false, false);
158-
if (res.pystack == NULL) {
159-
serial_write_compressed(translate("\nWARNING: Allocating pystack failed, defaulting back to build value.\n\n"));
160-
res.pystack = allocate_memory(CIRCUITPY_PYSTACK_SIZE, false, false);
149+
supervisor_allocation *pystack = allocate_memory(pystack_size, false, false);
150+
if (pystack == NULL) {
151+
serial_write_compressed(translate("\nInvalid CIRCUITPY_PYSTACK_SIZE\n\n\r"));
152+
pystack = allocate_memory(CIRCUITPY_PYSTACK_SIZE, false, false);
161153
}
162-
#endif
163-
res.heap = allocate_remaining_memory();
164-
return res;
154+
return pystack;
165155
}
156+
#endif
166157

167-
STATIC void start_mp(vm_memory_t vm_memory) {
158+
STATIC void start_mp(supervisor_allocation *heap, supervisor_allocation *pystack) {
168159
supervisor_workflow_reset();
169160

170161
// Stack limit should be less than real stack size, so we have a chance
@@ -192,11 +183,11 @@ STATIC void start_mp(vm_memory_t vm_memory) {
192183
readline_init0();
193184

194185
#if MICROPY_ENABLE_PYSTACK
195-
mp_pystack_init(vm_memory.pystack->ptr, vm_memory.pystack->ptr + get_allocation_length(vm_memory.pystack) / sizeof(size_t));
186+
mp_pystack_init(pystack->ptr, pystack->ptr + get_allocation_length(pystack) / sizeof(size_t));
196187
#endif
197188

198189
#if MICROPY_ENABLE_GC
199-
gc_init(vm_memory.heap->ptr, vm_memory.heap->ptr + get_allocation_length(vm_memory.heap) / 4);
190+
gc_init(heap->ptr, heap->ptr + get_allocation_length(heap) / 4);
200191
#endif
201192
mp_init();
202193
mp_obj_list_init((mp_obj_list_t *)mp_sys_path, 0);
@@ -296,7 +287,7 @@ STATIC void count_strn(void *data, const char *str, size_t len) {
296287
*(size_t *)data += len;
297288
}
298289

299-
STATIC void cleanup_after_vm(vm_memory_t vm_memory, mp_obj_t exception) {
290+
STATIC void cleanup_after_vm(supervisor_allocation *heap, supervisor_allocation *pystack, mp_obj_t exception) {
300291
// Get the traceback of any exception from this run off the heap.
301292
// MP_OBJ_SENTINEL means "this run does not contribute to traceback storage, don't touch it"
302293
// MP_OBJ_NULL (=0) means "this run completed successfully, clear any stored traceback"
@@ -376,9 +367,9 @@ STATIC void cleanup_after_vm(vm_memory_t vm_memory, mp_obj_t exception) {
376367
// Free the heap last because other modules may reference heap memory and need to shut down.
377368
filesystem_flush();
378369
stop_mp();
379-
free_memory(vm_memory.heap);
370+
free_memory(heap);
380371
#if MICROPY_ENABLE_PYSTACK
381-
free_memory(vm_memory.pystack);
372+
free_memory(pystack);
382373
#endif
383374
supervisor_move_memory();
384375

@@ -434,8 +425,14 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) {
434425
};
435426
#endif
436427

437-
vm_memory_t vm_memory = allocate_vm_memory();
438-
start_mp(vm_memory);
428+
supervisor_allocation *pystack;
429+
#if MICROPY_ENABLE_PYSTACK
430+
pystack = allocate_pystack();
431+
#else
432+
pystack = NULL;
433+
#endif
434+
supervisor_allocation *heap = allocate_remaining_memory();
435+
start_mp(heap, pystack);
439436

440437
#if CIRCUITPY_USB
441438
usb_setup_with_vm();
@@ -483,7 +480,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) {
483480

484481

485482
// Finished executing python code. Cleanup includes filesystem flush and a board reset.
486-
cleanup_after_vm(vm_memory, _exec_result.exception);
483+
cleanup_after_vm(heap, pystack, _exec_result.exception);
487484
_exec_result.exception = NULL;
488485

489486
// If a new next code file was set, that is a reason to keep it (obviously). Stuff this into
@@ -779,8 +776,14 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
779776

780777
// Do USB setup even if boot.py is not run.
781778

782-
vm_memory_t vm_memory = allocate_vm_memory();
783-
start_mp(vm_memory);
779+
supervisor_allocation *pystack;
780+
#if MICROPY_ENABLE_PYSTACK
781+
pystack = allocate_pystack();
782+
#else
783+
pystack = NULL;
784+
#endif
785+
supervisor_allocation *heap = allocate_remaining_memory();
786+
start_mp(heap, pystack);
784787

785788
#if CIRCUITPY_USB
786789
// Set up default USB values after boot.py VM starts but before running boot.py.
@@ -866,7 +869,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
866869

867870
port_post_boot_py(true);
868871

869-
cleanup_after_vm(vm_memory, _exec_result.exception);
872+
cleanup_after_vm(heap, pystack, _exec_result.exception);
870873
_exec_result.exception = NULL;
871874

872875
port_post_boot_py(false);
@@ -881,8 +884,14 @@ STATIC int run_repl(void) {
881884
int exit_code = PYEXEC_FORCED_EXIT;
882885
stack_resize();
883886
filesystem_flush();
884-
vm_memory_t vm_memory = allocate_vm_memory();
885-
start_mp(vm_memory);
887+
supervisor_allocation *pystack;
888+
#if MICROPY_ENABLE_PYSTACK
889+
pystack = allocate_pystack();
890+
#else
891+
pystack = NULL;
892+
#endif
893+
supervisor_allocation *heap = allocate_remaining_memory();
894+
start_mp(heap, pystack);
886895

887896
#if CIRCUITPY_USB
888897
usb_setup_with_vm();
@@ -925,7 +934,7 @@ STATIC int run_repl(void) {
925934
exit_code = PYEXEC_DEEP_SLEEP;
926935
}
927936
#endif
928-
cleanup_after_vm(vm_memory, MP_OBJ_SENTINEL);
937+
cleanup_after_vm(heap, pystack, MP_OBJ_SENTINEL);
929938

930939
// Also reset bleio. The above call omits it in case workflows should continue. In this case,
931940
// we're switching straight to another VM so we want to reset.

0 commit comments

Comments
 (0)