From bb0f8149df124d00dbf96b841727e34b91cf1162 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Fri, 22 Sep 2023 13:43:58 -0500 Subject: [PATCH] fix circuitpy memoryview.cast --- py/objgenerator.c | 4 +++- py/objstr.c | 7 ++++--- py/objstr.h | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/py/objgenerator.c b/py/objgenerator.c index 25cc8be569..e1873040f9 100644 --- a/py/objgenerator.c +++ b/py/objgenerator.c @@ -396,8 +396,10 @@ static mp_obj_t generatorexit(void) { #if MICROPY_CPYTHON_EXCEPTION_CHAIN MP_STATIC_ASSERT(!MICROPY_CONST_GENERATOREXIT_OBJ); mp_obj_exception_initialize0(&mp_static_GeneratorExit_obj, &mp_type_GeneratorExit); - #endif + return MP_OBJ_FROM_PTR(&mp_static_GeneratorExit_obj); + #else return MP_OBJ_FROM_PTR(&mp_const_GeneratorExit_obj); + #endif } STATIC mp_obj_t gen_instance_close(mp_obj_t self_in) { diff --git a/py/objstr.c b/py/objstr.c index 19e4ab3262..818da8c109 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -2040,7 +2040,7 @@ mp_obj_t mp_obj_bytes_fromhex(mp_obj_t type_in, mp_obj_t data) { STATIC mp_obj_t bytes_hex_as_str(size_t n_args, const mp_obj_t *args) { return mp_obj_bytes_hex(n_args, args, &mp_type_str); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bytes_hex_as_str_obj, 1, 2, bytes_hex_as_str); +MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_obj_bytes_hex_as_str_obj, 1, 2, bytes_hex_as_str); STATIC MP_DEFINE_CONST_FUN_OBJ_2(bytes_fromhex_obj, mp_obj_bytes_fromhex); STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(bytes_fromhex_classmethod_obj, MP_ROM_PTR(&bytes_fromhex_obj)); @@ -2073,7 +2073,7 @@ STATIC const mp_rom_map_elem_t array_bytearray_str_bytes_locals_table[] = { { MP_ROM_QSTR(MP_QSTR_extend), MP_ROM_PTR(&mp_obj_array_extend_obj) }, #endif #if MICROPY_PY_BUILTINS_BYTES_HEX - { MP_ROM_QSTR(MP_QSTR_hex), MP_ROM_PTR(&bytes_hex_as_str_obj) }, + { MP_ROM_QSTR(MP_QSTR_hex), MP_ROM_PTR(&mp_obj_bytes_hex_as_str_obj) }, { MP_ROM_QSTR(MP_QSTR_fromhex), MP_ROM_PTR(&bytes_fromhex_classmethod_obj) }, #endif #if MICROPY_CPYTHON_COMPAT @@ -2160,7 +2160,8 @@ MP_DEFINE_CONST_DICT_WITH_SIZE(mp_obj_array_locals_dict, TABLE_ENTRIES_ARRAY); #endif -#if MICROPY_PY_BUILTINS_MEMORYVIEW && MICROPY_PY_BUILTINS_BYTES_HEX +// CIRCUITPY: hex() but no cast() +#if MICROPY_PY_BUILTINS_MEMORYVIEW && MICROPY_PY_BUILTINS_BYTES_HEX && !MICROPY_CPYTHON_COMPAT MP_DEFINE_CONST_DICT_WITH_SIZE(mp_obj_memoryview_locals_dict, array_bytearray_str_bytes_locals_table + TABLE_ENTRIES_ARRAY, 1); // Just the "hex" entry. diff --git a/py/objstr.h b/py/objstr.h index 5d931f92ff..604f6d7886 100644 --- a/py/objstr.h +++ b/py/objstr.h @@ -119,5 +119,6 @@ extern const mp_obj_dict_t mp_obj_array_locals_dict; // CIRCUITPY MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(bytes_decode_obj); +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_obj_bytes_hex_as_str_obj); #endif // MICROPY_INCLUDED_PY_OBJSTR_H