py: Add checks for stream objects in print() and sys.print_exception().
This commit is contained in:
parent
2c8d130f70
commit
582b190764
@ -386,7 +386,7 @@ STATIC mp_obj_t mp_builtin_print(size_t n_args, const mp_obj_t *pos_args, mp_map
|
|||||||
mp_arg_parse_all(0, NULL, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, u.args);
|
mp_arg_parse_all(0, NULL, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, u.args);
|
||||||
|
|
||||||
#if MICROPY_PY_IO && MICROPY_PY_SYS_STDFILES
|
#if MICROPY_PY_IO && MICROPY_PY_SYS_STDFILES
|
||||||
// TODO file may not be a concrete object (eg it could be a small-int)
|
mp_get_stream_raise(u.args[ARG_file].u_obj, MP_STREAM_OP_WRITE);
|
||||||
mp_print_t print = {MP_OBJ_TO_PTR(u.args[ARG_file].u_obj), mp_stream_write_adaptor};
|
mp_print_t print = {MP_OBJ_TO_PTR(u.args[ARG_file].u_obj), mp_stream_write_adaptor};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -106,7 +106,8 @@ STATIC mp_obj_t mp_sys_print_exception(size_t n_args, const mp_obj_t *args) {
|
|||||||
#if MICROPY_PY_IO && MICROPY_PY_SYS_STDFILES
|
#if MICROPY_PY_IO && MICROPY_PY_SYS_STDFILES
|
||||||
void *stream_obj = &mp_sys_stdout_obj;
|
void *stream_obj = &mp_sys_stdout_obj;
|
||||||
if (n_args > 1) {
|
if (n_args > 1) {
|
||||||
stream_obj = MP_OBJ_TO_PTR(args[1]); // XXX may fail
|
mp_get_stream_raise(args[1], MP_STREAM_OP_WRITE);
|
||||||
|
stream_obj = MP_OBJ_TO_PTR(args[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_print_t print = {stream_obj, mp_stream_write_adaptor};
|
mp_print_t print = {stream_obj, mp_stream_write_adaptor};
|
||||||
|
Loading…
Reference in New Issue
Block a user