From 657aef66ff3cc308155ea1519ae0c701b326033a Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 10 Apr 2016 12:37:59 +0100 Subject: [PATCH] py/stream: Simplify arg extraction logic for stream_ioctl. Saves 16 bytes of code. Also, use mp_obj_get_int_truncated to allow integers as big as a machine word to be passed as the value. --- py/stream.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/py/stream.c b/py/stream.c index 0fb57118c6..9bd086558f 100644 --- a/py/stream.c +++ b/py/stream.c @@ -416,11 +416,10 @@ STATIC mp_obj_t stream_ioctl(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t bufinfo; uintptr_t val = 0; if (n_args > 2) { - if (MP_OBJ_IS_INT(args[2])) { - val = mp_obj_get_int(args[2]); - } else { - mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_WRITE); + if (mp_get_buffer(args[2], &bufinfo, MP_BUFFER_WRITE)) { val = (uintptr_t)bufinfo.buf; + } else { + val = mp_obj_get_int_truncated(args[2]); } }