summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-06-18 18:19:24 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-06-18 18:44:57 +0300
commit07209f8592f15435d6abbccaad5347cea2c7722e (patch)
treea009978926973dc9bb1365872f4313435df57259
parent080137961daef9a1b0fe1f37f54a820842728442 (diff)
downloadmicropython-07209f8592f15435d6abbccaad5347cea2c7722e.tar.gz
micropython-07209f8592f15435d6abbccaad5347cea2c7722e.zip
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.
-rw-r--r--cc3200/mods/modusocket.c2
-rw-r--r--cc3200/mods/modussl.c2
-rw-r--r--cc3200/mods/pybuart.c2
-rw-r--r--esp8266/modpybuart.c2
-rw-r--r--extmod/modlwip.c2
-rw-r--r--extmod/modussl.c8
-rw-r--r--extmod/modwebrepl.c2
-rw-r--r--extmod/modwebsocket.c2
-rw-r--r--extmod/vfs_fat_file.c4
-rw-r--r--extmod/virtpin.c4
-rw-r--r--py/modio.c2
-rw-r--r--py/obj.h3
-rw-r--r--py/objstringio.c4
-rw-r--r--py/stream.c7
-rw-r--r--stmhal/can.c2
-rw-r--r--stmhal/moduselect.c5
-rw-r--r--stmhal/modusocket.c2
-rw-r--r--stmhal/pybstdio.c4
-rw-r--r--stmhal/uart.c2
-rw-r--r--stmhal/usb.c4
-rw-r--r--unix/file.c4
-rw-r--r--unix/modsocket.c2
22 files changed, 38 insertions, 33 deletions
diff --git a/cc3200/mods/modusocket.c b/cc3200/mods/modusocket.c
index 43b7a840a8..360d034875 100644
--- a/cc3200/mods/modusocket.c
+++ b/cc3200/mods/modusocket.c
@@ -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,
};
diff --git a/cc3200/mods/modussl.c b/cc3200/mods/modussl.c
index 410588dd25..8342306bf7 100644
--- a/cc3200/mods/modussl.c
+++ b/cc3200/mods/modussl.c
@@ -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,
};
diff --git a/cc3200/mods/pybuart.c b/cc3200/mods/pybuart.c
index 87d89f02fb..e7b5255bdf 100644
--- a/cc3200/mods/pybuart.c
+++ b/cc3200/mods/pybuart.c
@@ -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,
};
diff --git a/esp8266/modpybuart.c b/esp8266/modpybuart.c
index 5971ffecec..0cd4fbe5a4 100644
--- a/esp8266/modpybuart.c
+++ b/esp8266/modpybuart.c
@@ -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,
};
diff --git a/extmod/modlwip.c b/extmod/modlwip.c
index cb7cc6596f..dbee7c3d1f 100644
--- a/extmod/modlwip.c
+++ b/extmod/modlwip.c
@@ -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,
};
diff --git a/extmod/modussl.c b/extmod/modussl.c
index 567033cf48..4a3e297e1e 100644
--- a/extmod/modussl.c
+++ b/extmod/modussl.c
@@ -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 {
diff --git a/extmod/modwebrepl.c b/extmod/modwebrepl.c
index 8ecab922aa..407d8fbc2c 100644
--- a/extmod/modwebrepl.c
+++ b/extmod/modwebrepl.c
@@ -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,
};
diff --git a/extmod/modwebsocket.c b/extmod/modwebsocket.c
index fc5e29a05e..468a2dc0ef 100644
--- a/extmod/modwebsocket.c
+++ b/extmod/modwebsocket.c
@@ -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,
};
diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c
index 857cd1f470..0cd61e4605 100644
--- a/extmod/vfs_fat_file.c
+++ b/extmod/vfs_fat_file.c
@@ -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,
};
diff --git a/extmod/virtpin.c b/extmod/virtpin.c
index a5817ab4d0..dbfa21d669 100644
--- a/extmod/virtpin.c
+++ b/extmod/virtpin.c
@@ -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);
}
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
diff --git a/py/obj.h b/py/obj.h
index 83f0406ce4..82abbac90d 100644
--- a/py/obj.h
+++ b/py/obj.h
@@ -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)
diff --git a/stmhal/can.c b/stmhal/can.c
index 262c487f62..88d66b6530 100644
--- a/stmhal/can.c
+++ b/stmhal/can.c
@@ -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,
};
diff --git a/stmhal/moduselect.c b/stmhal/moduselect.c
index e87478ae62..92e77e6ca8 100644
--- a/stmhal/moduselect.c
+++ b/stmhal/moduselect.c
@@ -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;
diff --git a/stmhal/modusocket.c b/stmhal/modusocket.c
index 9cc1f3314a..fbd1196446 100644
--- a/stmhal/modusocket.c
+++ b/stmhal/modusocket.c
@@ -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,
};
diff --git a/stmhal/pybstdio.c b/stmhal/pybstdio.c
index 352b7c10c2..cf31f53acf 100644
--- a/stmhal/pybstdio.c
+++ b/stmhal/pybstdio.c
@@ -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,
};
diff --git a/stmhal/uart.c b/stmhal/uart.c
index 210330e81a..cbcb7c059b 100644
--- a/stmhal/uart.c
+++ b/stmhal/uart.c
@@ -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,
};
diff --git a/stmhal/usb.c b/stmhal/usb.c
index b786fb7584..4ef6bfa500 100644
--- a/stmhal/usb.c
+++ b/stmhal/usb.c
@@ -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,
};
diff --git a/unix/file.c b/unix/file.c
index 33acdccd06..7a23572e13 100644
--- a/unix/file.c
+++ b/unix/file.c
@@ -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,
};
diff --git a/unix/modsocket.c b/unix/modsocket.c
index 8e0d86fc79..cd68b20a45 100644
--- a/unix/modsocket.c
+++ b/unix/modsocket.c
@@ -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,
};