py: Add mp_raise_type helper macro and use it where appropriate.

This provides a more consistent C-level API to raise exceptions, ie moving
away from nlr_raise towards mp_raise_XXX.  It also reduces code size by a
small amount on some ports.
This commit is contained in:
Damien George
2020-02-11 13:17:41 +11:00
parent 7679e3be96
commit 97eca38c4f
12 changed files with 17 additions and 16 deletions

View File

@@ -147,7 +147,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset);
STATIC mp_obj_t machine_soft_reset(void) {
pyexec_system_exit = PYEXEC_FORCED_EXIT;
nlr_raise(mp_obj_new_exception(&mp_type_SystemExit));
mp_raise_type(&mp_type_SystemExit);
}
MP_DEFINE_CONST_FUN_OBJ_0(machine_soft_reset_obj, machine_soft_reset);

View File

@@ -155,7 +155,7 @@ STATIC mp_obj_t mod_random_choice(mp_obj_t seq) {
if (len > 0) {
return mp_obj_subscr(seq, mp_obj_new_int(randbelow(len)), MP_OBJ_SENTINEL);
} else {
nlr_raise(mp_obj_new_exception(&mp_type_IndexError));
mp_raise_type(&mp_type_IndexError);
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_random_choice_obj, mod_random_choice);