From b0edec61ac2eeb3bb5c787639ea0cecaa71ea79d Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 10 May 2014 17:48:46 +0100 Subject: 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. --- stmhal/pyexec.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'stmhal/pyexec.c') 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); + } } } -- cgit v1.2.3