Skip to content

Commit 32b6ac7

Browse files
authored
Merge pull request #8519 from jepler/compressed-message-type
Rename compressed_string_t to mp_rom_error_text_t to match upstream
2 parents abeed5b + 3f1b9af commit 32b6ac7

File tree

32 files changed

+143
-149
lines changed

32 files changed

+143
-149
lines changed

devices/ble_hci/common-hal/_bleio/att.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1722,7 +1722,7 @@ void att_process_data(uint16_t conn_handle, uint8_t dlen, uint8_t data[]) {
17221722

17231723
// FIX Do we need all of these?
17241724
static void check_att_err(uint8_t err) {
1725-
const compressed_string_t *msg = NULL;
1725+
mp_rom_error_text_t msg = NULL;
17261726
switch (err) {
17271727
case 0:
17281728
return;

ports/espressif/common-hal/espidf/__init__.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ intptr_t common_hal_espidf_get_psram_end(void) {
122122
}
123123

124124
void raise_esp_error(esp_err_t err) {
125-
const compressed_string_t *msg = NULL;
125+
mp_rom_error_text_t msg = NULL;
126126
const mp_obj_type_t *exception_type = &mp_type_espidf_IDFError;
127127
switch (err) {
128128
case ESP_FAIL:

ports/espressif/common-hal/wifi/Monitor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static void wifi_monitor_cb(void *recv_buf, wifi_promiscuous_pkt_type_t type) {
7878
}
7979

8080
void common_hal_wifi_monitor_construct(wifi_monitor_obj_t *self, uint8_t channel, size_t queue) {
81-
const compressed_string_t *monitor_mode_init_error = translate("monitor init failed");
81+
mp_rom_error_text_t monitor_mode_init_error = translate("monitor init failed");
8282

8383
self->queue = xQueueCreate(queue, sizeof(monitor_packet_t));
8484
if (!self->queue) {

py/argcheck.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -179,36 +179,36 @@ NORETURN void mp_arg_error_unimpl_kw(void) {
179179

180180
mp_int_t mp_arg_validate_int(mp_int_t i, mp_int_t required_i, qstr arg_name) {
181181
if (i != required_i) {
182-
mp_raise_ValueError_varg(translate("%q must be %d"), arg_name, required_i);
182+
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q must be %d"), arg_name, required_i);
183183
}
184184
return i;
185185
}
186186

187187
mp_int_t mp_arg_validate_int_min(mp_int_t i, mp_int_t min, qstr arg_name) {
188188
if (i < min) {
189-
mp_raise_ValueError_varg(translate("%q must be >= %d"), arg_name, min);
189+
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q must be >= %d"), arg_name, min);
190190
}
191191
return i;
192192
}
193193

194194
mp_int_t mp_arg_validate_int_max(mp_int_t i, mp_int_t max, qstr arg_name) {
195195
if (i > max) {
196-
mp_raise_ValueError_varg(translate("%q must be <= %d"), arg_name, max);
196+
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q must be <= %d"), arg_name, max);
197197
}
198198
return i;
199199
}
200200

201201
mp_int_t mp_arg_validate_int_range(mp_int_t i, mp_int_t min, mp_int_t max, qstr arg_name) {
202202
if (i < min || i > max) {
203-
mp_raise_ValueError_varg(translate("%q must be %d-%d"), arg_name, min, max);
203+
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q must be %d-%d"), arg_name, min, max);
204204
}
205205
return i;
206206
}
207207

208208
mp_float_t mp_arg_validate_type_float(mp_obj_t obj, qstr arg_name) {
209209
mp_float_t a_float;
210210
if (!mp_obj_get_float_maybe(obj, &a_float)) {
211-
mp_raise_TypeError_varg(translate("%q must be of type %q, not %q"), arg_name, MP_QSTR_float, mp_obj_get_type(obj)->name);
211+
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);
212212
}
213213
return a_float;
214214
}
@@ -220,7 +220,7 @@ mp_float_t mp_arg_validate_obj_float_range(mp_obj_t float_in, mp_int_t min, mp_i
220220

221221
mp_float_t mp_arg_validate_float_range(mp_float_t f, mp_int_t min, mp_int_t max, qstr arg_name) {
222222
if (f < (mp_float_t)min || f > (mp_float_t)max) {
223-
mp_raise_ValueError_varg(translate("%q must be %d-%d"), arg_name, min, max);
223+
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q must be %d-%d"), arg_name, min, max);
224224
}
225225
return f;
226226
}
@@ -230,83 +230,83 @@ mp_float_t mp_arg_validate_obj_float_non_negative(mp_obj_t float_in, mp_float_t
230230
? default_for_null
231231
: mp_arg_validate_type_float(float_in, arg_name);
232232
if (f < (mp_float_t)0.0) {
233-
mp_raise_ValueError_varg(translate("%q must be >= %d"), arg_name, 0);
233+
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q must be >= %d"), arg_name, 0);
234234
}
235235
return f;
236236
}
237237

238238
mp_uint_t mp_arg_validate_length_range(mp_uint_t length, mp_uint_t min, mp_uint_t max, qstr arg_name) {
239239
if (length < min || length > max) {
240-
mp_raise_ValueError_varg(translate("%q length must be %d-%d"), arg_name, min, max);
240+
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q length must be %d-%d"), arg_name, min, max);
241241
}
242242
return length;
243243
}
244244

245245
mp_uint_t mp_arg_validate_length_min(mp_uint_t length, mp_uint_t min, qstr arg_name) {
246246
if (length < min) {
247-
mp_raise_ValueError_varg(translate("%q length must be >= %d"), arg_name, min);
247+
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q length must be >= %d"), arg_name, min);
248248
}
249249
return length;
250250
}
251251

252252
mp_uint_t mp_arg_validate_length_max(mp_uint_t length, mp_uint_t max, qstr arg_name) {
253253
if (length > max) {
254-
mp_raise_ValueError_varg(translate("%q length must be <= %d"), arg_name, max);
254+
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q length must be <= %d"), arg_name, max);
255255
}
256256
return length;
257257
}
258258

259259
mp_uint_t mp_arg_validate_length(mp_uint_t length, mp_uint_t required_length, qstr arg_name) {
260260
if (length != required_length) {
261-
mp_raise_ValueError_varg(translate("%q length must be %d"), arg_name, required_length);
261+
mp_raise_ValueError_varg(MP_ERROR_TEXT("%q length must be %d"), arg_name, required_length);
262262
}
263263
return length;
264264
}
265265

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

274274
mp_obj_t mp_arg_validate_type(mp_obj_t obj, const mp_obj_type_t *type, qstr arg_name) {
275275
if (!mp_obj_is_type(obj, type)) {
276-
mp_raise_TypeError_varg(translate("%q must be of type %q, not %q"), arg_name, type->name, mp_obj_get_type(obj)->name);
276+
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);
277277
}
278278
return obj;
279279
}
280280

281281
mp_obj_t mp_arg_validate_type_in(mp_obj_t obj, const mp_obj_type_t *type, qstr arg_name) {
282282
if (!mp_obj_is_type(obj, type)) {
283-
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);
283+
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);
284284
}
285285
return obj;
286286
}
287287

288288
mp_obj_t mp_arg_validate_type_or_none(mp_obj_t obj, const mp_obj_type_t *type, qstr arg_name) {
289289
if (obj != mp_const_none && !mp_obj_is_type(obj, type)) {
290-
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);
290+
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);
291291
}
292292
return obj;
293293
}
294294

295295
mp_obj_t mp_arg_validate_type_string(mp_obj_t obj, qstr arg_name) {
296296
if (!mp_obj_is_str(obj)) {
297-
mp_raise_TypeError_varg(translate("%q must be of type %q, not %q"), arg_name, MP_QSTR_str, mp_obj_get_type(obj)->name);
297+
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);
298298
}
299299
return obj;
300300
}
301301

302302
mp_int_t mp_arg_validate_type_int(mp_obj_t obj, qstr arg_name) {
303303
mp_int_t an_int;
304304
if (!mp_obj_get_int_maybe(obj, &an_int)) {
305-
mp_raise_TypeError_varg(translate("%q must be of type %q, not %q"), arg_name, MP_QSTR_int, mp_obj_get_type(obj)->name);
305+
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);
306306
}
307307
return an_int;
308308
}
309309

310310
NORETURN void mp_arg_error_invalid(qstr arg_name) {
311-
mp_raise_ValueError_varg(translate("Invalid %q"), arg_name);
311+
mp_raise_ValueError_varg(MP_ERROR_TEXT("Invalid %q"), arg_name);
312312
}

py/builtinhelp.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ STATIC void mp_help_print_modules(void) {
122122

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

140140
// try to print something sensible about the given object
141-
mp_cprintf(MP_PYTHON_PRINTER, translate("object "));
141+
mp_cprintf(MP_PYTHON_PRINTER, MP_ERROR_TEXT("object "));
142142
mp_obj_print(obj, PRINT_STR);
143143

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

146146
mp_map_t *map = NULL;
147147
if (type == &mp_type_module) {
@@ -168,7 +168,7 @@ STATIC mp_obj_t mp_builtin_help(size_t n_args, const mp_obj_t *args) {
168168
if (n_args == 0) {
169169
// print a general help message. Translate only works on single strings on one line.
170170
mp_cprintf(MP_PYTHON_PRINTER,
171-
translate("Welcome to Adafruit CircuitPython %s!\n\nVisit circuitpython.org for more information.\n\nTo list built-in modules type `help(\"modules\")`.\n"),
171+
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"),
172172
MICROPY_GIT_TAG);
173173
} else {
174174
// try to print something sensible about the given object

py/compile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ STATIC void compile_error_set_line(compiler_t *comp, mp_parse_node_t pn) {
255255
}
256256
}
257257

258-
STATIC void compile_syntax_error(compiler_t *comp, mp_parse_node_t pn, const compressed_string_t *msg) {
258+
STATIC void compile_syntax_error(compiler_t *comp, mp_parse_node_t pn, mp_rom_error_text_t msg) {
259259
// only register the error if there has been no other error
260260
if (comp->compile_error == MP_OBJ_NULL) {
261261
comp->compile_error = mp_obj_new_exception_msg(&mp_type_SyntaxError, msg);
@@ -2740,7 +2740,7 @@ STATIC void compile_yield_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
27402740
pns = (mp_parse_node_struct_t *)pns->nodes[0];
27412741
#if MICROPY_PY_ASYNC_AWAIT
27422742
if (comp->scope_cur->scope_flags & MP_SCOPE_FLAG_ASYNC) {
2743-
compile_syntax_error(comp, (mp_parse_node_t)pns, translate("'yield from' inside async function"));
2743+
compile_syntax_error(comp, (mp_parse_node_t)pns, MP_ERROR_TEXT("'yield from' inside async function"));
27442744
return;
27452745
}
27462746
#endif

py/emitinlinethumb.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ static inline bool emit_inline_thumb_allow_float(emit_inline_asm_t *emit) {
7474

7575
#endif
7676

77-
// CIRCUITPY-CHANGE
78-
STATIC void emit_inline_thumb_error_msg(emit_inline_asm_t *emit, const compressed_string_t *msg) {
77+
STATIC void emit_inline_thumb_error_msg(emit_inline_asm_t *emit, mp_rom_error_text_t msg) {
7978
*emit->error_slot = mp_obj_new_exception_msg(&mp_type_SyntaxError, msg);
8079
}
8180

py/emitinlinextensa.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ struct _emit_inline_asm_t {
4343
qstr *label_lookup;
4444
};
4545

46-
// CIRCUITPY-CHANGE
47-
STATIC void emit_inline_xtensa_error_msg(emit_inline_asm_t *emit, const compressed_string_t *msg) {
46+
STATIC void emit_inline_xtensa_error_msg(emit_inline_asm_t *emit, mp_rom_error_text_t msg) {
4847
*emit->error_slot = mp_obj_new_exception_msg(&mp_type_SyntaxError, msg);
4948
}
5049

py/maketranslationdata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ def output_translation_data(encoding_table, i18ns, out):
595595
decompressed = decompressed.replace(c, C_ESCAPES[c])
596596
formatted = ["{:d}".format(x) for x in compressed]
597597
out.write(
598-
"const compressed_string_t translation{} = {{ .data = {}, .tail = {{ {} }} }}; // {}\n".format(
598+
"const struct compressed_string translation{} = {{ .data = {}, .tail = {{ {} }} }}; // {}\n".format(
599599
i, formatted[0], ", ".join(formatted[1:]), original, decompressed
600600
)
601601
)

py/misc.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ typedef union _mp_float_union_t {
297297
// So leave MP_COMPRESSED_ROM_TEXT in place for makeqstrdefs.py / makecompresseddata.py to find them.
298298

299299
#else
300-
301300
// Compression enabled and doing a regular build.
302301
// Map MP_COMPRESSED_ROM_TEXT to the compressed strings.
303302

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

328327
return msg;
329328
}
330-
331329
#endif
332330

331+
#elif defined(CIRCUITPY)
332+
#include "supervisor/shared/translate/translate.h"
333333
#else
334334

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

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

351346
#endif // MICROPY_INCLUDED_PY_MISC_H

0 commit comments

Comments
 (0)