all: Rename mp_obj_type_t::stream_p to protocol.

It's now used for more than just stream protocol (e.g. pin protocol), so
don't use false names.
This commit is contained in:
Paul Sokolovsky 2016-06-18 18:19:24 +03:00
parent 080137961d
commit 07209f8592
22 changed files with 38 additions and 33 deletions

View File

@ -486,7 +486,7 @@ STATIC const mp_obj_type_t socket_type = {
{ &mp_type_type },
.name = MP_QSTR_socket,
.make_new = socket_make_new,
.stream_p = &socket_stream_p,
.protocol = &socket_stream_p,
.locals_dict = (mp_obj_t)&socket_locals_dict,
};

View File

@ -67,7 +67,7 @@ STATIC const mp_obj_type_t ssl_socket_type = {
.name = MP_QSTR_ussl,
.getiter = NULL,
.iternext = NULL,
.stream_p = &socket_stream_p,
.protocol = &socket_stream_p,
.locals_dict = (mp_obj_t)&socket_locals_dict,
};

View File

@ -669,6 +669,6 @@ const mp_obj_type_t pyb_uart_type = {
.make_new = pyb_uart_make_new,
.getiter = mp_identity,
.iternext = mp_stream_unbuffered_iter,
.stream_p = &uart_stream_p,
.protocol = &uart_stream_p,
.locals_dict = (mp_obj_t)&pyb_uart_locals_dict,
};

View File

@ -191,6 +191,6 @@ const mp_obj_type_t pyb_uart_type = {
.make_new = pyb_uart_make_new,
.getiter = mp_identity,
.iternext = mp_stream_unbuffered_iter,
.stream_p = &uart_stream_p,
.protocol = &uart_stream_p,
.locals_dict = (mp_obj_dict_t*)&pyb_uart_locals_dict,
};

View File

@ -1148,7 +1148,7 @@ STATIC const mp_obj_type_t lwip_socket_type = {
.name = MP_QSTR_socket,
.print = lwip_socket_print,
.make_new = lwip_socket_make_new,
.stream_p = &lwip_socket_stream_p,
.protocol = &lwip_socket_stream_p,
.locals_dict = (mp_obj_t)&lwip_socket_locals_dict,
};

View File

