Skip to content

Commit

Permalink
Fix board builds and use MP_ERROR_TEXT in py and extmod
Browse files Browse the repository at this point in the history
  • Loading branch information
tannewt committed May 6, 2021
1 parent 7f2f8e2 commit 3fda0c0
Show file tree
Hide file tree
Showing 117 changed files with 424 additions and 564 deletions.
2 changes: 1 addition & 1 deletion extmod/modubinascii.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
static void check_not_unicode(const mp_obj_t arg) {
#if MICROPY_CPYTHON_COMPAT
if (mp_obj_is_str(arg)) {
mp_raise_TypeError(translate("a bytes-like object is required"));
mp_raise_TypeError(MP_ERROR_TEXT("a bytes-like object is required"));
}
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion extmod/moduhashlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ STATIC mp_obj_t uhashlib_sha256_digest(mp_obj_t self_in) {
static void check_not_unicode(const mp_obj_t arg) {
#if MICROPY_CPYTHON_COMPAT
if (mp_obj_is_str(arg)) {
mp_raise_TypeError(translate("a bytes-like object is required"));
mp_raise_TypeError(MP_ERROR_TEXT("a bytes-like object is required"));
}
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion extmod/vfs_fat.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ STATIC mp_obj_t vfs_fat_setlabel(mp_obj_t self_in, mp_obj_t label_in) {
FRESULT res = f_setlabel(&self->fatfs, label_str);
if (res != FR_OK) {
if (res == FR_WRITE_PROTECTED) {
mp_raise_msg(&mp_type_OSError, translate("Read-only filesystem"));
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Read-only filesystem"));
}
mp_raise_OSError(fresult_to_errno_table[res]);
}
Expand Down
2 changes: 1 addition & 1 deletion extmod/vfs_posix_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "extmod/vfs_posix.h"
#include "supervisor/shared/translate.h"

#if defined(MICROPY_VFS_POSIX) && MICROPY_VFS_POSIX || MICROPY_VFS_POSIX_FILE
#if (defined(MICROPY_VFS_POSIX) && MICROPY_VFS_POSIX) || (defined(MICROPY_VFS_POSIX_FILE) && MICROPY_VFS_POSIX_FILE)

#include <fcntl.h>
#include <unistd.h>
Expand Down
9 changes: 0 additions & 9 deletions lib/utils/interrupt_char.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@ void mp_hal_set_interrupt_char(int c) {
mp_interrupt_char = c;
}

void mp_keyboard_interrupt(void) {
MP_STATE_VM(mp_pending_exception) = MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception));
#if MICROPY_ENABLE_SCHEDULER
if (MP_STATE_VM(sched_state) == MP_SCHED_IDLE) {
MP_STATE_VM(sched_state) = MP_SCHED_PENDING;
}
#endif
}

// Check to see if we've been CTRL-C'ed by autoreload or the user.
bool mp_hal_is_interrupted(void) {
return MP_STATE_VM(mp_pending_exception) != NULL;
Expand Down
1 change: 0 additions & 1 deletion lib/utils/interrupt_char.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

extern int mp_interrupt_char;
void mp_hal_set_interrupt_char(int c);
void mp_keyboard_interrupt(void);
bool mp_hal_is_interrupted(void);

#endif // MICROPY_INCLUDED_LIB_UTILS_INTERRUPT_CHAR_H
14 changes: 7 additions & 7 deletions ports/atmel-samd/bindings/samd/Clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ MP_DEFINE_CONST_FUN_OBJ_1(samd_clock_get_enabled_obj, samd_clock_get_enabled);
const mp_obj_property_t samd_clock_enabled_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&samd_clock_get_enabled_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj,},
MP_ROM_NONE,
MP_ROM_NONE,},
};

//| parent: Union[Clock, None]
Expand Down Expand Up @@ -85,8 +85,8 @@ MP_DEFINE_CONST_FUN_OBJ_1(samd_clock_get_parent_obj, samd_clock_get_parent);
const mp_obj_property_t samd_clock_parent_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&samd_clock_get_parent_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj,},
MP_ROM_NONE,
MP_ROM_NONE,},
};

