diff options
Diffstat (limited to 'py')
-rw-r--r-- | py/modio.c | 2 | ||||
-rw-r--r-- | py/obj.h | 3 | ||||
-rw-r--r-- | py/objstringio.c | 4 | ||||
-rw-r--r-- | py/stream.c | 7 |
4 files changed, 9 insertions, 7 deletions
diff --git a/py/modio.c b/py/modio.c index 2fbe6bc1e1..f8826c71a7 100644 --- a/py/modio.c +++ b/py/modio.c @@ -124,7 +124,7 @@ STATIC const mp_obj_type_t bufwriter_type = { { &mp_type_type }, .name = MP_QSTR_BufferedWriter, .make_new = bufwriter_make_new, - .stream_p = &bufwriter_stream_p, + .protocol = &bufwriter_stream_p, .locals_dict = (mp_obj_t)&bufwriter_locals_dict, }; #endif // MICROPY_PY_IO_BUFFEREDWRITER @@ -484,7 +484,8 @@ struct _mp_obj_type_t { mp_fun_1_t iternext; // may return MP_OBJ_STOP_ITERATION as an optimisation instead of raising StopIteration() (with no args) mp_buffer_p_t buffer_p; - const mp_stream_p_t *stream_p; + // One of disjoint protocols (interfaces), like mp_stream_p_t, etc. + const void *protocol; // these are for dynamically created types (classes) struct _mp_obj_tuple_t *bases_tuple; diff --git a/py/objstringio.c b/py/objstringio.c index 5fd2ca9d3b..abd4e835e8 100644 --- a/py/objstringio.c +++ b/py/objstringio.c @@ -174,7 +174,7 @@ const mp_obj_type_t mp_type_stringio = { .make_new = stringio_make_new, .getiter = mp_identity, .iternext = mp_stream_unbuffered_iter, - .stream_p = &stringio_stream_p, + .protocol = &stringio_stream_p, .locals_dict = (mp_obj_dict_t*)&stringio_locals_dict, }; @@ -186,7 +186,7 @@ const mp_obj_type_t mp_type_bytesio = { .make_new = stringio_make_new, .getiter = mp_identity, .iternext = mp_stream_unbuffered_iter, - .stream_p = &bytesio_stream_p, + .protocol = &bytesio_stream_p, .locals_dict = (mp_obj_dict_t*)&stringio_locals_dict, }; #endif diff --git a/py/stream.c b/py/stream.c index ebdbe26b45..4fcc151dca 100644 --- a/py/stream.c +++ b/py/stream.c @@ -58,10 +58,11 @@ mp_uint_t mp_stream_rw(mp_obj_t stream, void *buf_, mp_uint_t size, int *errcode mp_obj_base_t* s = (mp_obj_base_t*)MP_OBJ_TO_PTR(stream); typedef mp_uint_t (*io_func_t)(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode); io_func_t io_func; + const mp_stream_p_t *stream_p = s->type->protocol; if (flags & MP_STREAM_RW_WRITE) { - io_func = (io_func_t)s->type->stream_p->write; + io_func = (io_func_t)stream_p->write; } else { - io_func = s->type->stream_p->read; + io_func = stream_p->read; } *errcode = 0; @@ -94,7 +95,7 @@ mp_uint_t mp_stream_rw(mp_obj_t stream, void *buf_, mp_uint_t size, int *errcode const mp_stream_p_t *mp_get_stream_raise(mp_obj_t self_in, int flags) { mp_obj_base_t *o = (mp_obj_base_t*)MP_OBJ_TO_PTR(self_in); - const mp_stream_p_t *stream_p = o->type->stream_p; + const mp_stream_p_t *stream_p = o->type->protocol; if (stream_p == NULL || ((flags & MP_STREAM_OP_READ) && stream_p->read == NULL) || ((flags & MP_STREAM_OP_WRITE) && stream_p->write == NULL) |