From de541cf15560ef82ba6804791b894b271dd1c044 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 25 Oct 2023 21:40:11 +0200 Subject: [PATCH] Fix pointer-ness, const-ness of compressed messages micropython puts the pointer-ness into the typedef; we can put the const-ness there too. this reduces the delta to micropython; for instance, emitinlinextensa and emitinlinethumb now match upstream. --- devices/ble_hci/common-hal/_bleio/att.c | 2 +- ports/espressif/common-hal/espidf/__init__.c | 2 +- ports/espressif/common-hal/wifi/Monitor.c | 2 +- py/compile.c | 2 +- py/emitinlinethumb.c | 3 +- py/emitinlinextensa.c | 3 +- py/maketranslationdata.py | 2 +- py/moderrno.c | 2 +- py/mpprint.c | 6 +-- py/mpprint.h | 1 - py/obj.c | 8 ++-- py/obj.h | 6 +-- py/objexcept.c | 6 +-- py/qstr.c | 2 +- py/qstr.h | 2 +- py/runtime.c | 38 +++++++-------- py/runtime.h | 48 +++++++++---------- shared-bindings/_bleio/__init__.c | 6 +-- shared-bindings/_bleio/__init__.h | 6 +-- shared-bindings/memorymonitor/__init__.c | 2 +- shared-bindings/memorymonitor/__init__.h | 2 +- shared-bindings/usb/core/__init__.c | 2 +- shared-bindings/usb/core/__init__.h | 2 +- shared-module/os/getenv.c | 4 +- shared-module/sdcardio/SDCard.c | 12 ++--- supervisor/shared/safe_mode.c | 2 +- .../shared/translate/compressed_string.h | 10 ++-- supervisor/shared/translate/translate.c | 6 +-- supervisor/shared/translate/translate.h | 10 +++- supervisor/shared/translate/translate_impl.h | 6 +-- 30 files changed, 104 insertions(+), 101 deletions(-) diff --git a/devices/ble_hci/common-hal/_bleio/att.c b/devices/ble_hci/common-hal/_bleio/att.c index 6a95126864..05099ec718 100644 --- a/devices/ble_hci/common-hal/_bleio/att.c +++ b/devices/ble_hci/common-hal/_bleio/att.c @@ -1722,7 +1722,7 @@ void att_process_data(uint16_t conn_handle, uint8_t dlen, uint8_t data[]) { // FIX Do we need all of these? static void check_att_err(uint8_t err) { - const mp_rom_error_text_t *msg = NULL; + mp_rom_error_text_t msg = NULL; switch (err) { case 0: return; diff --git a/ports/espressif/common-hal/espidf/__init__.c b/ports/espressif/common-hal/espidf/__init__.c index 4d1a24c9ea..377faab166 100644 --- a/ports/espressif/common-hal/espidf/__init__.c +++ b/ports/espressif/common-hal/espidf/__init__.c @@ -122,7 +122,7 @@ intptr_t common_hal_espidf_get_psram_end(void) { } void raise_esp_error(esp_err_t err) { - const mp_rom_error_text_t *msg = NULL; + mp_rom_error_text_t msg = NULL; const mp_obj_type_t *exception_type = &mp_type_espidf_IDFError; switch (err) { case ESP_FAIL: diff --git a/ports/espressif/common-hal/wifi/Monitor.c b/ports/espressif/common-hal/wifi/Monitor.c index ff3700af57..f4d3a9f135 100644 --- a/ports/espressif/common-hal/wifi/Monitor.c +++ b/ports/espressif/common-hal/wifi/Monitor.c @@ -78,7 +78,7 @@ static void wifi_monitor_cb(void *recv_buf, wifi_promiscuous_pkt_type_t type) { } void common_hal_wifi_monitor_construct(wifi_monitor_obj_t *self, uint8_t channel, size_t queue) { - const mp_rom_error_text_t *monitor_mode_init_error = translate("monitor init failed"); + mp_rom_error_text_t monitor_mode_init_error = translate("monitor init failed"); self->queue = xQueueCreate(queue, sizeof(monitor_packet_t)); if (!self->queue) { diff --git a/py/compile.c b/py/compile.c index e233d846e3..4752d508c8 100644 --- a/py/compile.c +++ b/py/compile.c @@ -255,7 +255,7 @@ STATIC void compile_error_set_line(compiler_t *comp, mp_parse_node_t pn) { } } -STATIC void compile_syntax_error(compiler_t *comp, mp_parse_node_t pn, const mp_rom_error_text_t *msg) { +STATIC void compile_syntax_error(compiler_t *comp, mp_parse_node_t pn, mp_rom_error_text_t msg) { // only register the error if there has been no other error if (comp->compile_error == MP_OBJ_NULL) { comp->compile_error = mp_obj_new_exception_msg(&mp_type_SyntaxError, msg); diff --git a/py/emitinlinethumb.c b/py/emitinlinethumb.c index ea19b31686..29487f1048 100644 --- a/py/emitinlinethumb.c +++ b/py/emitinlinethumb.c @@ -74,8 +74,7 @@ static inline bool emit_inline_thumb_allow_float(emit_inline_asm_t *emit) { #endif -// CIRCUITPY-CHANGE -STATIC void emit_inline_thumb_error_msg(emit_inline_asm_t *emit, const mp_rom_error_text_t *msg) { +STATIC void emit_inline_thumb_error_msg(emit_inline_asm_t *emit, mp_rom_error_text_t msg) { *emit->error_slot = mp_obj_new_exception_msg(&mp_type_SyntaxError, msg); } diff --git a/py/emitinlinextensa.c b/py/emitinlinextensa.c index 72f59e515e..5dac2ae390 100644 --- a/py/emitinlinextensa.c +++ b/py/emitinlinextensa.c @@ -43,8 +43,7 @@ struct _emit_inline_asm_t { qstr *label_lookup; }; -// CIRCUITPY-CHANGE -STATIC void emit_inline_xtensa_error_msg(emit_inline_asm_t *emit, const mp_rom_error_text_t *msg) { +STATIC void emit_inline_xtensa_error_msg(emit_inline_asm_t *emit, mp_rom_error_text_t msg) { *emit->error_slot = mp_obj_new_exception_msg(&mp_type_SyntaxError, msg); } diff --git a/py/maketranslationdata.py b/py/maketranslationdata.py index 3d6ef03d31..8676aab1a5 100644 --- a/py/maketranslationdata.py +++ b/py/maketranslationdata.py @@ -595,7 +595,7 @@ def output_translation_data(encoding_table, i18ns, out): decompressed = decompressed.replace(c, C_ESCAPES[c]) formatted = ["{:d}".format(x) for x in compressed] out.write( - "const mp_rom_error_text_t translation{} = {{ .data = {}, .tail = {{ {} }} }}; // {}\n".format( + "const struct compressed_string translation{} = {{ .data = {}, .tail = {{ {} }} }}; // {}\n".format( i, formatted[0], ", ".join(formatted[1:]), original, decompressed ) ) diff --git a/py/moderrno.c b/py/moderrno.c index 07fa31e005..e8057ff002 100644 --- a/py/moderrno.c +++ b/py/moderrno.c @@ -127,7 +127,7 @@ const char *mp_common_errno_to_str(mp_obj_t errno_val, char *buf, size_t len) { return NULL; } - const mp_rom_error_text_t *desc = NULL; + mp_rom_error_text_t desc = NULL; switch (MP_OBJ_SMALL_INT_VALUE(errno_val)) { case EPERM: desc = MP_ERROR_TEXT("Operation not permitted"); diff --git a/py/mpprint.c b/py/mpprint.c index cb55f150cb..36b036d83f 100644 --- a/py/mpprint.c +++ b/py/mpprint.c @@ -496,7 +496,7 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args) { break; } case 'S': { - mp_rom_error_text_t *arg = va_arg(args, mp_rom_error_text_t *); + mp_rom_error_text_t arg = va_arg(args, mp_rom_error_text_t ); size_t len_with_nul = decompress_length(arg); size_t len = len_with_nul - 1; char str[len_with_nul]; @@ -593,7 +593,7 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args) { return chrs; } -int mp_cprintf(const mp_print_t *print, const mp_rom_error_text_t *compressed_fmt, ...) { +int mp_cprintf(const mp_print_t *print, mp_rom_error_text_t compressed_fmt, ...) { va_list ap; va_start(ap, compressed_fmt); int ret = mp_vcprintf(print, compressed_fmt, ap); @@ -601,7 +601,7 @@ int mp_cprintf(const mp_print_t *print, const mp_rom_error_text_t *compressed_fm return ret; } -int mp_vcprintf(const mp_print_t *print, const mp_rom_error_text_t *compressed_fmt, va_list args) { +int mp_vcprintf(const mp_print_t *print, mp_rom_error_text_t compressed_fmt, va_list args) { char fmt[decompress_length(compressed_fmt)]; // TODO: Optimise this to format-while-decompressing (and not require the temp stack space). decompress(compressed_fmt, fmt); diff --git a/py/mpprint.h b/py/mpprint.h index f5e61e1727..2d7e80b6f5 100644 --- a/py/mpprint.h +++ b/py/mpprint.h @@ -27,7 +27,6 @@ #define MICROPY_INCLUDED_PY_MPPRINT_H #include "py/mpconfig.h" -#include "py/misc.h" #define PF_FLAG_LEFT_ADJUST (0x001) #define PF_FLAG_SHOW_SIGN (0x002) diff --git a/py/obj.c b/py/obj.c index fa5f97a2e4..0d477613b3 100644 --- a/py/obj.c +++ b/py/obj.c @@ -147,7 +147,7 @@ void mp_obj_print(mp_obj_t o_in, mp_print_kind_t kind) { static void mp_obj_print_inner_exception(const mp_print_t *print, mp_obj_t self_in, mp_int_t limit) { #if MICROPY_CPYTHON_EXCEPTION_CHAIN mp_obj_exception_t *self = mp_obj_exception_get_native(self_in); - const mp_rom_error_text_t *msg = MP_ERROR_TEXT("During handling of the above exception, another exception occurred:"); + mp_rom_error_text_t msg = MP_ERROR_TEXT("During handling of the above exception, another exception occurred:"); mp_obj_exception_t *inner = NULL; if (self->cause) { msg = MP_ERROR_TEXT("The above exception was the direct cause of the following exception:"); @@ -177,11 +177,11 @@ void mp_obj_print_exception_with_limit(const mp_print_t *print, mp_obj_t exc, mp if (n > 0) { assert(n % 3 == 0); #if MICROPY_ENABLE_SOURCE_LINE - const mp_rom_error_text_t *frame = MP_ERROR_TEXT(" File \"%q\", line %d"); + mp_rom_error_text_t frame = MP_ERROR_TEXT(" File \"%q\", line %d"); #else - const mp_rom_error_text_t *frame = MP_ERROR_TEXT(" File \"%q\""); + mp_rom_error_text_t frame = MP_ERROR_TEXT(" File \"%q\""); #endif - const mp_rom_error_text_t *block_fmt = MP_ERROR_TEXT(", in %q\n"); + mp_rom_error_text_t block_fmt = MP_ERROR_TEXT(", in %q\n"); // Set traceback formatting // Default: Print full traceback diff --git a/py/obj.h b/py/obj.h index 1b1e8e5a83..12d9259d10 100644 --- a/py/obj.h +++ b/py/obj.h @@ -1034,12 +1034,12 @@ mp_obj_t mp_obj_new_exception_args(const mp_obj_type_t *exc_type, size_t n_args, #define mp_obj_new_exception_msg_varg(exc_type, ...) mp_obj_new_exception(exc_type) #else // CIRCUITPY-CHANGE -mp_obj_t mp_obj_new_exception_msg(const mp_obj_type_t *exc_type, const mp_rom_error_text_t *msg); -mp_obj_t mp_obj_new_exception_msg_varg(const mp_obj_type_t *exc_type, const mp_rom_error_text_t *fmt, ...); // counts args by number of % symbols in fmt, excluding %%; can only handle void* sizes (ie no float/double!) +mp_obj_t mp_obj_new_exception_msg(const mp_obj_type_t *exc_type, mp_rom_error_text_t msg); +mp_obj_t mp_obj_new_exception_msg_varg(const mp_obj_type_t *exc_type, mp_rom_error_text_t fmt, ...); // counts args by number of % symbols in fmt, excluding %%; can only handle void* sizes (ie no float/double!) #endif #ifdef va_start // CIRCUITPY-CHANGE -mp_obj_t mp_obj_new_exception_msg_vlist(const mp_obj_type_t *exc_type, const mp_rom_error_text_t *fmt, va_list arg); // same fmt restrictions as above +mp_obj_t mp_obj_new_exception_msg_vlist(const mp_obj_type_t *exc_type, mp_rom_error_text_t fmt, va_list arg); // same fmt restrictions as above #endif mp_obj_t mp_obj_new_gen_wrap(mp_obj_t fun); mp_obj_t mp_obj_new_closure(mp_obj_t fun, size_t n_closed, const mp_obj_t *closed); diff --git a/py/objexcept.c b/py/objexcept.c index c13e8d526c..e9d5dc814f 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -479,7 +479,7 @@ mp_obj_t mp_obj_new_exception_args(const mp_obj_type_t *exc_type, size_t n_args, } #if MICROPY_ERROR_REPORTING != MICROPY_ERROR_REPORTING_NONE -mp_obj_t mp_obj_new_exception_msg(const mp_obj_type_t *exc_type, const mp_rom_error_text_t *msg) { +mp_obj_t mp_obj_new_exception_msg(const mp_obj_type_t *exc_type, mp_rom_error_text_t msg) { // CIRCUITPY-CHANGE: is different here and for many lines below. return mp_obj_new_exception_msg_varg(exc_type, msg); } @@ -517,7 +517,7 @@ STATIC void exc_add_strn(void *data, const char *str, size_t len) { pr->len += len; } -mp_obj_t mp_obj_new_exception_msg_varg(const mp_obj_type_t *exc_type, const mp_rom_error_text_t *fmt, ...) { +mp_obj_t mp_obj_new_exception_msg_varg(const mp_obj_type_t *exc_type, mp_rom_error_text_t fmt, ...) { va_list args; va_start(args, fmt); mp_obj_t exc = mp_obj_new_exception_msg_vlist(exc_type, fmt, args); @@ -525,7 +525,7 @@ mp_obj_t mp_obj_new_exception_msg_varg(const mp_obj_type_t *exc_type, const mp_r return exc; } -mp_obj_t mp_obj_new_exception_msg_vlist(const mp_obj_type_t *exc_type, const mp_rom_error_text_t *fmt, va_list ap) { +mp_obj_t mp_obj_new_exception_msg_vlist(const mp_obj_type_t *exc_type, mp_rom_error_text_t fmt, va_list ap) { assert(fmt != NULL); // Check that the given type is an exception type diff --git a/py/qstr.c b/py/qstr.c index 420774e353..c17a0016c6 100644 --- a/py/qstr.c +++ b/py/qstr.c @@ -370,7 +370,7 @@ STATIC const byte *find_uncompressed_string(uint8_t n) { // Given a compressed string in src, decompresses it into dst. // dst must be large enough (use MP_MAX_UNCOMPRESSED_TEXT_LEN+1). -void mp_decompress_rom_string(byte *dst, const mp_rom_error_text_t src_chr) { +void mp_decompress_rom_string(byte *dst, mp_rom_error_text_t src_chr) { // Skip past the 0xff marker. const byte *src = (byte *)src_chr + 1; // Need to add spaces around compressed words, except for the first (i.e. transition from 1<->2). diff --git a/py/qstr.h b/py/qstr.h index 3d4ec1fcd4..c031fb919d 100644 --- a/py/qstr.h +++ b/py/qstr.h @@ -97,7 +97,7 @@ void qstr_pool_info(size_t *n_pool, size_t *n_qstr, size_t *n_str_data_bytes, si void qstr_dump_data(void); #if MICROPY_ROM_TEXT_COMPRESSION -void mp_decompress_rom_string(byte *dst, const mp_rom_error_text_t src); +void mp_decompress_rom_string(byte *dst, mp_rom_error_text_t src); #define MP_IS_COMPRESSED_ROM_STRING(s) (*(byte *)(s) == 0xff) #endif diff --git a/py/runtime.c b/py/runtime.c index 4a842e1864..36ab52f461 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -1744,7 +1744,7 @@ NORETURN MP_COLD void mp_raise_NotImplementedError_no_msg(void) { #else -NORETURN MP_COLD void mp_raise_msg(const mp_obj_type_t *exc_type, const mp_rom_error_text_t *msg) { +NORETURN MP_COLD void mp_raise_msg(const mp_obj_type_t *exc_type, mp_rom_error_text_t msg) { if (msg == NULL) { nlr_raise(mp_obj_new_exception(exc_type)); } else { @@ -1752,12 +1752,12 @@ NORETURN MP_COLD void mp_raise_msg(const mp_obj_type_t *exc_type, const mp_rom_e } } -NORETURN MP_COLD void mp_raise_msg_vlist(const mp_obj_type_t *exc_type, const mp_rom_error_text_t *fmt, va_list argptr) { +NORETURN MP_COLD void mp_raise_msg_vlist(const mp_obj_type_t *exc_type, mp_rom_error_text_t fmt, va_list argptr) { mp_obj_t exception = mp_obj_new_exception_msg_vlist(exc_type, fmt, argptr); nlr_raise(exception); } -NORETURN MP_COLD void mp_raise_msg_varg(const mp_obj_type_t *exc_type, const mp_rom_error_text_t *fmt, ...) { +NORETURN MP_COLD void mp_raise_msg_varg(const mp_obj_type_t *exc_type, mp_rom_error_text_t fmt, ...) { va_list argptr; va_start(argptr, fmt); mp_raise_msg_vlist(exc_type, fmt, argptr); @@ -1772,59 +1772,59 @@ NORETURN MP_COLD void mp_raise_msg_str(const mp_obj_type_t *exc_type, const char } } -NORETURN MP_COLD void mp_raise_AttributeError(const mp_rom_error_text_t *msg) { +NORETURN MP_COLD void mp_raise_AttributeError(mp_rom_error_text_t msg) { mp_raise_msg(&mp_type_AttributeError, msg); } -NORETURN MP_COLD void mp_raise_RuntimeError(const mp_rom_error_text_t *msg) { +NORETURN MP_COLD void mp_raise_RuntimeError(mp_rom_error_text_t msg) { mp_raise_msg(&mp_type_RuntimeError, msg); } -NORETURN MP_COLD void mp_raise_RuntimeError_varg(const mp_rom_error_text_t *fmt, ...) { +NORETURN MP_COLD void mp_raise_RuntimeError_varg(mp_rom_error_text_t fmt, ...) { va_list argptr; va_start(argptr, fmt); mp_raise_msg_vlist(&mp_type_RuntimeError, fmt, argptr); va_end(argptr); } -NORETURN MP_COLD void mp_raise_ImportError(const mp_rom_error_text_t *msg) { +NORETURN MP_COLD void mp_raise_ImportError(mp_rom_error_text_t msg) { mp_raise_msg(&mp_type_ImportError, msg); } -NORETURN MP_COLD void mp_raise_IndexError(const mp_rom_error_text_t *msg) { +NORETURN MP_COLD void mp_raise_IndexError(mp_rom_error_text_t msg) { mp_raise_msg(&mp_type_IndexError, msg); } -NORETURN MP_COLD void mp_raise_IndexError_varg(const mp_rom_error_text_t *fmt, ...) { +NORETURN MP_COLD void mp_raise_IndexError_varg(mp_rom_error_text_t fmt, ...) { va_list argptr; va_start(argptr, fmt); mp_raise_msg_vlist(&mp_type_IndexError, fmt, argptr); va_end(argptr); } -NORETURN MP_COLD void mp_raise_ValueError(const mp_rom_error_text_t *msg) { +NORETURN MP_COLD void mp_raise_ValueError(mp_rom_error_text_t msg) { mp_raise_msg(&mp_type_ValueError, msg); } -NORETURN MP_COLD void mp_raise_ValueError_varg(const mp_rom_error_text_t *fmt, ...) { +NORETURN MP_COLD void mp_raise_ValueError_varg(mp_rom_error_text_t fmt, ...) { va_list argptr; va_start(argptr, fmt); mp_raise_msg_vlist(&mp_type_ValueError, fmt, argptr); va_end(argptr); } -NORETURN MP_COLD void mp_raise_TypeError(const mp_rom_error_text_t *msg) { +NORETURN MP_COLD void mp_raise_TypeError(mp_rom_error_text_t msg) { mp_raise_msg(&mp_type_TypeError, msg); } -NORETURN MP_COLD void mp_raise_TypeError_varg(const mp_rom_error_text_t *fmt, ...) { +NORETURN MP_COLD void mp_raise_TypeError_varg(mp_rom_error_text_t fmt, ...) { va_list argptr; va_start(argptr, fmt); mp_raise_msg_vlist(&mp_type_TypeError, fmt, argptr); va_end(argptr); } -NORETURN MP_COLD void mp_raise_OSError_msg(const mp_rom_error_text_t *msg) { +NORETURN MP_COLD void mp_raise_OSError_msg(mp_rom_error_text_t msg) { mp_raise_msg(&mp_type_OSError, msg); } @@ -1836,14 +1836,14 @@ NORETURN MP_COLD void mp_raise_OSError_errno_str(int errno_, mp_obj_t str) { nlr_raise(mp_obj_new_exception_args(&mp_type_OSError, 2, args)); } -NORETURN MP_COLD void mp_raise_OSError_msg_varg(const mp_rom_error_text_t *fmt, ...) { +NORETURN MP_COLD void mp_raise_OSError_msg_varg(mp_rom_error_text_t fmt, ...) { va_list argptr; va_start(argptr, fmt); mp_raise_msg_vlist(&mp_type_OSError, fmt, argptr); va_end(argptr); } -NORETURN MP_COLD void mp_raise_ConnectionError(const mp_rom_error_text_t *msg) { +NORETURN MP_COLD void mp_raise_ConnectionError(mp_rom_error_text_t msg) { mp_raise_msg(&mp_type_ConnectionError, msg); } @@ -1851,11 +1851,11 @@ NORETURN MP_COLD void mp_raise_BrokenPipeError(void) { mp_raise_type_arg(&mp_type_BrokenPipeError, MP_OBJ_NEW_SMALL_INT(MP_EPIPE)); } -NORETURN MP_COLD void mp_raise_NotImplementedError(const mp_rom_error_text_t *msg) { +NORETURN MP_COLD void mp_raise_NotImplementedError(mp_rom_error_text_t msg) { mp_raise_msg(&mp_type_NotImplementedError, msg); } -NORETURN MP_COLD void mp_raise_NotImplementedError_varg(const mp_rom_error_text_t *fmt, ...) { +NORETURN MP_COLD void mp_raise_NotImplementedError_varg(mp_rom_error_text_t fmt, ...) { va_list argptr; va_start(argptr, fmt); mp_raise_msg_vlist(&mp_type_NotImplementedError, fmt, argptr); @@ -1863,7 +1863,7 @@ NORETURN MP_COLD void mp_raise_NotImplementedError_varg(const mp_rom_error_text_ } -NORETURN MP_COLD void mp_raise_OverflowError_varg(const mp_rom_error_text_t *fmt, ...) { +NORETURN MP_COLD void mp_raise_OverflowError_varg(mp_rom_error_text_t fmt, ...) { va_list argptr; va_start(argptr, fmt); mp_raise_msg_vlist(&mp_type_OverflowError, fmt, argptr); diff --git a/py/runtime.h b/py/runtime.h index b6a3e48fb6..c197b3d2cd 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -242,44 +242,44 @@ NORETURN void mp_raise_NotImplementedError_no_msg(void); #define mp_raise_NotImplementedError(msg) mp_raise_NotImplementedError_no_msg() #else #define mp_raise_type(exc_type) mp_raise_msg(exc_type, NULL) -NORETURN void mp_raise_msg(const mp_obj_type_t *exc_type, const mp_rom_error_text_t *msg); -NORETURN void mp_raise_msg_varg(const mp_obj_type_t *exc_type, const mp_rom_error_text_t *fmt, ...); -NORETURN void mp_raise_ValueError(const mp_rom_error_text_t *msg); -NORETURN void mp_raise_TypeError(const mp_rom_error_text_t *msg); -NORETURN void mp_raise_NotImplementedError(const mp_rom_error_text_t *msg); +NORETURN void mp_raise_msg(const mp_obj_type_t *exc_type, mp_rom_error_text_t msg); +NORETURN void mp_raise_msg_varg(const mp_obj_type_t *exc_type, mp_rom_error_text_t fmt, ...); +NORETURN void mp_raise_ValueError(mp_rom_error_text_t msg); +NORETURN void mp_raise_TypeError(mp_rom_error_text_t msg); +NORETURN void mp_raise_NotImplementedError(mp_rom_error_text_t msg); #endif NORETURN void mp_raise_type_arg(const mp_obj_type_t *exc_type, mp_obj_t arg); -NORETURN void mp_raise_msg(const mp_obj_type_t *exc_type, const mp_rom_error_text_t *msg); -NORETURN void mp_raise_msg_varg(const mp_obj_type_t *exc_type, const mp_rom_error_text_t *fmt +NORETURN void mp_raise_msg(const mp_obj_type_t *exc_type, mp_rom_error_text_t msg); +NORETURN void mp_raise_msg_varg(const mp_obj_type_t *exc_type, mp_rom_error_text_t fmt , ...); -NORETURN void mp_raise_msg_vlist(const mp_obj_type_t *exc_type, const mp_rom_error_text_t *fmt, va_list argptr); +NORETURN void mp_raise_msg_vlist(const mp_obj_type_t *exc_type, mp_rom_error_text_t fmt, va_list argptr); // Only use this string version in native mpy files. Otherwise, use the compressed string version. NORETURN void mp_raise_msg_str(const mp_obj_type_t *exc_type, const char *msg); -NORETURN void mp_raise_AttributeError(const mp_rom_error_text_t *msg); +NORETURN void mp_raise_AttributeError(mp_rom_error_text_t msg); NORETURN void mp_raise_BrokenPipeError(void); -NORETURN void mp_raise_ConnectionError(const mp_rom_error_text_t *msg); -NORETURN void mp_raise_ImportError(const mp_rom_error_text_t *msg); -NORETURN void mp_raise_IndexError(const mp_rom_error_text_t *msg); -NORETURN void mp_raise_IndexError_varg(const mp_rom_error_text_t *msg, ...); -NORETURN void mp_raise_NotImplementedError(const mp_rom_error_text_t *msg); -NORETURN void mp_raise_NotImplementedError_varg(const mp_rom_error_text_t *fmt, ...); +NORETURN void mp_raise_ConnectionError(mp_rom_error_text_t msg); +NORETURN void mp_raise_ImportError(mp_rom_error_text_t msg); +NORETURN void mp_raise_IndexError(mp_rom_error_text_t msg); +NORETURN void mp_raise_IndexError_varg(mp_rom_error_text_t msg, ...); +NORETURN void mp_raise_NotImplementedError(mp_rom_error_text_t msg); +NORETURN void mp_raise_NotImplementedError_varg(mp_rom_error_text_t fmt, ...); NORETURN void mp_raise_OSError_errno_str(int errno_, mp_obj_t str); NORETURN void mp_raise_OSError(int errno_); -NORETURN void mp_raise_OSError_msg(const mp_rom_error_text_t *msg); -NORETURN void mp_raise_OSError_msg_varg(const mp_rom_error_text_t *fmt, ...); +NORETURN void mp_raise_OSError_msg(mp_rom_error_text_t msg); +NORETURN void mp_raise_OSError_msg_varg(mp_rom_error_text_t fmt, ...); NORETURN void mp_raise_OSError_with_filename(int errno_, const char *filename); -NORETURN void mp_raise_OverflowError_varg(const mp_rom_error_text_t *fmt, ...); +NORETURN void mp_raise_OverflowError_varg(mp_rom_error_text_t fmt, ...); NORETURN void mp_raise_recursion_depth(void); -NORETURN void mp_raise_RuntimeError(const mp_rom_error_text_t *msg); -NORETURN void mp_raise_RuntimeError_varg(const mp_rom_error_text_t *fmt, ...); +NORETURN void mp_raise_RuntimeError(mp_rom_error_text_t msg); +NORETURN void mp_raise_RuntimeError_varg(mp_rom_error_text_t fmt, ...); NORETURN void mp_raise_StopIteration(mp_obj_t arg); -NORETURN void mp_raise_TypeError(const mp_rom_error_text_t *msg); -NORETURN void mp_raise_TypeError_varg(const mp_rom_error_text_t *fmt, ...); +NORETURN void mp_raise_TypeError(mp_rom_error_text_t msg); +NORETURN void mp_raise_TypeError_varg(mp_rom_error_text_t fmt, ...); NORETURN void mp_raise_TypeError_int_conversion(mp_const_obj_t arg); -NORETURN void mp_raise_ValueError(const mp_rom_error_text_t *msg); -NORETURN void mp_raise_ValueError_varg(const mp_rom_error_text_t *fmt, ...); +NORETURN void mp_raise_ValueError(mp_rom_error_text_t msg); +NORETURN void mp_raise_ValueError_varg(mp_rom_error_text_t fmt, ...); NORETURN void mp_raise_ZeroDivisionError(void); #if MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG diff --git a/shared-bindings/_bleio/__init__.c b/shared-bindings/_bleio/__init__.c index 949fcae867..f754f569a3 100644 --- a/shared-bindings/_bleio/__init__.c +++ b/shared-bindings/_bleio/__init__.c @@ -66,7 +66,7 @@ //| ... //| MP_DEFINE_BLEIO_EXCEPTION(BluetoothError, Exception) -NORETURN void mp_raise_bleio_BluetoothError(const mp_rom_error_text_t *fmt, ...) { +NORETURN void mp_raise_bleio_BluetoothError(mp_rom_error_text_t fmt, ...) { va_list argptr; va_start(argptr, fmt); mp_obj_t exception = mp_obj_new_exception_msg_vlist(&mp_type_bleio_BluetoothError, fmt, argptr); @@ -81,7 +81,7 @@ NORETURN void mp_raise_bleio_BluetoothError(const mp_rom_error_text_t *fmt, ...) //| ... //| MP_DEFINE_BLEIO_EXCEPTION(RoleError, bleio_BluetoothError) -NORETURN void mp_raise_bleio_RoleError(const mp_rom_error_text_t *msg) { +NORETURN void mp_raise_bleio_RoleError(mp_rom_error_text_t msg) { mp_raise_msg(&mp_type_bleio_RoleError, msg); } @@ -91,7 +91,7 @@ NORETURN void mp_raise_bleio_RoleError(const mp_rom_error_text_t *msg) { //| ... //| MP_DEFINE_BLEIO_EXCEPTION(SecurityError, bleio_BluetoothError) -NORETURN void mp_raise_bleio_SecurityError(const mp_rom_error_text_t *fmt, ...) { +NORETURN void mp_raise_bleio_SecurityError(mp_rom_error_text_t fmt, ...) { va_list argptr; va_start(argptr, fmt); mp_obj_t exception = mp_obj_new_exception_msg_vlist(&mp_type_bleio_SecurityError, fmt, argptr); diff --git a/shared-bindings/_bleio/__init__.h b/shared-bindings/_bleio/__init__.h index b980421a52..e7d923fbe9 100644 --- a/shared-bindings/_bleio/__init__.h +++ b/shared-bindings/_bleio/__init__.h @@ -62,9 +62,9 @@ void bleio_reset(void); extern mp_obj_t bleio_set_adapter(mp_obj_t adapter_obj); -NORETURN void mp_raise_bleio_BluetoothError(const mp_rom_error_text_t *msg, ...); -NORETURN void mp_raise_bleio_RoleError(const mp_rom_error_text_t *msg); -NORETURN void mp_raise_bleio_SecurityError(const mp_rom_error_text_t *msg, ...); +NORETURN void mp_raise_bleio_BluetoothError(mp_rom_error_text_t msg, ...); +NORETURN void mp_raise_bleio_RoleError(mp_rom_error_text_t msg); +NORETURN void mp_raise_bleio_SecurityError(mp_rom_error_text_t msg, ...); bleio_adapter_obj_t *common_hal_bleio_allocate_adapter_or_raise(void); void common_hal_bleio_check_connected(uint16_t conn_handle); diff --git a/shared-bindings/memorymonitor/__init__.c b/shared-bindings/memorymonitor/__init__.c index 72dfd53a01..677254c00d 100644 --- a/shared-bindings/memorymonitor/__init__.c +++ b/shared-bindings/memorymonitor/__init__.c @@ -43,7 +43,7 @@ //| MP_DEFINE_MEMORYMONITOR_EXCEPTION(AllocationError, Exception) -NORETURN void mp_raise_memorymonitor_AllocationError(const mp_rom_error_text_t *fmt, ...) { +NORETURN void mp_raise_memorymonitor_AllocationError(mp_rom_error_text_t fmt, ...) { va_list argptr; va_start(argptr, fmt); mp_obj_t exception = mp_obj_new_exception_msg_vlist(&mp_type_memorymonitor_AllocationError, fmt, argptr); diff --git a/shared-bindings/memorymonitor/__init__.h b/shared-bindings/memorymonitor/__init__.h index 4d79c8f542..cffb3b77f0 100644 --- a/shared-bindings/memorymonitor/__init__.h +++ b/shared-bindings/memorymonitor/__init__.h @@ -44,6 +44,6 @@ void memorymonitor_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_pr extern const mp_obj_type_t mp_type_memorymonitor_AllocationError; -NORETURN void mp_raise_memorymonitor_AllocationError(const mp_rom_error_text_t *msg, ...); +NORETURN void mp_raise_memorymonitor_AllocationError(mp_rom_error_text_t msg, ...); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_MEMORYMONITOR___INIT___H diff --git a/shared-bindings/usb/core/__init__.c b/shared-bindings/usb/core/__init__.c index 236b33acfc..47c833ee0e 100644 --- a/shared-bindings/usb/core/__init__.c +++ b/shared-bindings/usb/core/__init__.c @@ -48,7 +48,7 @@ //| ... //| MP_DEFINE_USB_CORE_EXCEPTION(USBError, OSError) -NORETURN void mp_raise_usb_core_USBError(const mp_rom_error_text_t *fmt, ...) { +NORETURN void mp_raise_usb_core_USBError(mp_rom_error_text_t fmt, ...) { mp_obj_t exception; if (fmt == NULL) { exception = mp_obj_new_exception(&mp_type_usb_core_USBError); diff --git a/shared-bindings/usb/core/__init__.h b/shared-bindings/usb/core/__init__.h index 85b929871a..40f3030a6d 100644 --- a/shared-bindings/usb/core/__init__.h +++ b/shared-bindings/usb/core/__init__.h @@ -45,7 +45,7 @@ void usb_core_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_print_k extern const mp_obj_type_t mp_type_usb_core_USBError; extern const mp_obj_type_t mp_type_usb_core_USBTimeoutError; -NORETURN void mp_raise_usb_core_USBError(const mp_rom_error_text_t *fmt, ...); +NORETURN void mp_raise_usb_core_USBError(mp_rom_error_text_t fmt, ...); NORETURN void mp_raise_usb_core_USBTimeoutError(void); // Find is all Python object oriented so we don't need a separate common-hal API diff --git a/shared-module/os/getenv.c b/shared-module/os/getenv.c index 74e01e07bf..4644453da9 100644 --- a/shared-module/os/getenv.c +++ b/shared-module/os/getenv.c @@ -314,7 +314,7 @@ STATIC os_getenv_err_t os_getenv_buf_terminated(const char *key, char *value, si return result; } -STATIC void print_dont_raise(const mp_obj_type_t *exc_type, const mp_rom_error_text_t *fmt, ...) { +STATIC void print_dont_raise(const mp_obj_type_t *exc_type, mp_rom_error_text_t fmt, ...) { va_list argptr; va_start(argptr, fmt); mp_vcprintf(&mp_plat_print, fmt, argptr); @@ -322,7 +322,7 @@ STATIC void print_dont_raise(const mp_obj_type_t *exc_type, const mp_rom_error_t va_end(argptr); } -STATIC void handle_getenv_error(os_getenv_err_t error, void (*handle)(const mp_obj_type_t *exc_type, const mp_rom_error_text_t *fmt, ...)) { +STATIC void handle_getenv_error(os_getenv_err_t error, void (*handle)(const mp_obj_type_t *exc_type, mp_rom_error_text_t fmt, ...)) { if (error == GETENV_OK) { return; } diff --git a/shared-module/sdcardio/SDCard.c b/shared-module/sdcardio/SDCard.c index f9c31d0f66..f4fa8b77f2 100644 --- a/shared-module/sdcardio/SDCard.c +++ b/shared-module/sdcardio/SDCard.c @@ -199,7 +199,7 @@ STATIC int block_cmd(sdcardio_sdcard_obj_t *self, int cmd_, int block, void *res return cmd(self, cmd_, block * self->cdv, response_buf, response_len, true, true); } -STATIC const mp_rom_error_text_t *init_card_v1(sdcardio_sdcard_obj_t *self) { +STATIC mp_rom_error_text_t init_card_v1(sdcardio_sdcard_obj_t *self) { for (int i = 0; i < CMD_TIMEOUT; i++) { if (cmd(self, 41, 0, NULL, 0, true, true) == 0) { return NULL; @@ -208,7 +208,7 @@ STATIC const mp_rom_error_text_t *init_card_v1(sdcardio_sdcard_obj_t *self) { return translate("timeout waiting for v1 card"); } -STATIC const mp_rom_error_text_t *init_card_v2(sdcardio_sdcard_obj_t *self) { +STATIC mp_rom_error_text_t init_card_v2(sdcardio_sdcard_obj_t *self) { for (int i = 0; i < CMD_TIMEOUT; i++) { uint8_t ocr[4]; common_hal_time_delay_ms(50); @@ -225,7 +225,7 @@ STATIC const mp_rom_error_text_t *init_card_v2(sdcardio_sdcard_obj_t *self) { return translate("timeout waiting for v2 card"); } -STATIC const mp_rom_error_text_t *init_card(sdcardio_sdcard_obj_t *self) { +STATIC mp_rom_error_text_t init_card(sdcardio_sdcard_obj_t *self) { clock_card(self, 10); common_hal_digitalio_digitalinout_set_value(&self->cs, false); @@ -256,12 +256,12 @@ STATIC const mp_rom_error_text_t *init_card(sdcardio_sdcard_obj_t *self) { uint8_t rb7[4]; int response = cmd(self, 8, 0x1AA, rb7, sizeof(rb7), false, true); if (response == R1_IDLE_STATE) { - const mp_rom_error_text_t *result = init_card_v2(self); + mp_rom_error_text_t result = init_card_v2(self); if (result != NULL) { return result; } } else if (response == (R1_IDLE_STATE | R1_ILLEGAL_COMMAND)) { - const mp_rom_error_text_t *result = init_card_v1(self); + mp_rom_error_text_t result = init_card_v1(self); if (result != NULL) { return result; } @@ -314,7 +314,7 @@ void common_hal_sdcardio_sdcard_construct(sdcardio_sdcard_obj_t *self, busio_spi self->baudrate = 250000; lock_bus_or_throw(self); - const mp_rom_error_text_t *result = init_card(self); + mp_rom_error_text_t result = init_card(self); extraclock_and_unlock_bus(self); if (result != NULL) { diff --git a/supervisor/shared/safe_mode.c b/supervisor/shared/safe_mode.c index c7ead7ac53..ee79d88233 100644 --- a/supervisor/shared/safe_mode.c +++ b/supervisor/shared/safe_mode.c @@ -148,7 +148,7 @@ void print_safe_mode_message(safe_mode_t reason) { serial_write_compressed(translate("\nYou are in safe mode because:\n")); - const mp_rom_error_text_t *message = NULL; + mp_rom_error_text_t message = NULL; // First check for safe mode reasons that do not necessarily reflect bugs. diff --git a/supervisor/shared/translate/compressed_string.h b/supervisor/shared/translate/compressed_string.h index 1174121068..917f763d7d 100644 --- a/supervisor/shared/translate/compressed_string.h +++ b/supervisor/shared/translate/compressed_string.h @@ -94,12 +94,12 @@ typedef struct compressed_string { uint8_t data; const uint8_t tail[]; -} *mp_rom_error_text_t; +} const *mp_rom_error_text_t; // Return the compressed, translated version of a source string // Usually, due to LTO, this is optimized into a load of a constant // pointer. -// const mp_rom_error_text_t *translate(const char *c); -void serial_write_compressed(const mp_rom_error_text_t *compressed); -char *decompress(const mp_rom_error_text_t *compressed, char *decompressed); -uint16_t decompress_length(const mp_rom_error_text_t *compressed); +// mp_rom_error_text_t translate(const char *c); +void serial_write_compressed(mp_rom_error_text_t compressed); +char *decompress(mp_rom_error_text_t compressed, char *decompressed); +uint16_t decompress_length(mp_rom_error_text_t compressed); diff --git a/supervisor/shared/translate/translate.c b/supervisor/shared/translate/translate.c index 244497dfe0..e0b5fb897a 100644 --- a/supervisor/shared/translate/translate.c +++ b/supervisor/shared/translate/translate.c @@ -39,7 +39,7 @@ #include "py/mpprint.h" #include "supervisor/serial.h" -void serial_write_compressed(const mp_rom_error_text_t *compressed) { +void serial_write_compressed(mp_rom_error_text_t compressed) { mp_printf(MP_PYTHON_PRINTER, "%S", compressed); } @@ -90,7 +90,7 @@ STATIC int put_utf8(char *buf, int u) { } } -uint16_t decompress_length(const mp_rom_error_text_t *compressed) { +uint16_t decompress_length(mp_rom_error_text_t compressed) { #ifndef NO_QSTR #if (compress_max_length_bits <= 8) return 1 + (compressed->data >> (8 - compress_max_length_bits)); @@ -123,7 +123,7 @@ static int get_nbits(bitstream_state_t *st, int n) { return r; } -char *decompress(const mp_rom_error_text_t *compressed, char *decompressed) { +char *decompress(mp_rom_error_text_t compressed, char *decompressed) { bitstream_state_t b = { .ptr = &(compressed->data) + (compress_max_length_bits >> 3), .bit = 1 << (7 - ((compress_max_length_bits) & 0x7)), diff --git a/supervisor/shared/translate/translate.h b/supervisor/shared/translate/translate.h index be84670776..76bc462625 100644 --- a/supervisor/shared/translate/translate.h +++ b/supervisor/shared/translate/translate.h @@ -30,9 +30,10 @@ #include #include -#include "supervisor/shared/translate/compressed_string.h" // Map MicroPython's error messages to our translations. +#if !defined(MICROPY_ENABLE_DYNRUNTIME) || !MICROPY_ENABLE_DYNRUNTIME +#include "supervisor/shared/translate/compressed_string.h" #define MP_COMPRESSED_ROM_TEXT(x) translate(x) // translate() is a giant function with many strcmp calls. The assumption is @@ -47,5 +48,10 @@ #else // In link time optimized (LTO) builds, we can compile this once into a .o and // at link time the calls will be optimized. -const mp_rom_error_text_t *translate(const char *c); +mp_rom_error_text_t translate(const char *c); +#endif + +#else +typedef const char *mp_rom_error_text_t; +#define MP_COMPRESSED_ROM_TEXT(x) x #endif diff --git a/supervisor/shared/translate/translate_impl.h b/supervisor/shared/translate/translate_impl.h index e1a295a0db..a57f90ff41 100644 --- a/supervisor/shared/translate/translate_impl.h +++ b/supervisor/shared/translate/translate_impl.h @@ -34,7 +34,7 @@ #ifndef NO_QSTR #define QDEF(id, hash, len, str) -#define TRANSLATION(english_id, number) extern mp_rom_error_text_t translation##number; +#define TRANSLATION(english_id, number) extern struct compressed_string translation##number; #include "genhdr/qstrdefs.generated.h" #undef TRANSLATION #undef QDEF @@ -50,10 +50,10 @@ __attribute__((always_inline)) #endif // Prevent instrumenting this because that disables the inlining we rely of for code size // optimization. -__attribute__((no_instrument_function)) const mp_rom_error_text_t *translate(const char *original) { +__attribute__((no_instrument_function)) mp_rom_error_text_t translate(const char *original) { #ifndef NO_QSTR #define QDEF(id, hash, len, str) - #define TRANSLATION(english_id, number) if (strcmp(original, english_id) == 0) { return &translation##number; } else + #define TRANSLATION(english_id, number) if (strcmp(original, english_id) == 0) { return (mp_rom_error_text_t)&translation##number; } else #include "genhdr/qstrdefs.generated.h" #undef TRANSLATION #undef QDEF