diff options
author | Damien George <damien.p.george@gmail.com> | 2018-06-20 15:57:10 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2018-06-20 15:57:10 +1000 |
commit | 582b190764641e5049768da1ba8962c841ec014b (patch) | |
tree | f7a4dc0fc1b9e18d0195dca97dcabfd6dd10755c /py | |
parent | 2c8d130f702d07041e30d808b974b0ba2a1e51e0 (diff) |
py: Add checks for stream objects in print() and sys.print_exception().
Diffstat (limited to 'py')
-rw-r--r-- | py/modbuiltins.c | 2 | ||||
-rw-r--r-- | py/modsys.c | 3 |
2 files changed, 3 insertions, 2 deletions
diff --git a/py/modbuiltins.c b/py/modbuiltins.c index b216e021f..c169b2ee4 100644 --- a/py/modbuiltins.c +++ b/py/modbuiltins.c @@ -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); #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}; #endif diff --git a/py/modsys.c b/py/modsys.c index 609f8b454..98addfcfc 100644 --- a/py/modsys.c +++ b/py/modsys.c @@ -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 void *stream_obj = &mp_sys_stdout_obj; 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}; |