//| frequency: int
Expand All @@ -102,8 +102,8 @@ MP_DEFINE_CONST_FUN_OBJ_1(samd_clock_get_frequency_obj, samd_clock_get_frequency
const mp_obj_property_t samd_clock_frequency_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&samd_clock_get_frequency_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj,},
MP_ROM_NONE,
MP_ROM_NONE,},
};

//| calibration: int
Expand Down Expand Up @@ -134,7 +134,7 @@ const mp_obj_property_t samd_clock_calibration_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&samd_clock_get_calibration_obj,
(mp_obj_t)&samd_clock_set_calibration_obj,
(mp_obj_t)&mp_const_none_obj,},
MP_ROM_NONE,},
};

STATIC const mp_rom_map_elem_t samd_clock_locals_dict_table[] = {
Expand Down
10 changes: 5 additions & 5 deletions ports/raspberrypi/bindings/rp2pio/StateMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ const mp_obj_property_t rp2pio_statemachine_frequency_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&rp2pio_statemachine_get_frequency_obj,
(mp_obj_t)&rp2pio_statemachine_set_frequency_obj,
(mp_obj_t)&mp_const_none_obj},
MP_ROM_NONE},
};

//| rxstall: bool
Expand All @@ -550,8 +550,8 @@ MP_DEFINE_CONST_FUN_OBJ_1(rp2pio_statemachine_get_rxstall_obj, rp2pio_statemachi
const mp_obj_property_t rp2pio_statemachine_rxstall_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&rp2pio_statemachine_get_rxstall_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj},
MP_ROM_NONE,
MP_ROM_NONE},
};

//| in_waiting: int
Expand All @@ -568,8 +568,8 @@ MP_DEFINE_CONST_FUN_OBJ_1(rp2pio_statemachine_get_in_waiting_obj, rp2pio_statema
const mp_obj_property_t rp2pio_statemachine_in_waiting_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&rp2pio_statemachine_get_in_waiting_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj},
MP_ROM_NONE,
MP_ROM_NONE},
};

