diff options
| author | Jim Mussared <jim.mussared@gmail.com> | 2023-06-26 23:53:12 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2023-07-21 18:49:03 +1000 |
| commit | 198311c780e9e05a58c710d73a22abaf8347d4ee (patch) | |
| tree | 7fa2b8b220776b8f715c8880b2b71600274a921c /shared/runtime | |
| parent | add1200343e59774d2b168cc2ff1ab8ae5660489 (diff) | |
py/stream: Add mp_stream___exit___obj that calls mp_stream_close.
There are enough places that implement __exit__ by forwarding directly to
mp_stream_close that this saves code size.
For the cases where __exit__ is a no-op, additionally make their
MP_STREAM_CLOSE ioctl handled as a no-op.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'shared/runtime')
| -rw-r--r-- | shared/runtime/sys_stdio_mphal.c | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/shared/runtime/sys_stdio_mphal.c b/shared/runtime/sys_stdio_mphal.c index ab5bdd34e..84ce5828e 100644 --- a/shared/runtime/sys_stdio_mphal.c +++ b/shared/runtime/sys_stdio_mphal.c @@ -89,17 +89,14 @@ STATIC mp_uint_t stdio_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, (void)self_in; if (request == MP_STREAM_POLL) { return mp_hal_stdio_poll(arg); + } else if (request == MP_STREAM_CLOSE) { + return 0; } else { *errcode = MP_EINVAL; return MP_STREAM_ERROR; } } -STATIC mp_obj_t stdio_obj___exit__(size_t n_args, const mp_obj_t *args) { - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(stdio_obj___exit___obj, 4, 4, stdio_obj___exit__); - STATIC const mp_rom_map_elem_t stdio_locals_dict_table[] = { #if MICROPY_PY_SYS_STDIO_BUFFER { MP_ROM_QSTR(MP_QSTR_buffer), MP_ROM_PTR(&stdio_buffer_obj) }, @@ -111,7 +108,7 @@ STATIC const mp_rom_map_elem_t stdio_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) }, { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_identity_obj) }, { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&mp_identity_obj) }, - { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&stdio_obj___exit___obj) }, + { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&mp_stream___exit___obj) }, }; STATIC MP_DEFINE_CONST_DICT(stdio_locals_dict, stdio_locals_dict_table); |
