Skip to content

Commit f4a6a57

Browse files
committed
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.
1 parent 5228854 commit f4a6a57

6 files changed

Lines changed: 11 additions & 23 deletions

File tree

py/obj.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ typedef struct _mp_stream_p_t {
238238
// are implementation-dependent, but will be exposed to user, e.g. via exception).
239239
mp_uint_t (*read)(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode);
240240
mp_uint_t (*write)(mp_obj_t obj, const void *buf, mp_uint_t size, int *errcode);
241-
mp_uint_t (*ioctl)(mp_obj_t obj, mp_uint_t request, int *errcode, ...);
241+
mp_uint_t (*ioctl)(mp_obj_t obj, mp_uint_t request, mp_uint_t arg, int *errcode);
242242
mp_uint_t is_text : 1; // default is bytes, set this for text stream
243243
} mp_stream_p_t;
244244

stmhal/can.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -418,13 +418,11 @@ STATIC const mp_map_elem_t pyb_can_locals_dict_table[] = {
418418

419419
STATIC MP_DEFINE_CONST_DICT(pyb_can_locals_dict, pyb_can_locals_dict_table);
420420

421-
mp_uint_t can_ioctl(mp_obj_t self_in, mp_uint_t request, int *errcode, ...) {
421+
mp_uint_t can_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
422422
pyb_can_obj_t *self = self_in;
423-
va_list vargs;
424-
va_start(vargs, errcode);
425423
mp_uint_t ret;
426424
if (request == MP_IOCTL_POLL) {
427-
mp_uint_t flags = va_arg(vargs, mp_uint_t);
425+
mp_uint_t flags = arg;
428426
ret = 0;
429427
if ((flags & MP_IOCTL_POLL_RD)
430428
&& ((__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, ...) {
438436
*errcode = EINVAL;
439437
ret = -1;
440438
}
441-
va_end(vargs);
442439
return ret;
443440
}
444441

stmhal/modcc3k.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -583,13 +583,11 @@ STATIC const mp_map_elem_t cc3k_socket_locals_dict_table[] = {
583583

584584
STATIC MP_DEFINE_CONST_DICT(cc3k_socket_locals_dict, cc3k_socket_locals_dict_table);
585585

586-
mp_uint_t cc3k_ioctl(mp_obj_t self_in, mp_uint_t request, int *errcode, ...) {
586+
mp_uint_t cc3k_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
587587
cc3k_socket_obj_t *self = self_in;
588-
va_list vargs;
589-
va_start(vargs, errcode);
590588
mp_uint_t ret;
591589
if (request == MP_IOCTL_POLL) {
592-
mp_uint_t flags = va_arg(vargs, mp_uint_t);
590+
mp_uint_t flags = arg;
593591
ret = 0;
594592
int fd = self->fd;
595593

@@ -642,7 +640,6 @@ mp_uint_t cc3k_ioctl(mp_obj_t self_in, mp_uint_t request, int *errcode, ...) {
642640
*errcode = EINVAL;
643641
ret = -1;
644642
}
645-
va_end(vargs);
646643
return ret;
647644
}
648645

stmhal/moduselect.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
typedef struct _poll_obj_t {
4646
mp_obj_t obj;
47-
mp_uint_t (*ioctl)(mp_obj_t obj, mp_uint_t request, int *errcode, ...);
47+
mp_uint_t (*ioctl)(mp_obj_t obj, mp_uint_t request, mp_uint_t arg, int *errcode);
4848
mp_uint_t flags;
4949
mp_uint_t flags_ret;
5050
} poll_obj_t;
@@ -85,7 +85,7 @@ STATIC mp_uint_t poll_map_poll(mp_map_t *poll_map, mp_uint_t *rwx_num) {
8585

8686
poll_obj_t *poll_obj = (poll_obj_t*)poll_map->table[i].value;
8787
int errcode;
88-
mp_int_t ret = poll_obj->ioctl(poll_obj->obj, MP_IOCTL_POLL, &errcode, poll_obj->flags);
88+
mp_int_t ret = poll_obj->ioctl(poll_obj->obj, MP_IOCTL_POLL, poll_obj->flags, &errcode);
8989
poll_obj->flags_ret = ret;
9090

9191
if (ret == -1) {

stmhal/uart.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -713,13 +713,11 @@ STATIC mp_uint_t pyb_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t
713713
}
714714
}
715715

716-
STATIC mp_uint_t pyb_uart_ioctl(mp_obj_t self_in, mp_uint_t request, int *errcode, ...) {
716+
STATIC mp_uint_t pyb_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
717717
pyb_uart_obj_t *self = self_in;
718-
va_list vargs;
719-
va_start(vargs, errcode);
720718
mp_uint_t ret;
721719
if (request == MP_IOCTL_POLL) {
722-
mp_uint_t flags = va_arg(vargs, mp_uint_t);
720+
mp_uint_t flags = arg;
723721
ret = 0;
724722
if ((flags & MP_IOCTL_POLL_RD) && uart_rx_any(self)) {
725723
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
731729
*errcode = EINVAL;
732730
ret = MP_STREAM_ERROR;
733731
}
734-
va_end(vargs);
735732
return ret;
736733
}
737734

stmhal/usb.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,10 @@ STATIC mp_uint_t pyb_usb_vcp_write(mp_obj_t self_in, const void *buf, mp_uint_t
292292
return ret;
293293
}
294294

295-
STATIC mp_uint_t pyb_usb_vcp_ioctl(mp_obj_t self_in, mp_uint_t request, int *errcode, ...) {
296-
va_list vargs;
297-
va_start(vargs, errcode);
295+
STATIC mp_uint_t pyb_usb_vcp_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
298296
mp_uint_t ret;
299297
if (request == MP_IOCTL_POLL) {
300-
mp_uint_t flags = va_arg(vargs, mp_uint_t);
298+
mp_uint_t flags = arg;
301299
ret = 0;
302300
if ((flags & MP_IOCTL_POLL_RD) && USBD_CDC_RxNum() > 0) {
303301
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
309307
*errcode = EINVAL;
310308
ret = MP_STREAM_ERROR;
311309
}
312-
va_end(vargs);
313310
return ret;
314311
}
315312

0 commit comments

Comments
 (0)