Skip to content

Rename compressed_string_t to mp_rom_error_text_t to match upstream #8519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion devices/ble_hci/common-hal/_bleio/att.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 compressed_string_t *msg = NULL;
mp_rom_error_text_t msg = NULL;
switch (err) {
case 0:
return;
Expand Down
2 changes: 1 addition & 1 deletion ports/espressif/common-hal/espidf/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ intptr_t common_hal_espidf_get_psram_end(void) {
}

void raise_esp_error(esp_err_t err) {
const compressed_string_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:
Expand Down
2 changes: 1 addition & 1 deletion ports/espressif/common-hal/wifi/Monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 compressed_string_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) {
Expand Down
36 changes: 18 additions & 18 deletions py/argcheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,36 +179,36 @@ NORETURN void mp_arg_error_unimpl_kw(void) {

mp_int_t mp_arg_validate_int(mp_int_t i, mp_int_t required_i, qstr arg_name) {
if (i != required_i) {
mp_raise_ValueError_varg(translate("%q must be %d"), arg_name, required_i);
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q must be %d"), arg_name, required_i);
}
return i;
}

mp_int_t mp_arg_validate_int_min(mp_int_t i, mp_int_t min, qstr arg_name) {
if (i < min) {
mp_raise_ValueError_varg(translate("%q must be >= %d"), arg_name, min);
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q must be >= %d"), arg_name, min);
}
return i;
}

mp_int_t mp_arg_validate_int_max(mp_int_t i, mp_int_t max, qstr arg_name) {
if (i > max) {
mp_raise_ValueError_varg(translate("%q must be <= %d"), arg_name, max);
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q must be <= %d"), arg_name, max);
}
return i;
}

mp_int_t mp_arg_validate_int_range(mp_int_t i, mp_int_t min, mp_int_t max, qstr arg_name) {
if (i < min || i > max) {
mp_raise_ValueError_varg(translate("%q must be %d-%d"), arg_name, min, max);
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q must be %d-%d"), arg_name, min, max);
}
return i;
}

mp_float_t mp_arg_validate_type_float(mp_obj_t obj, qstr arg_name) {
mp_float_t a_float;
if (!mp_obj_get_float_maybe(obj, &a_float)) {
mp_raise_TypeError_varg(translate("%q must be of type %q, not %q"), arg_name, MP_QSTR_float, mp_obj_get_type(obj)->name);
mp_raise_TypeError_varg(MP_ERROR_TEXT("%q must be of type %q, not %q"), arg_name, MP_QSTR_float, mp_obj_get_type(obj)->name);
}
return a_float;
}
Expand All @@ -220,7 +220,7 @@ mp_float_t mp_arg_validate_obj_float_range(mp_obj_t float_in, mp_int_t min, mp_i

mp_float_t mp_arg_validate_float_range(mp_float_t f, mp_int_t min, mp_int_t max, qstr arg_name) {
if (f < (mp_float_t)min || f > (mp_float_t)max) {
mp_raise_ValueError_varg(translate("%q must be %d-%d"), arg_name, min, max);
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q must be %d-%d"), arg_name, min, max);
}
return f;
}
Expand All @@ -230,83 +230,83 @@ mp_float_t mp_arg_validate_obj_float_non_negative(mp_obj_t float_in, mp_float_t
? default_for_null
: mp_arg_validate_type_float(float_in, arg_name);
if (f < (mp_float_t)0.0) {
mp_raise_ValueError_varg(translate("%q must be >= %d"), arg_name, 0);
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q must be >= %d"), arg_name, 0);
}
return f;
}

mp_uint_t mp_arg_validate_length_range(mp_uint_t length, mp_uint_t min, mp_uint_t max, qstr arg_name) {
if (length < min || length > max) {
mp_raise_ValueError_varg(translate("%q length must be %d-%d"), arg_name, min, max);
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q length must be %d-%d"), arg_name, min, max);
}
return length;
}

mp_uint_t mp_arg_validate_length_min(mp_uint_t length, mp_uint_t min, qstr arg_name) {
if (length < min) {
mp_raise_ValueError_varg(translate("%q length must be >= %d"), arg_name, min);
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q length must be >= %d"), arg_name, min);
}
return length;
}

mp_uint_t mp_arg_validate_length_max(mp_uint_t length, mp_uint_t max, qstr arg_name) {
if (length > max) {
mp_raise_ValueError_varg(translate("%q length must be <= %d"), arg_name, max);
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q length must be <= %d"), arg_name, max);
}
return length;
}

mp_uint_t mp_arg_validate_length(mp_uint_t length, mp_uint_t required_length, qstr arg_name) {
if (length != required_length) {
mp_raise_ValueError_varg(translate("%q length must be %d"), arg_name, required_length);
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q length must be %d"), arg_name, required_length);
}
return length;
}

// int instead of uint because an index can be negative in some cases.
mp_int_t mp_arg_validate_index_range(mp_int_t index, mp_int_t min, mp_int_t max, qstr arg_name) {
if (index < min || index > max) {
mp_raise_IndexError_varg(translate("%q out of range"), arg_name, min, max);
mp_raise_IndexError_varg(MP_ERROR_TEXT("%q out of range"), arg_name, min, max);
}
return index;
}

mp_obj_t mp_arg_validate_type(mp_obj_t obj, const mp_obj_type_t *type, qstr arg_name) {
if (!mp_obj_is_type(obj, type)) {
mp_raise_TypeError_varg(translate("%q must be of type %q, not %q"), arg_name, type->name, mp_obj_get_type(obj)->name);
mp_raise_TypeError_varg(MP_ERROR_TEXT("%q must be of type %q, not %q"), arg_name, type->name, mp_obj_get_type(obj)->name);
}
return obj;
}

mp_obj_t mp_arg_validate_type_in(mp_obj_t obj, const mp_obj_type_t *type, qstr arg_name) {
if (!mp_obj_is_type(obj, type)) {
mp_raise_TypeError_varg(translate("%q in %q must be of type %q, not %q"), MP_QSTR_object, arg_name, type->name, mp_obj_get_type(obj)->name);
mp_raise_TypeError_varg(MP_ERROR_TEXT("%q in %q must be of type %q, not %q"), MP_QSTR_object, arg_name, type->name, mp_obj_get_type(obj)->name);
}
return obj;
}

mp_obj_t mp_arg_validate_type_or_none(mp_obj_t obj, const mp_obj_type_t *type, qstr arg_name) {
if (obj != mp_const_none && !mp_obj_is_type(obj, type)) {
mp_raise_TypeError_varg(translate("%q must be of type %q or %q, not %q"), arg_name, type->name, MP_QSTR_None, mp_obj_get_type(obj)->name);
mp_raise_TypeError_varg(MP_ERROR_TEXT("%q must be of type %q or %q, not %q"), arg_name, type->name, MP_QSTR_None, mp_obj_get_type(obj)->name);
}
return obj;
}

mp_obj_t mp_arg_validate_type_string(mp_obj_t obj, qstr arg_name) {
if (!mp_obj_is_str(obj)) {
mp_raise_TypeError_varg(translate("%q must be of type %q, not %q"), arg_name, MP_QSTR_str, mp_obj_get_type(obj)->name);
mp_raise_TypeError_varg(MP_ERROR_TEXT("%q must be of type %q, not %q"), arg_name, MP_QSTR_str, mp_obj_get_type(obj)->name);
}
return obj;
}

mp_int_t mp_arg_validate_type_int(mp_obj_t obj, qstr arg_name) {
mp_int_t an_int;
if (!mp_obj_get_int_maybe(obj, &an_int)) {
mp_raise_TypeError_varg(translate("%q must be of type %q, not %q"), arg_name, MP_QSTR_int, mp_obj_get_type(obj)->name);
mp_raise_TypeError_varg(MP_ERROR_TEXT("%q must be of type %q, not %q"), arg_name, MP_QSTR_int, mp_obj_get_type(obj)->name);
}
return an_int;
}

NORETURN void mp_arg_error_invalid(qstr arg_name) {
mp_raise_ValueError_varg(translate("Invalid %q"), arg_name);
mp_raise_ValueError_varg(MP_ERROR_TEXT("Invalid %q"), arg_name);
}
8 changes: 4 additions & 4 deletions py/builtinhelp.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ STATIC void mp_help_print_modules(void) {

#if MICROPY_ENABLE_EXTERNAL_IMPORT
// let the user know there may be other modules available from the filesystem
serial_write_compressed(translate("Plus any modules on the filesystem\n"));
serial_write_compressed(MP_ERROR_TEXT("Plus any modules on the filesystem\n"));
#endif
}
#endif
Expand All @@ -138,10 +138,10 @@ STATIC void mp_help_print_obj(const mp_obj_t obj) {
const mp_obj_type_t *type = mp_obj_get_type(obj);

// try to print something sensible about the given object
mp_cprintf(MP_PYTHON_PRINTER, translate("object "));
mp_cprintf(MP_PYTHON_PRINTER, MP_ERROR_TEXT("object "));
mp_obj_print(obj, PRINT_STR);

mp_cprintf(MP_PYTHON_PRINTER, translate(" is of type %q\n"), type->name);
mp_cprintf(MP_PYTHON_PRINTER, MP_ERROR_TEXT(" is of type %q\n"), type->name);

mp_map_t *map = NULL;
if (type == &mp_type_module) {
Expand All @@ -168,7 +168,7 @@ STATIC mp_obj_t mp_builtin_help(size_t n_args, const mp_obj_t *args) {
if (n_args == 0) {
// print a general help message. Translate only works on single strings on one line.
mp_cprintf(MP_PYTHON_PRINTER,
translate("Welcome to Adafruit CircuitPython %s!\n\nVisit circuitpython.org for more information.\n\nTo list built-in modules type `help(\"modules\")`.\n"),
MP_ERROR_TEXT("Welcome to Adafruit CircuitPython %s!\n\nVisit circuitpython.org for more information.\n\nTo list built-in modules type `help(\"modules\")`.\n"),
MICROPY_GIT_TAG);
} else {
// try to print something sensible about the given object
Expand Down
4 changes: 2 additions & 2 deletions py/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 compressed_string_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);
Expand Down Expand Up @@ -2740,7 +2740,7 @@ STATIC void compile_yield_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
pns = (mp_parse_node_struct_t *)pns->nodes[0];
#if MICROPY_PY_ASYNC_AWAIT
if (comp->scope_cur->scope_flags & MP_SCOPE_FLAG_ASYNC) {
compile_syntax_error(comp, (mp_parse_node_t)pns, translate("'yield from' inside async function"));
compile_syntax_error(comp, (mp_parse_node_t)pns, MP_ERROR_TEXT("'yield from' inside async function"));
return;
}
#endif
Expand Down
3 changes: 1 addition & 2 deletions py/emitinlinethumb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 compressed_string_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);
}

Expand Down
3 changes: 1 addition & 2 deletions py/emitinlinextensa.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 compressed_string_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);
}

Expand Down
2 changes: 1 addition & 1 deletion py/maketranslationdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 compressed_string_t translation{} = {{ .data = {}, .tail = {{ {} }} }}; // {}\n".format(
"const struct compressed_string translation{} = {{ .data = {}, .tail = {{ {} }} }}; // {}\n".format(
i, formatted[0], ", ".join(formatted[1:]), original, decompressed
)
)
Expand Down
9 changes: 2 additions & 7 deletions py/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ typedef union _mp_float_union_t {
// So leave MP_COMPRESSED_ROM_TEXT in place for makeqstrdefs.py / makecompresseddata.py to find them.

#else

// Compression enabled and doing a regular build.
// Map MP_COMPRESSED_ROM_TEXT to the compressed strings.

Expand Down Expand Up @@ -327,9 +326,10 @@ inline MP_ALWAYSINLINE const char *MP_COMPRESSED_ROM_TEXT(const char *msg) {

return msg;
}

#endif

#elif defined(CIRCUITPY)
#include "supervisor/shared/translate/translate.h"
#else

// Compression not enabled, just make it a no-op.
Expand All @@ -341,11 +341,6 @@ typedef const char *mp_rom_error_text_t;

// Might add more types of compressed text in the future.
// For now, forward directly to MP_COMPRESSED_ROM_TEXT.
// CIRCUITPY-CHANGE: MP_ERROR_TEXT() -> translate()
#if CIRCUITPY
#include "supervisor/shared/translate/translate.h"
#else
#define MP_ERROR_TEXT(x) (mp_rom_error_text_t)MP_COMPRESSED_ROM_TEXT(x)
#endif

#endif // MICROPY_INCLUDED_PY_MISC_H
2 changes: 1 addition & 1 deletion py/moderrno.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const char *mp_common_errno_to_str(mp_obj_t errno_val, char *buf, size_t len) {
return NULL;
}

const compressed_string_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");
Expand Down
6 changes: 3 additions & 3 deletions py/mpprint.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args) {
break;
}
case 'S': {
compressed_string_t *arg = va_arg(args, compressed_string_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];
Expand Down Expand Up @@ -593,15 +593,15 @@ 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 compressed_string_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);
va_end(ap);
return ret;
}

int mp_vcprintf(const mp_print_t *print, const compressed_string_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);
Expand Down
24 changes: 9 additions & 15 deletions py/obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 compressed_string_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:");
Expand Down Expand Up @@ -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 compressed_string_t *frame = MP_ERROR_TEXT(" File \"%q\", line %d");
mp_rom_error_text_t frame = MP_ERROR_TEXT(" File \"%q\", line %d");
#else
const compressed_string_t *frame = MP_ERROR_TEXT(" File \"%q\"");
mp_rom_error_text_t frame = MP_ERROR_TEXT(" File \"%q\"");
#endif
const compressed_string_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
Expand Down Expand Up @@ -685,18 +685,12 @@ mp_obj_t mp_obj_generic_subscript_getiter(mp_obj_t obj, mp_obj_iter_buf_t *iter_

bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
const mp_obj_type_t *type = mp_obj_get_type(obj);
if (!MP_OBJ_TYPE_HAS_SLOT(type, buffer)) {
return false;
if (MP_OBJ_TYPE_HAS_SLOT(type, buffer)
&& MP_OBJ_TYPE_GET_SLOT(type, buffer)(obj, bufinfo, flags & MP_BUFFER_RW) == 0) {
return true;
}
int ret = MP_OBJ_TYPE_GET_SLOT(type, buffer)(obj, bufinfo, flags);
if (ret != 0) {
return false;
}
return true;
}

void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
if (!mp_get_buffer(obj, bufinfo, flags)) {
if (flags & MP_BUFFER_RAISE_IF_UNSUPPORTED) {
mp_raise_TypeError(MP_ERROR_TEXT("object with buffer protocol required"));
}
return false;
}
Loading