Use mp_raise instead of nlr_raise(new_exception) where possible
This saves a bit of code space
This commit is contained in:
parent
0556f9f851
commit
d5f6748d1b
@ -21,7 +21,7 @@
|
||||
STATIC uintptr_t machine_mem_get_addr(mp_obj_t addr_o, uint align) {
|
||||
uintptr_t addr = mp_obj_int_get_truncated(addr_o);
|
||||
if ((addr & (align - 1)) != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, translate("address %08x is not aligned to %d bytes"), addr, align));
|
||||
mp_raise_ValueError_varg(translate("address %08x is not aligned to %d bytes"), addr, align);
|
||||
}
|
||||
return addr;
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_uheapq_heappush_obj, mod_uheapq_heappush);
|
||||
STATIC mp_obj_t mod_uheapq_heappop(mp_obj_t heap_in) {
|
||||
mp_obj_list_t *heap = get_heap(heap_in);
|
||||
if (heap->len == 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_IndexError, translate("empty heap")));
|
||||
mp_raise_IndexError(translate("empty heap"));
|
||||
}
|
||||
mp_obj_t item = heap->items[0];
|
||||
heap->len -= 1;
|
||||
|
@ -24,7 +24,7 @@ typedef struct _mp_obj_vfs_posix_file_t {
|
||||
#ifdef MICROPY_CPYTHON_COMPAT
|
||||
STATIC void check_fd_is_open(const mp_obj_vfs_posix_file_t *o) {
|
||||
if (o->fd < 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, translate("I/O operation on closed file")));
|
||||
mp_raise_ValueError(translate("I/O operation on closed file"));
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
4
py/bc.c
4
py/bc.c
@ -214,8 +214,8 @@ void mp_setup_code_state(mp_code_state_t *code_state, size_t n_args, size_t n_kw
|
||||
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||
mp_raise_TypeError(translate("unexpected keyword argument"));
|
||||
#else
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||
translate("unexpected keyword argument '%q'"), MP_OBJ_QSTR_VALUE(wanted_arg_name)));
|
||||
mp_raise_TypeError_varg(
|
||||
translate("unexpected keyword argument '%q'"), MP_OBJ_QSTR_VALUE(wanted_arg_name));
|
||||
#endif
|
||||
}
|
||||
mp_obj_dict_store(dict, kwargs[2 * i], kwargs[2 * i + 1]);
|
||||
|
@ -2134,10 +2134,8 @@ STATIC NORETURN void bad_implicit_conversion(mp_obj_t self_in) {
|
||||
mp_raise_TypeError(translate("can't convert to str implicitly"));
|
||||
} else {
|
||||
const qstr src_name = mp_obj_get_type_qstr(self_in);
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||
translate("can't convert '%q' object to %q implicitly"),
|
||||
src_name, src_name == MP_QSTR_str ? MP_QSTR_bytes : MP_QSTR_str));
|
||||
}
|
||||
mp_raise_TypeError_varg(translate("can't convert '%q' object to %q implicitly"),
|
||||
src_name, src_name == MP_QSTR_str ? MP_QSTR_bytes : MP_QSTR_str);
|
||||
}
|
||||
|
||||
// use this if you will anyway convert the string to a qstr
|
||||
|
Loading…
Reference in New Issue
Block a user