diff options
author | Damien George <damien.p.george@gmail.com> | 2017-10-19 14:10:17 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-10-19 14:10:17 +1100 |
commit | 9725a654bdfc4ec0b7d6bc6aa3f4365f0825c5f3 (patch) | |
tree | e3c95bc281d7ed0a6c21bf70fa0a9a2005bd0bcf | |
parent | c53ca32561d19add3c2f6fae9b09d472fe52165e (diff) |
extmod/uos_dupterm: Swallow any errors from dupterm closing the stream.
Without this the board will crash when deactivating a stream that doesn't
have a close() method (eg UART) or that raises an exception within the
method (eg user-defined function).
-rw-r--r-- | extmod/uos_dupterm.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/extmod/uos_dupterm.c b/extmod/uos_dupterm.c index d4326d326..f77cff577 100644 --- a/extmod/uos_dupterm.c +++ b/extmod/uos_dupterm.c @@ -43,7 +43,13 @@ void mp_uos_deactivate(size_t dupterm_idx, const char *msg, mp_obj_t exc) { if (exc != MP_OBJ_NULL) { mp_obj_print_exception(&mp_plat_print, exc); } - mp_stream_close(term); + nlr_buf_t nlr; + if (nlr_push(&nlr) == 0) { + mp_stream_close(term); + nlr_pop(); + } else { + // Ignore any errors during stream closing + } } int mp_uos_dupterm_rx_chr(void) { @@ -61,8 +67,8 @@ int mp_uos_dupterm_rx_chr(void) { if (res == mp_const_none) { nlr_pop(); } else if (res == MP_OBJ_NEW_SMALL_INT(0)) { - mp_uos_deactivate(idx, "dupterm: EOF received, deactivating\n", MP_OBJ_NULL); nlr_pop(); + mp_uos_deactivate(idx, "dupterm: EOF received, deactivating\n", MP_OBJ_NULL); } else { mp_buffer_info_t bufinfo; mp_get_buffer_raise(MP_STATE_VM(dupterm_arr_obj), &bufinfo, MP_BUFFER_READ); |