STATIC const mp_rom_map_elem_t rp2pio_statemachine_locals_dict_table[] = {
Expand Down
1 change: 0 additions & 1 deletion ports/unix/variants/dev/mpconfigvariant.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ PROG ?= micropython-dev

FROZEN_MANIFEST ?= $(VARIANT_DIR)/manifest.py

MICROPY_ROM_TEXT_COMPRESSION = 1
MICROPY_VFS_FAT = 1
MICROPY_VFS_LFS1 = 1
MICROPY_VFS_LFS2 = 1
Expand Down
1 change: 0 additions & 1 deletion ports/unix/variants/minimal/mpconfigvariant.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ PROG = micropython-minimal

FROZEN_MANIFEST =

MICROPY_ROM_TEXT_COMPRESSION = 1
MICROPY_PY_BTREE = 0
MICROPY_PY_FFI = 0
MICROPY_PY_SOCKET = 0
Expand Down
4 changes: 2 additions & 2 deletions py/bc.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ void mp_setup_code_state(mp_code_state_t *code_state, size_t n_args, size_t n_kw
mp_obj_t wanted_arg_name = kwargs[2 * i];
if (MP_UNLIKELY(!mp_obj_is_qstr(wanted_arg_name))) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError(translate("unexpected keyword argument"));
mp_raise_TypeError(MP_ERROR_TEXT("unexpected keyword argument"));
#else
mp_raise_TypeError(translate("keywords must be strings"));
mp_raise_TypeError(MP_ERROR_TEXT("keywords must be strings"));
#endif
}
for (size_t j = 0; j < n_pos_args + n_kwonly_args; j++) {
Expand Down
4 changes: 2 additions & 2 deletions py/builtinimport.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,10 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
} else {
// couldn't find the file, so fail
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_ImportError(translate("module not found"));
mp_raise_ImportError(MP_ERROR_TEXT("module not found"));
#else
mp_raise_msg_varg(&mp_type_ImportError,
translate("no module named '%q'"), mod_name);
MP_ERROR_TEXT("no module named '%q'"), mod_name);
#endif
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion py/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1801,7 +1801,7 @@ STATIC bool compile_require_async_context(compiler_t *comp, mp_parse_node_struct
return true;
}
compile_syntax_error(comp, (mp_parse_node_t)pns,
translate("'await', 'async for' or 'async with' outside async function"));
MP_ERROR_TEXT("'await', 'async for' or 'async with' outside async function"));
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion py/enum.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ mp_obj_t cp_enum_find(const mp_obj_type_t *type, int value) {

int cp_enum_value(const mp_obj_type_t *type, mp_obj_t *obj) {
if (!mp_obj_is_type(obj, type)) {
mp_raise_TypeError_varg(translate("Expected a %q"), type->name);
mp_raise_TypeError_varg(MP_ERROR_TEXT("Expected a %q"), type->name);
}
return ((cp_enum_obj_t *)MP_OBJ_TO_PTR(obj))->value;
}
Expand Down
46 changes: 0 additions & 46 deletions py/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,50 +275,4 @@ typedef union _mp_float_union_t {

#endif // MICROPY_PY_BUILTINS_FLOAT

/** ROM string compression *************/

#if MICROPY_ROM_TEXT_COMPRESSION

#ifdef NO_QSTR

// Compression enabled but doing QSTR extraction.
// 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.

// Force usage of the MP_ERROR_TEXT macro by requiring an opaque type.
typedef struct {} *mp_rom_error_text_t;

#include <string.h>

inline __attribute__((always_inline)) const char *MP_COMPRESSED_ROM_TEXT(const char *msg) {
// "genhdr/compressed.data.h" contains an invocation of the MP_MATCH_COMPRESSED macro for each compressed string.
// The giant if(strcmp) tree is optimized by the compiler, which turns this into a direct return of the compressed data.
#define MP_MATCH_COMPRESSED(a, b) if (strcmp(msg, a) == 0) { return b; } else

// It also contains a single invocation of the MP_COMPRESSED_DATA macro, we don't need that here.
#define MP_COMPRESSED_DATA(x)

#include "genhdr/compressed.data.h"

#undef MP_COMPRESSED_DATA
#undef MP_MATCH_COMPRESSED

return msg;
}

#endif

#else

// Compression not enabled, just make it a no-op.

typedef const char *mp_rom_error_text_t;
#define MP_COMPRESSED_ROM_TEXT(x) x

#endif // MICROPY_ROM_TEXT_COMPRESSION

#endif // MICROPY_INCLUDED_PY_MISC_H
2 changes: 1 addition & 1 deletion py/modstruct.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ STATIC void struct_pack_into_internal(mp_obj_t fmt_in, byte *p, size_t n_args, c
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_ValueError(NULL);
#else
mp_raise_ValueError_varg(translate("pack expected %d items for packing (got %d)"), count, n_args);
mp_raise_ValueError_varg(MP_ERROR_TEXT("pack expected %d items for packing (got %d)"), count, n_args);
#endif
}
const char *fmt = mp_obj_str_get_str(fmt_in);
Expand Down
2 changes: 1 addition & 1 deletion py/nativeglue.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ typedef struct _mp_fun_table_t {
#if defined(__GNUC__)
NORETURN // Only certain compilers support no-return attributes in function pointer declarations
#endif
void (*raise_msg)(const mp_obj_type_t *exc_type, mp_rom_error_text_t msg);
void (*raise_msg_str)(const mp_obj_type_t *exc_type, const char *msg);
const mp_obj_type_t *(*obj_get_type)(mp_const_obj_t o_in);
mp_obj_t (*obj_new_str)(const char *data, size_t len);
mp_obj_t (*obj_new_bytes)(const byte *data, size_t len);
Expand Down
8 changes: 4 additions & 4 deletions py/obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,17 @@ void mp_obj_print_exception(const mp_print_t *print, mp_obj_t exc) {
if (n > 0) {
assert(n % 3 == 0);
// Decompress the format strings
const compressed_string_t *traceback = translate("Traceback (most recent call last):\n");
const compressed_string_t *traceback = MP_ERROR_TEXT("Traceback (most recent call last):\n");
char decompressed[decompress_length(traceback)];
decompress(traceback, decompressed);
#if MICROPY_ENABLE_SOURCE_LINE
const compressed_string_t *frame = translate(" File \"%q\", line %d");
const compressed_string_t *frame = MP_ERROR_TEXT(" File \"%q\", line %d");
#else
const compressed_string_t *frame = translate(" File \"%q\"");
const compressed_string_t *frame = MP_ERROR_TEXT(" File \"%q\"");
#endif
char decompressed_frame[decompress_length(frame)];
decompress(frame, decompressed_frame);
const compressed_string_t *block_fmt = translate(", in %q\n");
const compressed_string_t *block_fmt = MP_ERROR_TEXT(", in %q\n");
char decompressed_block[decompress_length(block_fmt)];
decompress(block_fmt, decompressed_block);

Expand Down
4 changes: 2 additions & 2 deletions py/obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ typedef struct _mp_rom_obj_t { mp_const_obj_t o; } mp_rom_obj_t;
const mp_obj_property_t obj_name = { \
.base.type = &mp_type_property, \
.proxy = {(mp_obj_t)&fun_name##_obj, \
(mp_obj_t)&mp_const_none_obj, \
(mp_obj_t)&mp_const_none_obj}, }
MP_ROM_NONE, \
MP_ROM_NONE}, }

// These macros are used to define constant or mutable map/dict objects
// You can put "static" in front of the definition to make it local
Expand Down
10 changes: 5 additions & 5 deletions py/objarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ STATIC void array_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t
#if MICROPY_PY_BUILTINS_BYTEARRAY || MICROPY_PY_ARRAY
STATIC mp_obj_array_t *array_new(char typecode, size_t n) {
if (typecode == 'x') {
mp_raise_ValueError(translate("bad typecode"));
mp_raise_ValueError(MP_ERROR_TEXT("bad typecode"));
}
int typecode_size = mp_binary_get_size('@', typecode, NULL);
mp_obj_array_t *o = m_new_obj(mp_obj_array_t);
Expand Down Expand Up @@ -134,7 +134,7 @@ STATIC mp_obj_t array_construct(char typecode, mp_obj_t initializer) {
// construct array from raw bytes
size_t sz = mp_binary_get_size('@', typecode, NULL);
if (bufinfo.len % sz) {
mp_raise_ValueError(translate("bytes length not a multiple of item size"));
mp_raise_ValueError(MP_ERROR_TEXT("bytes length not a multiple of item size"));
}
size_t len = bufinfo.len / sz;
mp_obj_array_t *o = array_new(typecode, len);
Expand Down Expand Up @@ -249,7 +249,7 @@ STATIC mp_obj_t memoryview_cast(const mp_obj_t self_in, const mp_obj_t typecode_
size_t element_size = mp_binary_get_size('@', typecode[0], NULL);
size_t bytelen = self->len * mp_binary_get_size('@', self->typecode & ~MP_OBJ_ARRAY_TYPECODE_FLAG_RW, NULL);
if (bytelen % element_size != 0) {
mp_raise_TypeError(translate("memoryview: length is not a multiple of itemsize"));
mp_raise_TypeError(MP_ERROR_TEXT("memoryview: length is not a multiple of itemsize"));
}
mp_obj_array_t *result = MP_OBJ_TO_PTR(mp_obj_new_memoryview(*typecode, bytelen / element_size, self->items));

Expand Down Expand Up @@ -458,7 +458,7 @@ STATIC mp_obj_t buffer_finder(size_t n_args, const mp_obj_t *args, int direction
mp_get_buffer_raise(args[1], &needle_bufinfo, MP_BUFFER_READ);

if (mp_binary_get_size('@', needle_bufinfo.typecode, NULL) != 1) {
mp_raise_TypeError(translate("a bytes-like object is required"));
mp_raise_TypeError(MP_ERROR_TEXT("a bytes-like object is required"));
}

const byte *start = haystack_bufinfo.buf;
Expand All @@ -477,7 +477,7 @@ STATIC mp_obj_t buffer_finder(size_t n_args, const mp_obj_t *args, int direction

if (p == NULL) {
if (is_index) {
mp_raise_ValueError(translate("substring not found"));
mp_raise_ValueError(MP_ERROR_TEXT("substring not found"));
} else {
return MP_OBJ_NEW_SMALL_INT(-1);
}
Expand Down
4 changes: 0 additions & 4 deletions py/objexcept.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,11 +465,7 @@ mp_obj_t mp_obj_new_exception_msg_vlist(const mp_obj_type_t *exc_type, const com

// Create the string object and call mp_obj_exception_make_new to create the exception
o_str->base.type = &mp_type_str;
#if MICROPY_ROM_TEXT_COMPRESSION
o_str->hash = 0; // will be computed only if string object is accessed
#else
o_str->hash = qstr_compute_hash(o_str->data, o_str->len);
#endif
mp_obj_t arg = MP_OBJ_FROM_PTR(o_str);
return mp_obj_exception_make_new(exc_type, 1, &arg, NULL);
}
Expand Down
3 changes: 1 addition & 2 deletions py/objgenerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,7 @@ STATIC mp_obj_t gen_instance_await(mp_obj_t self_in) {
if (!self->coroutine_generator) {
// Pretend like a generator does not have this coroutine behavior.
// Pay no attention to the dir() behind the curtain
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_AttributeError,
translate("type object 'generator' has no attribute '__await__'")));
mp_raise_AttributeError(MP_ERROR_TEXT("type object 'generator' has no attribute '__await__'"));
}
// You can directly call send on a coroutine generator or you can __await__ then send on the return of that.
return self;
Expand Down
8 changes: 4 additions & 4 deletions py/objint.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ mp_obj_t mp_obj_new_int_from_float(mp_float_t val) {
if (u.p.exp == ((1 << MP_FLOAT_EXP_BITS) - 1)) {
// ...then number is Inf (positive or negative) if fraction is 0, else NaN.
if (u.p.frc == 0) {
mp_raise_OverflowError_varg(translate("can't convert %q to %q"), MP_QSTR_inf, MP_QSTR_int);
mp_raise_OverflowError_varg(MP_ERROR_TEXT("can't convert %q to %q"), MP_QSTR_inf, MP_QSTR_int);
} else {
mp_raise_ValueError_varg(translate("can't convert %q to %q"), MP_QSTR_NaN, MP_QSTR_int);
mp_raise_ValueError_varg(MP_ERROR_TEXT("can't convert %q to %q"), MP_QSTR_NaN, MP_QSTR_int);
}
} else {
mp_fp_as_int_class_t icl = mp_classify_fp_as_int(val);
Expand Down Expand Up @@ -332,7 +332,7 @@ void mp_obj_int_buffer_overflow_check(mp_obj_t self_in, size_t nbytes, bool is_s
}
}

mp_raise_OverflowError_varg(translate("value must fit in %d byte(s)"), nbytes);
mp_raise_OverflowError_varg(MP_ERROR_TEXT("value must fit in %d byte(s)"), nbytes);
}

#endif // MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
Expand Down Expand Up @@ -368,7 +368,7 @@ void mp_small_int_buffer_overflow_check(mp_int_t val, size_t nbytes, bool is_sig
// Fall through to failure.
}

mp_raise_OverflowError_varg(translate("value must fit in %d byte(s)"), nbytes);
mp_raise_OverflowError_varg(MP_ERROR_TEXT("value must fit in %d byte(s)"), nbytes);
}

#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE
Expand Down
2 changes: 1 addition & 1 deletion py/objint_mpz.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ mp_obj_t mp_obj_int_pow3(mp_obj_t base, mp_obj_t exponent, mp_obj_t modulus) {
mpz_t *mod = mp_mpz_for_int(modulus, &m_temp);

if (mpz_is_zero(mod)) {
mp_raise_msg(&mp_type_ValueError, translate("pow() 3rd argument cannot be 0"));
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("pow() 3rd argument cannot be 0"));
}

mpz_pow3_inpl(&(res_p->mpz), lhs, rhs, mod);
Expand Down
Loading

0 comments on commit 3fda0c0

Please sign in to comment.