aboutsummaryrefslogtreecommitdiff
path: root/ports/nrf/modules
diff options
context:
space:
mode:
authorAyke van Laethem2018-07-18 15:25:17 +0200
committerAyke van Laethem2018-07-18 15:25:17 +0200
commit2f0f4fdcd34ecfe16cb9a39bfc070ad8a6329ea0 (patch)
tree4f1e03fcd6568fbebc8d915e8438c349308e84bb /ports/nrf/modules
parent4117a3d672df8686fb06df421bd07d5ce882ae56 (diff)
nrf: Use mp_raise_ValueError instead of nlr_raise(...)
Saves 60 bytes on the nRF52 with SD disabled. There will be a bigger saving with SD enabled and/or on the micro:bit board.
Diffstat (limited to 'ports/nrf/modules')
-rw-r--r--ports/nrf/modules/random/modrandom.c12
-rw-r--r--ports/nrf/modules/ubluepy/ubluepy_characteristic.c3
-rw-r--r--ports/nrf/modules/ubluepy/ubluepy_service.c9
-rw-r--r--ports/nrf/modules/ubluepy/ubluepy_uuid.c6
-rw-r--r--ports/nrf/modules/uos/microbitfs.c5
5 files changed, 14 insertions, 21 deletions
diff --git a/ports/nrf/modules/random/modrandom.c b/ports/nrf/modules/random/modrandom.c
index ffa77acf3..f60c1b753 100644
--- a/ports/nrf/modules/random/modrandom.c
+++ b/ports/nrf/modules/random/modrandom.c
@@ -91,7 +91,7 @@ static inline int randbelow(int n) {
STATIC mp_obj_t mod_random_getrandbits(mp_obj_t num_in) {
int n = mp_obj_get_int(num_in);
if (n > 30 || n == 0) {
- nlr_raise(mp_obj_new_exception(&mp_type_ValueError));
+ mp_raise_ValueError(NULL);
}
uint32_t mask = ~0;
// Beware of C undefined behavior when shifting by >= than bit size
@@ -107,7 +107,7 @@ STATIC mp_obj_t mod_random_randrange(size_t n_args, const mp_obj_t *args) {
if (start > 0) {
return mp_obj_new_int(randbelow(start));
} else {
- nlr_raise(mp_obj_new_exception(&mp_type_ValueError));
+ mp_raise_ValueError(NULL);
}
} else {
mp_int_t stop = mp_obj_get_int(args[1]);
@@ -116,7 +116,7 @@ STATIC mp_obj_t mod_random_randrange(size_t n_args, const mp_obj_t *args) {
if (start < stop) {
return mp_obj_new_int(start + randbelow(stop - start));
} else {
- nlr_raise(mp_obj_new_exception(&mp_type_ValueError));
+ mp_raise_ValueError(NULL);
}
} else {
// range(start, stop, step)
@@ -127,12 +127,12 @@ STATIC mp_obj_t mod_random_randrange(size_t n_args, const mp_obj_t *args) {
} else if (step < 0) {
n = (stop - start + step + 1) / step;
} else {
- nlr_raise(mp_obj_new_exception(&mp_type_ValueError));
+ mp_raise_ValueError(NULL);
}
if (n > 0) {
return mp_obj_new_int(start + step * randbelow(n));
} else {
- nlr_raise(mp_obj_new_exception(&mp_type_ValueError));
+ mp_raise_ValueError(NULL);
}
}
}
@@ -145,7 +145,7 @@ STATIC mp_obj_t mod_random_randint(mp_obj_t a_in, mp_obj_t b_in) {
if (a <= b) {
return mp_obj_new_int(a + randbelow(b - a + 1));
} else {
- nlr_raise(mp_obj_new_exception(&mp_type_ValueError));
+ mp_raise_ValueError(NULL);
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_random_randint_obj, mod_random_randint);
diff --git a/ports/nrf/modules/ubluepy/ubluepy_characteristic.c b/ports/nrf/modules/ubluepy/ubluepy_characteristic.c
index 8e1d0eb1e..e271132cb 100644
--- a/ports/nrf/modules/ubluepy/ubluepy_characteristic.c
+++ b/ports/nrf/modules/ubluepy/ubluepy_characteristic.c
@@ -63,8 +63,7 @@ STATIC mp_obj_t ubluepy_characteristic_make_new(const mp_obj_type_t *type, size_
s->p_uuid = MP_OBJ_TO_PTR(uuid_obj);
// (void)sd_characterstic_add(s);
} else {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
- "Invalid UUID parameter"));
+ mp_raise_ValueError("Invalid UUID parameter");
}
if (args[1].u_int > 0) {
diff --git a/ports/nrf/modules/ubluepy/ubluepy_service.c b/ports/nrf/modules/ubluepy/ubluepy_service.c
index 68d905743..e83ed1f22 100644
--- a/ports/nrf/modules/ubluepy/ubluepy_service.c
+++ b/ports/nrf/modules/ubluepy/ubluepy_service.c
@@ -68,15 +68,13 @@ STATIC mp_obj_t ubluepy_service_make_new(const mp_obj_type_t *type, size_t n_arg
if (type > 0 && type <= UBLUEPY_SERVICE_PRIMARY) {
s->type = type;
} else {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
- "Invalid Service type"));
+ mp_raise_ValueError("Invalid Service type");
}
(void)ble_drv_service_add(s);
} else {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
- "Invalid UUID parameter"));
+ mp_raise_ValueError("Invalid UUID parameter");
}
// clear reference to peripheral
@@ -127,8 +125,7 @@ STATIC mp_obj_t service_get_characteristic(mp_obj_t self_in, mp_obj_t uuid) {
// validate that there is an UUID object passed in as parameter
if (!(MP_OBJ_IS_TYPE(uuid, &ubluepy_uuid_type))) {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
- "Invalid UUID parameter"));
+ mp_raise_ValueError("Invalid UUID parameter");
}
mp_obj_t * chars = NULL;
diff --git a/ports/nrf/modules/ubluepy/ubluepy_uuid.c b/ports/nrf/modules/ubluepy/ubluepy_uuid.c
index 380d2e404..98dba912a 100644
--- a/ports/nrf/modules/ubluepy/ubluepy_uuid.c
+++ b/ports/nrf/modules/ubluepy/ubluepy_uuid.c
@@ -122,8 +122,7 @@ STATIC mp_obj_t ubluepy_uuid_make_new(const mp_obj_type_t *type, size_t n_args,
ble_drv_uuid_add_vs(buffer, &s->uuid_vs_idx);
} else {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
- "Invalid UUID string length"));
+ mp_raise_ValueError("Invalid UUID string length");
}
} else if (MP_OBJ_IS_TYPE(uuid_obj, &ubluepy_uuid_type)) {
// deep copy instance
@@ -132,8 +131,7 @@ STATIC mp_obj_t ubluepy_uuid_make_new(const mp_obj_type_t *type, size_t n_args,
s->value[0] = p_old->value[0];
s->value[1] = p_old->value[1];
} else {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
- "Invalid UUID parameter"));
+ mp_raise_ValueError("Invalid UUID parameter");
}
return MP_OBJ_FROM_PTR(s);
diff --git a/ports/nrf/modules/uos/microbitfs.c b/ports/nrf/modules/uos/microbitfs.c
index 7acc9c52d..928dc5c50 100644
--- a/ports/nrf/modules/uos/microbitfs.c
+++ b/ports/nrf/modules/uos/microbitfs.c
@@ -32,7 +32,6 @@
#include "microbitfs.h"
#include "drivers/flash.h"
#include "modrandom.h"
-#include "py/nlr.h"
#include "py/obj.h"
#include "py/stream.h"
#include "py/runtime.h"
@@ -390,7 +389,7 @@ STATIC mp_obj_t microbit_remove(mp_obj_t filename) {
STATIC void check_file_open(file_descriptor_obj *self) {
if (!self->open) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "I/O operation on closed file"));
+ mp_raise_ValueError("I/O operation on closed file");
}
}
@@ -680,7 +679,7 @@ mp_obj_t uos_mbfs_open(size_t n_args, const mp_obj_t *args) {
}
return res;
mode_error:
- nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "illegal mode"));
+ mp_raise_ValueError("illegal mode");
}
STATIC mp_obj_t uos_mbfs_stat(mp_obj_t filename) {