diff options
author | Damien George <damien.p.george@gmail.com> | 2014-05-10 17:48:46 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-05-10 17:48:46 +0100 |
commit | b0edec61ac2eeb3bb5c787639ea0cecaa71ea79d (patch) | |
tree | 3361f191ccdd937cf124b7086aa372b2c0cc4bbb /stmhal/pyexec.c | |
parent | e1199ecf10fcdab85856a2b0e6557b98df15b4ca (diff) |
stmhal: Improve handling of out-of-memory in REPL.
Addresses issue #558, but it's likely that other out-of-memory errors
could crash the pyboard. Reason is that qstrs use m_new and can raise
an exception within the parser.
Diffstat (limited to 'stmhal/pyexec.c')
-rw-r--r-- | stmhal/pyexec.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/stmhal/pyexec.c b/stmhal/pyexec.c index 166f0a6d1..45928427e 100644 --- a/stmhal/pyexec.c +++ b/stmhal/pyexec.c @@ -163,7 +163,11 @@ raw_repl_reset: } mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, line.buf, line.len, 0); - parse_compile_execute(lex, MP_PARSE_FILE_INPUT, false); + if (lex == NULL) { + printf("MemoryError\n"); + } else { + parse_compile_execute(lex, MP_PARSE_FILE_INPUT, false); + } // indicate end of output with EOF character stdout_tx_str("\004"); @@ -239,7 +243,11 @@ friendly_repl_reset: } mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, vstr_str(&line), vstr_len(&line), 0); - parse_compile_execute(lex, MP_PARSE_SINGLE_INPUT, true); + if (lex == NULL) { + printf("MemoryError\n"); + } else { + parse_compile_execute(lex, MP_PARSE_SINGLE_INPUT, true); + } } } |