Skip to content

Commit

Permalink
lib/utils/pyexec: Forcefully unlock the heap if locked and REPL active.
Browse files Browse the repository at this point in the history
Otherwise there is really nothing that can be done, it can't be unlocked by
the user because there is no way to allocate memory to execute the unlock.

See issue micropython#4205 and micropython#4209.
  • Loading branch information
dpgeorge committed Oct 13, 2018
1 parent 7059b4a commit f5d46a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/library/micropython.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ Functions
in a row and the lock-depth will increase, and then `heap_unlock()` must be
called the same number of times to make the heap available again.

If the REPL becomes active with the heap locked then it will be forcefully
unlocked.

.. function:: kbd_intr(chr)

Set the character that will raise a `KeyboardInterrupt` exception. By
Expand Down
6 changes: 6 additions & 0 deletions lib/utils/pyexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ int pyexec_friendly_repl(void) {
}
#endif

// 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_MEM(gc_lock_depth) != 0) {
MP_STATE_MEM(gc_lock_depth) = 0;
}

vstr_reset(&line);
int ret = readline(&line, ">>> ");
mp_parse_input_kind_t parse_input_kind = MP_PARSE_SINGLE_INPUT;
Expand Down

0 comments on commit f5d46a8

Please sign in to comment.