Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ports/unix/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ void prompt_write_history(void) {
#if MICROPY_USE_READLINE == 1
char *home = getenv("HOME");
if (home != NULL) {
if (MP_STATE_THREAD(gc_lock_depth) != 0) {
return;
}
vstr_t vstr;
vstr_init(&vstr, 50);
vstr_printf(&vstr, "%s/.micropython.history", home);
Expand Down
5 changes: 5 additions & 0 deletions ports/unix/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ static int do_repl(void) {
mp_hal_stdio_mode_raw();

input_restart:
// If the GC is locked at this point there is no way out except a reset,
// so force the GC to be unlocked to help the user debug what went wrong.
if (MP_STATE_THREAD(gc_lock_depth) != 0) {
MP_STATE_THREAD(gc_lock_depth) = 0;
}
vstr_reset(&line);
int ret = readline(&line, mp_repl_get_ps1());
mp_parse_input_kind_t parse_input_kind = MP_PARSE_SINGLE_INPUT;
Expand Down
7 changes: 7 additions & 0 deletions tests/cmdline/repl_lock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import micropython
micropython.heap_lock()
1+1
micropython.heap_lock()
####################################################################
micropython.heap_lock()
raise SystemExit
10 changes: 10 additions & 0 deletions tests/cmdline/repl_lock.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
MicroPython \.\+ version
Use \.\+
>>> import micropython
>>> micropython.heap_lock()
>>> 1+1
2
>>> micropython.heap_lock()
>>> ####################################################################
>>> micropython.heap_lock()
>>> raise SystemExit
Loading