stream: Convert .ioctl() to take fixed number of args.

This is more efficient, as allows to use register calling convention.
If needed, a structure pointer can be passed as argument to pass more
data.
native-del-fast
Paul Sokolovsky 2014-11-17 00:16:14 +02:00
parent 5228854f0e
commit f4a6a577ab
6 changed files with 11 additions and 23 deletions

View File

@ -238,7 +238,7 @@ typedef struct _mp_stream_p_t {
// are implementation-dependent, but will be exposed to user, e.g. via exception).
mp_uint_t (*read)(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode);
mp_uint_t (*write)(mp_obj_t obj, const void *buf, mp_uint_t size, int *errcode);
mp_uint_t (*ioctl)(mp_obj_t obj, mp_uint_t request, int *errcode, ...);
mp_uint_t (*ioctl)(mp_obj_t obj, mp_uint_t request, mp_uint_t arg, int *errcode);
mp_uint_t is_text : 1; // default is bytes, set this for text stream
} mp_stream_p_t;

View File

@ -418,13 +418,11 @@ STATIC const mp_map_elem_t pyb_can_locals_dict_table[] = {
STATIC MP_DEFINE_CONST_DICT(pyb_can_locals_dict, pyb_can_locals_dict_table);
mp_uint_t can_ioctl(mp_obj_t self_in, mp_uint_t request, int *errcode, ...) {
mp_uint_t can_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
pyb_can_obj_t *self = self_in;
va_list vargs;
va_start(vargs, errcode);
mp_uint_t ret;
if (request == MP_IOCTL_POLL) {
mp_uint_t flags = va_arg(vargs, mp_uint_t);
mp_uint_t flags = arg;
ret = 0;
if ((flags & MP_IOCTL_POLL_RD)
&& ((__HAL_CAN_MSG_PENDING(&self->can, CAN_FIFO0) != 0)
@ -438,7 +436,6 @@ mp_uint_t can_ioctl(mp_obj_t self_in, mp_uint_t request, int *errcode, ...) {
*errcode = EINVAL;
ret = -1;
}
va_end(vargs);
return ret;
}

View File

@ -583,13 +583,11 @@ STATIC const mp_map_elem_t cc3k_socket_locals_dict_table[] = {
STATIC MP_DEFINE_CONST_DICT(cc3k_socket_locals_dict, cc3k_socket_locals_dict_table);
mp_uint_t cc3k_ioctl(mp_obj_t self_in, mp_uint_t request, int *errcode, ...) {
mp_uint_t cc3k_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
cc3k_socket_obj_t *self = self_in;
va_list vargs;
va_start(vargs, errcode);
mp_uint_t ret;
if (request == MP_IOCTL_POLL) {
mp_uint_t flags = va_arg(vargs, mp_uint_t);
mp_uint_t flags = arg;
ret = 0;
int fd = self->fd;
@ -642,7 +640,6 @@ mp_uint_t cc3k_ioctl(mp_obj_t self_in, mp_uint_t request, int *errcode, ...) {
*errcode = EINVAL;
ret = -1;
}
va_end(vargs);
return ret;
}

View File

@ -44,7 +44,7 @@
typedef struct _poll_obj_t {
mp_obj_t obj;
mp_uint_t (*ioctl)(mp_obj_t obj, mp_uint_t request, int *errcode, ...);
mp_uint_t (*ioctl)(mp_obj_t obj, mp_uint_t request, mp_uint_t arg, int *errcode);
mp_uint_t flags;
mp_uint_t flags_ret;
} poll_obj_t;
@ -85,7 +85,7 @@ STATIC mp_uint_t poll_map_poll(mp_map_t *poll_map, mp_uint_t *rwx_num) {
poll_obj_t *poll_obj = (poll_obj_t*)poll_map->table[i].value;
int errcode;
mp_int_t ret = poll_obj->ioctl(poll_obj->obj, MP_IOCTL_POLL, &errcode, poll_obj->flags);
mp_int_t ret = poll_obj->ioctl(poll_obj->obj, MP_IOCTL_POLL, poll_obj->flags, &errcode);
poll_obj->flags_ret = ret;
if (ret == -1) {

View File

@ -713,13 +713,11 @@ STATIC mp_uint_t pyb_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t
}
}
STATIC mp_uint_t pyb_uart_ioctl(mp_obj_t self_in, mp_uint_t request, int *errcode, ...) {
STATIC mp_uint_t pyb_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
pyb_uart_obj_t *self = self_in;
va_list vargs;
va_start(vargs, errcode);
mp_uint_t ret;
if (request == MP_IOCTL_POLL) {
mp_uint_t flags = va_arg(vargs, mp_uint_t);
mp_uint_t flags = arg;
ret = 0;
if ((flags & MP_IOCTL_POLL_RD) && uart_rx_any(self)) {
ret |= MP_IOCTL_POLL_RD;
@ -731,7 +729,6 @@ STATIC mp_uint_t pyb_uart_ioctl(mp_obj_t self_in, mp_uint_t request, int *errcod
*errcode = EINVAL;
ret = MP_STREAM_ERROR;
}
va_end(vargs);
return ret;
}

View File

@ -292,12 +292,10 @@ STATIC mp_uint_t pyb_usb_vcp_write(mp_obj_t self_in, const void *buf, mp_uint_t
return ret;
}
STATIC mp_uint_t pyb_usb_vcp_ioctl(mp_obj_t self_in, mp_uint_t request, int *errcode, ...) {
va_list vargs;
va_start(vargs, errcode);
STATIC mp_uint_t pyb_usb_vcp_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
mp_uint_t ret;
if (request == MP_IOCTL_POLL) {
mp_uint_t flags = va_arg(vargs, mp_uint_t);
mp_uint_t flags = arg;
ret = 0;
if ((flags & MP_IOCTL_POLL_RD) && USBD_CDC_RxNum() > 0) {
ret |= MP_IOCTL_POLL_RD;
@ -309,7 +307,6 @@ STATIC mp_uint_t pyb_usb_vcp_ioctl(mp_obj_t self_in, mp_uint_t request, int *err
*errcode = EINVAL;
ret = MP_STREAM_ERROR;
}
va_end(vargs);
return ret;
}