aboutsummaryrefslogtreecommitdiff
path: root/extmod
diff options
context:
space:
mode:
authorDamien George2020-02-11 13:17:41 +1100
committerDamien George2020-02-13 11:03:37 +1100
commit97eca38c4f03e76bd464fb25974544a043af2a9e (patch)
tree9141a63cb6e1e414330d0a93e11ceedc955f4c27 /extmod
parent7679e3be96f7e0996faa89678beaf423d7c25999 (diff)
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.
Diffstat (limited to 'extmod')
-rw-r--r--extmod/modbtree.c4
-rw-r--r--extmod/modurandom.c2
-rw-r--r--extmod/moduzlib.c2
3 files changed, 4 insertions, 4 deletions
diff --git a/extmod/modbtree.c b/extmod/modbtree.c
index a1d576fda..ffcd5c8bd 100644
--- a/extmod/modbtree.c
+++ b/extmod/modbtree.c
@@ -256,7 +256,7 @@ STATIC mp_obj_t btree_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
key.data = (void*)mp_obj_str_get_data(index, &key.size);
int res = __bt_delete(self->db, &key, 0);
if (res == RET_SPECIAL) {
- nlr_raise(mp_obj_new_exception(&mp_type_KeyError));
+ mp_raise_type(&mp_type_KeyError);
}
CHECK_ERROR(res);
return mp_const_none;
@@ -266,7 +266,7 @@ STATIC mp_obj_t btree_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
key.data = (void*)mp_obj_str_get_data(index, &key.size);
int res = __bt_get(self->db, &key, &val, 0);
if (res == RET_SPECIAL) {
- nlr_raise(mp_obj_new_exception(&mp_type_KeyError));
+ mp_raise_type(&mp_type_KeyError);
}
CHECK_ERROR(res);
return mp_obj_new_bytes(val.data, val.size);
diff --git a/extmod/modurandom.c b/extmod/modurandom.c
index e3c7fc7f5..34fe1b749 100644
--- a/extmod/modurandom.c
+++ b/extmod/modurandom.c
@@ -154,7 +154,7 @@ STATIC mp_obj_t mod_urandom_choice(mp_obj_t seq) {
if (len > 0) {
return mp_obj_subscr(seq, mp_obj_new_int(yasmarang_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_urandom_choice_obj, mod_urandom_choice);
diff --git a/extmod/moduzlib.c b/extmod/moduzlib.c
index 64327f1f7..9d3ca7da6 100644
--- a/extmod/moduzlib.c
+++ b/extmod/moduzlib.c
@@ -61,7 +61,7 @@ STATIC int read_src_stream(TINF_DATA *data) {
mp_raise_OSError(err);
}
if (out_sz == 0) {
- nlr_raise(mp_obj_new_exception(&mp_type_EOFError));
+ mp_raise_type(&mp_type_EOFError);
}
return c;
}