@ -156,7 +156,7 @@ STATIC const mp_obj_type_t ussl_socket_type = {
.print = socket_print,
.getiter = NULL,
.iternext = NULL,
.stream_p = &ussl_socket_stream_p,
.protocol = &ussl_socket_stream_p,
.locals_dict = (void*)&ussl_socket_locals_dict,
};
@ -202,7 +202,8 @@ int mp_stream_errno;
ssize_t mp_stream_posix_write(void *sock_obj, const void *buf, size_t len) {
struct _mp_obj_base_t *o = (struct _mp_obj_base_t *)sock_obj;
mp_uint_t out_sz = o->type->stream_p->write(o, buf, len, &mp_stream_errno);
const mp_stream_p_t *stream_p = o->type->protocol;
mp_uint_t out_sz = stream_p->write(o, buf, len, &mp_stream_errno);
if (out_sz == MP_STREAM_ERROR) {
return -1;
} else {
@ -212,7 +213,8 @@ ssize_t mp_stream_posix_write(void *sock_obj, const void *buf, size_t len) {
ssize_t mp_stream_posix_read(void *sock_obj, void *buf, size_t len) {
struct _mp_obj_base_t *o = (struct _mp_obj_base_t *)sock_obj;
mp_uint_t out_sz = o->type->stream_p->read(o, buf, len, &mp_stream_errno);
const mp_stream_p_t *stream_p = o->type->protocol;
mp_uint_t out_sz = stream_p->read(o, buf, len, &mp_stream_errno);
if (out_sz == MP_STREAM_ERROR) {
return -1;
} else {

View File

@ -317,7 +317,7 @@ STATIC const mp_obj_type_t webrepl_type = {
{ &mp_type_type },
.name = MP_QSTR__webrepl,
.make_new = webrepl_make_new,
.stream_p = &webrepl_stream_p,
.protocol = &webrepl_stream_p,
.locals_dict = (mp_obj_t)&webrepl_locals_dict,
};

View File

@ -298,7 +298,7 @@ STATIC const mp_obj_type_t websocket_type = {
{ &mp_type_type },
.name = MP_QSTR_websocket,
.make_new = websocket_make_new,
.stream_p = &websocket_stream_p,
.protocol = &websocket_stream_p,
.locals_dict = (mp_obj_t)&websocket_locals_dict,
};

View File

@ -259,7 +259,7 @@ const mp_obj_type_t mp_type_fileio = {
.make_new = file_obj_make_new,
.getiter = mp_identity,
.iternext = mp_stream_unbuffered_iter,
.stream_p = &fileio_stream_p,
.protocol = &fileio_stream_p,
.locals_dict = (mp_obj_dict_t*)&rawfile_locals_dict,
};
#endif
@ -278,7 +278,7 @@ const mp_obj_type_t mp_type_textio = {
.make_new = file_obj_make_new,
.getiter = mp_identity,
.iternext = mp_stream_unbuffered_iter,
.stream_p = &textio_stream_p,
.protocol = &textio_stream_p,
.locals_dict = (mp_obj_dict_t*)&rawfile_locals_dict,
};

View File

@ -28,12 +28,12 @@
int mp_virtual_pin_read(mp_obj_t pin) {
mp_obj_base_t* s = (mp_obj_base_t*)MP_OBJ_TO_PTR(pin);
mp_pin_p_t *pin_p = (mp_pin_p_t*)s->type->stream_p;
mp_pin_p_t *pin_p = (mp_pin_p_t*)s->type->protocol;
return pin_p->ioctl(pin, MP_PIN_READ, 0, NULL);
}
void mp_virtual_pin_write(mp_obj_t pin, int value) {
mp_obj_base_t* s = (mp_obj_base_t*)MP_OBJ_TO_PTR(pin);
mp_pin_p_t *pin_p = (mp_pin_p_t*)s->type->stream_p;
mp_pin_p_t *pin_p = (mp_pin_p_t*)s->type->protocol;
pin_p->ioctl(pin, MP_PIN_WRITE, value, NULL);
}

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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)

View File

@ -888,7 +888,7 @@ const mp_obj_type_t pyb_can_type = {
.name = MP_QSTR_CAN,
.print = pyb_can_print,
.make_new = pyb_can_make_new,
.stream_p = &can_stream_p,
.protocol = &can_stream_p,
.locals_dict = (mp_obj_t)&pyb_can_locals_dict,
};

View File

@ -53,12 +53,13 @@ STATIC void poll_map_add(mp_map_t *poll_map, const mp_obj_t *obj, mp_uint_t obj_
if (elem->value == NULL) {
// object not found; get its ioctl and add it to the poll list
mp_obj_type_t *type = mp_obj_get_type(obj[i]);
if (type->stream_p == NULL || type->stream_p->ioctl == NULL) {
const mp_stream_p_t *stream_p = type->protocol;
if (stream_p == NULL || stream_p->ioctl == NULL) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "object with stream.ioctl required"));
}
poll_obj_t *poll_obj = m_new_obj(poll_obj_t);
poll_obj->obj = obj[i];
poll_obj->ioctl = type->stream_p->ioctl;
poll_obj->ioctl = stream_p->ioctl;
poll_obj->flags = flags;
poll_obj->flags_ret = 0;
elem->value = poll_obj;

View File

@ -376,7 +376,7 @@ STATIC const mp_obj_type_t socket_type = {
{ &mp_type_type },
.name = MP_QSTR_socket,
.make_new = socket_make_new,
.stream_p = &socket_stream_p,
.protocol = &socket_stream_p,
.locals_dict = (mp_obj_t)&socket_locals_dict,
};

View File

@ -123,7 +123,7 @@ STATIC const mp_obj_type_t stdio_obj_type = {
.print = stdio_obj_print,
.getiter = mp_identity,
.iternext = mp_stream_unbuffered_iter,
.stream_p = &stdio_obj_stream_p,
.protocol = &stdio_obj_stream_p,
.locals_dict = (mp_obj_t)&stdio_locals_dict,
};
@ -156,7 +156,7 @@ STATIC const mp_obj_type_t stdio_buffer_obj_type = {
.print = stdio_obj_print,
.getiter = mp_identity,
.iternext = mp_stream_unbuffered_iter,
.stream_p = &stdio_buffer_obj_stream_p,
.protocol = &stdio_buffer_obj_stream_p,
.locals_dict = (mp_obj_t)&stdio_locals_dict,
};

View File

@ -933,6 +933,6 @@ const mp_obj_type_t pyb_uart_type = {
.make_new = pyb_uart_make_new,
.getiter = mp_identity,
.iternext = mp_stream_unbuffered_iter,
.stream_p = &uart_stream_p,
.protocol = &uart_stream_p,
.locals_dict = (mp_obj_t)&pyb_uart_locals_dict,
};

View File

@ -530,7 +530,7 @@ const mp_obj_type_t pyb_usb_vcp_type = {
.make_new = pyb_usb_vcp_make_new,
.getiter = mp_identity,
.iternext = mp_stream_unbuffered_iter,
.stream_p = &pyb_usb_vcp_stream_p,
.protocol = &pyb_usb_vcp_stream_p,
.locals_dict = (mp_obj_t)&pyb_usb_vcp_locals_dict,
};
@ -614,7 +614,7 @@ const mp_obj_type_t pyb_usb_hid_type = {
{ &mp_type_type },
.name = MP_QSTR_USB_HID,
.make_new = pyb_usb_hid_make_new,
.stream_p = &pyb_usb_hid_stream_p,
.protocol = &pyb_usb_hid_stream_p,
.locals_dict = (mp_obj_t)&pyb_usb_hid_locals_dict,
};

View File

@ -242,7 +242,7 @@ const mp_obj_type_t mp_type_fileio = {
.make_new = fdfile_make_new,
.getiter = mp_identity,
.iternext = mp_stream_unbuffered_iter,
.stream_p = &fileio_stream_p,
.protocol = &fileio_stream_p,
.locals_dict = (mp_obj_dict_t*)&rawfile_locals_dict,
};
#endif
@ -261,7 +261,7 @@ const mp_obj_type_t mp_type_textio = {
.make_new = fdfile_make_new,
.getiter = mp_identity,
.iternext = mp_stream_unbuffered_iter,
.stream_p = &textio_stream_p,
.protocol = &textio_stream_p,
.locals_dict = (mp_obj_dict_t*)&rawfile_locals_dict,
};

View File

@ -381,7 +381,7 @@ STATIC const mp_obj_type_t usocket_type = {
.make_new = socket_make_new,
.getiter = NULL,
.iternext = NULL,
.stream_p = &usocket_stream_p,
.protocol = &usocket_stream_p,
.locals_dict = (mp_obj_dict_t*)&usocket_locals_dict,
};