From ac9cb9389c8d2290f9404c9d1008a7491d09f721 Mon Sep 17 00:00:00 2001 From: Isaac Benitez Date: Tue, 5 Jul 2022 22:31:33 -0700 Subject: [PATCH 1/6] Check parameters of int.from_bytes --- locale/circuitpython.pot | 8 ++++++++ py/objint.c | 24 ++++++++++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 5740e1e288..1cf3725cd2 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -2450,6 +2450,10 @@ msgstr "" msgid "byteorder is not a string" msgstr "" +#: py/objint.c +msgid "byteorder must be 'little' or 'big'" +msgstr "" + #: py/objarray.c msgid "bytes length not a multiple of item size" msgstr "" @@ -2953,6 +2957,10 @@ msgstr "" msgid "frequency is read-only for this board" msgstr "" +#: py/objint.c +msgid "from_bytes() does not implement signed=True" +msgstr "" + #: py/objdeque.c msgid "full" msgstr "" diff --git a/py/objint.c b/py/objint.c index 98178e7ffa..fa8bc7985c 100644 --- a/py/objint.c +++ b/py/objint.c @@ -480,19 +480,31 @@ MP_DEFINE_CONST_FUN_OBJ_1(int_bit_length_obj, int_bit_length); #endif // this is a classmethod -STATIC mp_obj_t int_from_bytes(size_t n_args, const mp_obj_t *args) { +STATIC mp_obj_t int_from_bytes(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // TODO: Support signed param (assumes signed=False at the moment) - (void)n_args; + + enum { ARG_signed }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_signed, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 3, pos_args + 3, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + if (args[ARG_signed].u_bool) { + mp_raise_msg(&mp_type_NotImplementedError, MP_ERROR_TEXT("from_bytes() does not implement signed=True")); + } // get the buffer info mp_buffer_info_t bufinfo; - mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_READ); + mp_get_buffer_raise(pos_args[1], &bufinfo, MP_BUFFER_READ); const byte *buf = (const byte *)bufinfo.buf; int delta = 1; - if (args[2] == MP_OBJ_NEW_QSTR(MP_QSTR_little)) { + if (pos_args[2] == MP_OBJ_NEW_QSTR(MP_QSTR_little)) { buf += bufinfo.len - 1; delta = -1; + } else if (pos_args[2] != MP_OBJ_NEW_QSTR(MP_QSTR_big)) { + mp_raise_ValueError(MP_ERROR_TEXT("byteorder must be 'little' or 'big'")); } mp_uint_t value = 0; @@ -501,7 +513,7 @@ STATIC mp_obj_t int_from_bytes(size_t n_args, const mp_obj_t *args) { #if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE if (value > (MP_SMALL_INT_MAX >> 8)) { // Result will overflow a small-int so construct a big-int - return mp_obj_int_from_bytes_impl(args[2] != MP_OBJ_NEW_QSTR(MP_QSTR_little), bufinfo.len, bufinfo.buf); + return mp_obj_int_from_bytes_impl(pos_args[2] != MP_OBJ_NEW_QSTR(MP_QSTR_little), bufinfo.len, bufinfo.buf); } #endif value = (value << 8) | *buf; @@ -509,7 +521,7 @@ STATIC mp_obj_t int_from_bytes(size_t n_args, const mp_obj_t *args) { return mp_obj_new_int_from_uint(value); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(int_from_bytes_fun_obj, 3, 4, int_from_bytes); +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(int_from_bytes_fun_obj, 3, int_from_bytes); STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(int_from_bytes_obj, MP_ROM_PTR(&int_from_bytes_fun_obj)); STATIC mp_obj_t int_to_bytes(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { From 4d3ab4f4fc714d4886ad06741b0521d170529e16 Mon Sep 17 00:00:00 2001 From: Isaac Benitez Date: Wed, 6 Jul 2022 07:22:45 -0700 Subject: [PATCH 2/6] Added non-keyword args to allowed_args --- locale/circuitpython.pot | 12 ++++-------- py/objint.c | 20 +++++++++++--------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 1cf3725cd2..07323bfc83 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -205,6 +205,10 @@ msgstr "" msgid "%q, %q, and %q must all be the same length" msgstr "" +#: py/objint.c +msgid "%q=%q" +msgstr "" + #: ports/espressif/bindings/espidf/__init__.c ports/espressif/esp_error.c #, c-format msgid "%s error 0x%x" @@ -2450,10 +2454,6 @@ msgstr "" msgid "byteorder is not a string" msgstr "" -#: py/objint.c -msgid "byteorder must be 'little' or 'big'" -msgstr "" - #: py/objarray.c msgid "bytes length not a multiple of item size" msgstr "" @@ -2957,10 +2957,6 @@ msgstr "" msgid "frequency is read-only for this board" msgstr "" -#: py/objint.c -msgid "from_bytes() does not implement signed=True" -msgstr "" - #: py/objdeque.c msgid "full" msgstr "" diff --git a/py/objint.c b/py/objint.c index fa8bc7985c..b44a2e3b4a 100644 --- a/py/objint.c +++ b/py/objint.c @@ -483,28 +483,30 @@ MP_DEFINE_CONST_FUN_OBJ_1(int_bit_length_obj, int_bit_length); STATIC mp_obj_t int_from_bytes(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // TODO: Support signed param (assumes signed=False at the moment) - enum { ARG_signed }; + enum { ARG_bytes, ARG_byteorder, ARG_signed }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_signed, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, + { MP_QSTR_bytes, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_byteorder, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_signed, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args - 3, pos_args + 3, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); if (args[ARG_signed].u_bool) { - mp_raise_msg(&mp_type_NotImplementedError, MP_ERROR_TEXT("from_bytes() does not implement signed=True")); + mp_raise_NotImplementedError_varg(MP_ERROR_TEXT("%q=%q"), MP_QSTR_signed, MP_QSTR_True); } // get the buffer info mp_buffer_info_t bufinfo; - mp_get_buffer_raise(pos_args[1], &bufinfo, MP_BUFFER_READ); + mp_get_buffer_raise(args[ARG_bytes].u_obj, &bufinfo, MP_BUFFER_READ); const byte *buf = (const byte *)bufinfo.buf; int delta = 1; - if (pos_args[2] == MP_OBJ_NEW_QSTR(MP_QSTR_little)) { + if (args[ARG_byteorder].u_obj == MP_OBJ_NEW_QSTR(MP_QSTR_little)) { buf += bufinfo.len - 1; delta = -1; - } else if (pos_args[2] != MP_OBJ_NEW_QSTR(MP_QSTR_big)) { - mp_raise_ValueError(MP_ERROR_TEXT("byteorder must be 'little' or 'big'")); + } else if (args[ARG_byteorder].u_obj != MP_OBJ_NEW_QSTR(MP_QSTR_big)) { + mp_arg_error_invalid(MP_QSTR_byteorder); } mp_uint_t value = 0; @@ -513,7 +515,7 @@ STATIC mp_obj_t int_from_bytes(size_t n_args, const mp_obj_t *pos_args, mp_map_t #if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE if (value > (MP_SMALL_INT_MAX >> 8)) { // Result will overflow a small-int so construct a big-int - return mp_obj_int_from_bytes_impl(pos_args[2] != MP_OBJ_NEW_QSTR(MP_QSTR_little), bufinfo.len, bufinfo.buf); + return mp_obj_int_from_bytes_impl(args[ARG_byteorder].u_obj != MP_OBJ_NEW_QSTR(MP_QSTR_little), bufinfo.len, bufinfo.buf); } #endif value = (value << 8) | *buf; From eb7e32da9982654f36d6005fd71ecf7b9eddc44d Mon Sep 17 00:00:00 2001 From: Isaac Benitez Date: Wed, 6 Jul 2022 09:15:18 -0700 Subject: [PATCH 3/6] Added field initializers --- py/objint.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/py/objint.c b/py/objint.c index b44a2e3b4a..7f8d08d37a 100644 --- a/py/objint.c +++ b/py/objint.c @@ -485,8 +485,8 @@ STATIC mp_obj_t int_from_bytes(size_t n_args, const mp_obj_t *pos_args, mp_map_t enum { ARG_bytes, ARG_byteorder, ARG_signed }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_bytes, MP_ARG_REQUIRED | MP_ARG_OBJ }, - { MP_QSTR_byteorder, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_bytes, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_byteorder, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_signed, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; From 51f2253cef5bbd0f856eeadd03b04504b288f81a Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 19 Jul 2022 14:07:18 -0400 Subject: [PATCH 4/6] no Russian font for SAMD21; adjust unix build warnings --- ports/atmel-samd/mpconfigport.mk | 9 ++------- ports/unix/Makefile | 4 ++-- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/ports/atmel-samd/mpconfigport.mk b/ports/atmel-samd/mpconfigport.mk index 66ebb54a6b..3ea6c44049 100644 --- a/ports/atmel-samd/mpconfigport.mk +++ b/ports/atmel-samd/mpconfigport.mk @@ -61,17 +61,12 @@ endif MICROPY_PY_ASYNC_AWAIT = 0 -# We don't have room for the fonts for terminalio for ja and ko +# We don't have room for the fonts for terminalio for certain languages, # so turn off terminalio, and if it's off and displayio is on, # force a clean build. # Note that we cannot test $(CIRCUITPY_DISPLAYIO) directly with an # ifeq, because it's not set yet. -ifeq ($(TRANSLATION), ja) -CIRCUITPY_TERMINALIO = 0 -RELEASE_NEEDS_CLEAN_BUILD = $(CIRCUITPY_DISPLAYIO) -endif - -ifeq ($(TRANSLATION), ko) +ifneq (,$(filter $(TRANSLATION),ja ko ru)) CIRCUITPY_TERMINALIO = 0 RELEASE_NEEDS_CLEAN_BUILD = $(CIRCUITPY_DISPLAYIO) endif diff --git a/ports/unix/Makefile b/ports/unix/Makefile index ae293fcb7d..c0d2bdfc63 100644 --- a/ports/unix/Makefile +++ b/ports/unix/Makefile @@ -37,8 +37,8 @@ INC += -I$(BUILD) # compiler settings CWARN = -Wall -Werror -CWARN += -Wextra -Wno-unused-parameter -Wpointer-arith -Wdouble-promotion -Wfloat-conversion -CFLAGS += $(INC) $(CWARN) -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT) -I$(VARIANT_DIR) $(CFLAGS_EXTRA) +CWARN += -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wpointer-arith -Wdouble-promotion -Wfloat-conversion +CFLAGS += $(INC) $(CWARN) -std=gnu11 -DUNIX $(CFLAGS_MOD) $(COPT) -I$(VARIANT_DIR) $(CFLAGS_EXTRA) # Debugging/Optimization ifdef DEBUG From 1cdf325c96e36084f706adacbd650f25848c8fbf Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 19 Jul 2022 16:35:23 -0400 Subject: [PATCH 5/6] shrink Feather ESP32S3 TFT --- .../boards/adafruit_feather_esp32s3_tft/mpconfigboard.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/espressif/boards/adafruit_feather_esp32s3_tft/mpconfigboard.mk b/ports/espressif/boards/adafruit_feather_esp32s3_tft/mpconfigboard.mk index b3c68b3b62..afc76833e0 100644 --- a/ports/espressif/boards/adafruit_feather_esp32s3_tft/mpconfigboard.mk +++ b/ports/espressif/boards/adafruit_feather_esp32s3_tft/mpconfigboard.mk @@ -17,4 +17,4 @@ CIRCUITPY_ESP_FLASH_MODE=dio CIRCUITPY_ESP_FLASH_FREQ=40m CIRCUITPY_ESP_FLASH_SIZE=4MB -CIRCUITPY_MODULE=wroom +CIRCUITPY_PS2IO = 0 From e8776440120cbdc89872f758b9f67029bda8a6fc Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 19 Jul 2022 17:45:29 -0400 Subject: [PATCH 6/6] use -Os on Feather ESP32-S3 TFT to shrink build --- .../boards/adafruit_feather_esp32s3_tft/mpconfigboard.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/espressif/boards/adafruit_feather_esp32s3_tft/mpconfigboard.mk b/ports/espressif/boards/adafruit_feather_esp32s3_tft/mpconfigboard.mk index db7ccf9337..dcbd2f9c7a 100644 --- a/ports/espressif/boards/adafruit_feather_esp32s3_tft/mpconfigboard.mk +++ b/ports/espressif/boards/adafruit_feather_esp32s3_tft/mpconfigboard.mk @@ -17,4 +17,4 @@ CIRCUITPY_ESP_FLASH_MODE = dio CIRCUITPY_ESP_FLASH_FREQ = 40m CIRCUITPY_ESP_FLASH_SIZE = 4MB -CIRCUITPY_PS2IO = 0 +OPTIMIZATION_FLAGS = -Os