Skip to content

Commit d5f6748

Browse files
committed
Use mp_raise instead of nlr_raise(new_exception) where possible
This saves a bit of code space
1 parent 0556f9f commit d5f6748

File tree

5 files changed

+7
-9
lines changed

5 files changed

+7
-9
lines changed

extmod/machine_mem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
STATIC uintptr_t machine_mem_get_addr(mp_obj_t addr_o, uint align) {
2222
uintptr_t addr = mp_obj_int_get_truncated(addr_o);
2323
if ((addr & (align - 1)) != 0) {
24-
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, translate("address %08x is not aligned to %d bytes"), addr, align));
24+
mp_raise_ValueError_varg(translate("address %08x is not aligned to %d bytes"), addr, align);
2525
}
2626
return addr;
2727
}

extmod/moduheapq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_uheapq_heappush_obj, mod_uheapq_heappush);
6262
STATIC mp_obj_t mod_uheapq_heappop(mp_obj_t heap_in) {
6363
mp_obj_list_t *heap = get_heap(heap_in);
6464
if (heap->len == 0) {
65-
nlr_raise(mp_obj_new_exception_msg(&mp_type_IndexError, translate("empty heap")));
65+
mp_raise_IndexError(translate("empty heap"));
6666
}
6767
mp_obj_t item = heap->items[0];
6868
heap->len -= 1;

extmod/vfs_posix_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ typedef struct _mp_obj_vfs_posix_file_t {
2424
#ifdef MICROPY_CPYTHON_COMPAT
2525
STATIC void check_fd_is_open(const mp_obj_vfs_posix_file_t *o) {
2626
if (o->fd < 0) {
27-
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, translate("I/O operation on closed file")));
27+
mp_raise_ValueError(translate("I/O operation on closed file"));
2828
}
2929
}
3030
#else

py/bc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ void mp_setup_code_state(mp_code_state_t *code_state, size_t n_args, size_t n_kw
214214
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
215215
mp_raise_TypeError(translate("unexpected keyword argument"));
216216
#else
217-
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
218-
translate("unexpected keyword argument '%q'"), MP_OBJ_QSTR_VALUE(wanted_arg_name)));
217+
mp_raise_TypeError_varg(
218+
translate("unexpected keyword argument '%q'"), MP_OBJ_QSTR_VALUE(wanted_arg_name));
219219
#endif
220220
}
221221
mp_obj_dict_store(dict, kwargs[2 * i], kwargs[2 * i + 1]);

py/objstr.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,10 +2134,8 @@ STATIC NORETURN void bad_implicit_conversion(mp_obj_t self_in) {
21342134
mp_raise_TypeError(translate("can't convert to str implicitly"));
21352135
} else {
21362136
const qstr src_name = mp_obj_get_type_qstr(self_in);
2137-
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
2138-
translate("can't convert '%q' object to %q implicitly"),
2139-
src_name, src_name == MP_QSTR_str ? MP_QSTR_bytes : MP_QSTR_str));
2140-
}
2137+
mp_raise_TypeError_varg(translate("can't convert '%q' object to %q implicitly"),
2138+
src_name, src_name == MP_QSTR_str ? MP_QSTR_bytes : MP_QSTR_str);
21412139
}
21422140

21432141
// use this if you will anyway convert the string to a qstr

0 commit comments

Comments
 (0)