diff options
author | Damien George <damien.p.george@gmail.com> | 2020-04-20 23:57:13 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2020-04-27 23:58:46 +1000 |
commit | bd6ca15444b9bdb8330b45433a848838fa3f2ddb (patch) | |
tree | 20cf8947958cb558987d7e31a10e704e06f63932 /py/modio.c | |
parent | e08ca78f40bb1948acffa60c0315083acfb02227 (diff) |
py/modio: Allow uio.IOBase streams to return errno for read/write error.
This allows user code that inherits from uio.IOBase to return an errno
error code from the user readinto/write function, by returning a negative
value. Eg returning -123 means an errno of 123. This is already how the
custom ioctl works.
Diffstat (limited to 'py/modio.c')
-rw-r--r-- | py/modio.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/py/modio.c b/py/modio.c index 14f5f21d6..8a18357e2 100644 --- a/py/modio.c +++ b/py/modio.c @@ -59,12 +59,17 @@ STATIC mp_uint_t iobase_read_write(mp_obj_t obj, void *buf, mp_uint_t size, int mp_load_method(obj, qst, dest); mp_obj_array_t ar = {{&mp_type_bytearray}, BYTEARRAY_TYPECODE, 0, size, buf}; dest[2] = MP_OBJ_FROM_PTR(&ar); - mp_obj_t ret = mp_call_method_n_kw(1, 0, dest); - if (ret == mp_const_none) { + mp_obj_t ret_obj = mp_call_method_n_kw(1, 0, dest); + if (ret_obj == mp_const_none) { *errcode = MP_EAGAIN; return MP_STREAM_ERROR; + } + mp_int_t ret = mp_obj_get_int(ret_obj); + if (ret >= 0) { + return ret; } else { - return mp_obj_get_int(ret); + *errcode = -ret; + return MP_STREAM_ERROR; } } STATIC mp_uint_t iobase_read(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode) { |