Skip to content

Commit cfedcd4

Browse files
authored
Merge pull request #7748 from microdev1/patch
Rewrite pystack logic & Update auto-reload
2 parents c935601 + e4b5b20 commit cfedcd4

File tree

3 files changed

+25
-33
lines changed

3 files changed

+25
-33
lines changed

locale/circuitpython.pot

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

31-
#: main.c
32-
msgid ""
33-
"\n"
34-
"Invalid CIRCUITPY_PYSTACK_SIZE\n"
35-
"\n"
36-
"\r"
37-
msgstr ""
38-
3931
#: supervisor/shared/safe_mode.c
4032
msgid ""
4133
"\n"
@@ -1252,6 +1244,10 @@ msgstr ""
12521244
msgid "Invalid BSSID"
12531245
msgstr ""
12541246

1247+
#: main.c
1248+
msgid "Invalid CIRCUITPY_PYSTACK_SIZE\n"
1249+
msgstr ""
1250+
12551251
#: shared-bindings/wifi/Radio.c
12561252
msgid "Invalid MAC address"
12571253
msgstr ""

main.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -134,26 +134,18 @@ static void reset_devices(void) {
134134

135135
#if MICROPY_ENABLE_PYSTACK
136136
STATIC supervisor_allocation *allocate_pystack(safe_mode_t safe_mode) {
137-
mp_int_t pystack_size = CIRCUITPY_PYSTACK_SIZE;
138137
#if CIRCUITPY_OS_GETENV && CIRCUITPY_SETTABLE_PYSTACK
139-
// Fetch value if exists from settings.toml
140-
// Leaves size to build default on any failure
141-
if (safe_mode == SAFE_MODE_NONE || safe_mode == SAFE_MODE_USER) {
138+
if (safe_mode == SAFE_MODE_NONE) {
139+
mp_int_t pystack_size = CIRCUITPY_PYSTACK_SIZE;
142140
(void)common_hal_os_getenv_int("CIRCUITPY_PYSTACK_SIZE", &pystack_size);
143-
// Check if value is valid
144-
pystack_size = pystack_size - pystack_size % sizeof(size_t); // Round down to multiple of 4.
145-
if ((pystack_size < 384) || (pystack_size > 900000)) {
146-
serial_write_compressed(translate("\nInvalid CIRCUITPY_PYSTACK_SIZE\n\n\r"));
147-
pystack_size = CIRCUITPY_PYSTACK_SIZE; // Reset
141+
supervisor_allocation *pystack = allocate_memory(pystack_size >= 384 ? pystack_size : 0, false, false);
142+
if (pystack) {
143+
return pystack;
148144
}
145+
serial_write_compressed(translate("Invalid CIRCUITPY_PYSTACK_SIZE\n"));
149146
}
150147
#endif
151-
supervisor_allocation *pystack = allocate_memory(pystack_size, false, false);
152-
if (pystack == NULL) {
153-
serial_write_compressed(translate("\nInvalid CIRCUITPY_PYSTACK_SIZE\n\n\r"));
154-
pystack = allocate_memory(CIRCUITPY_PYSTACK_SIZE, false, false);
155-
}
156-
return pystack;
148+
return allocate_memory(CIRCUITPY_PYSTACK_SIZE, false, false);
157149
}
158150
#endif
159151

supervisor/shared/reload.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,19 @@ inline bool autoreload_is_enabled() {
8282
}
8383

8484
void autoreload_trigger() {
85-
if (autoreload_enabled & !autoreload_suspended) {
86-
last_autoreload_trigger = supervisor_ticks_ms32();
87-
// Guard against the rare time that ticks is 0;
88-
if (last_autoreload_trigger == 0) {
89-
last_autoreload_trigger += 1;
90-
}
91-
// Initiate a reload of the VM immediately. Later code will pause to
92-
// wait for the autoreload to become ready. Doing the VM exit
93-
// immediately is clearer for the user.
85+
if (!autoreload_enabled || autoreload_suspended != 0) {
86+
return;
87+
}
88+
bool reload_initiated = autoreload_pending();
89+
last_autoreload_trigger = supervisor_ticks_ms32();
90+
// Guard against the rare time that ticks is 0;
91+
if (last_autoreload_trigger == 0) {
92+
last_autoreload_trigger += 1;
93+
}
94+
// Initiate a reload of the VM immediately. Later code will pause to
95+
// wait for the autoreload to become ready. Doing the VM exit
96+
// immediately is clearer for the user.
97+
if (!reload_initiated) {
9498
reload_initiate(RUN_REASON_AUTO_RELOAD);
9599
}
96100
}
@@ -111,5 +115,5 @@ bool autoreload_ready() {
111115
}
112116

113117
bool autoreload_pending(void) {
114-
return last_autoreload_trigger != 0;
118+
return last_autoreload_trigger > 0;
115119
}

0 commit comments

Comments
 (0)