all: Convert nlr_raise(mp_obj_new_exception_msg(x)) to mp_raise_msg(x).

This helper function was added a while ago and these are the remaining
cases to convert, to save a bit of code size.
This commit is contained in:
Damien George 2019-11-05 11:33:03 +11:00
parent 80df377e95
commit c13f9f209d
19 changed files with 30 additions and 35 deletions

View File

@ -558,7 +558,7 @@ STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_ob
uint val_type = GET_TYPE(arr_sz, VAL_TYPE_BITS);
arr_sz &= VALUE_MASK(VAL_TYPE_BITS);
if (index >= arr_sz) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_IndexError, "struct: index out of range"));
mp_raise_msg(&mp_type_IndexError, "struct: index out of range");
}
if (t->len == 2) {

View File

@ -81,7 +81,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 = uheapq_get_heap(heap_in);
if (heap->len == 0) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_IndexError, "empty heap"));
mp_raise_msg(&mp_type_IndexError, "empty heap");
}
mp_obj_t item = heap->items[0];
heap->len -= 1;

View File

@ -142,7 +142,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_utimeq_heappush_obj, 4, 4, mod_ut
STATIC mp_obj_t mod_utimeq_heappop(mp_obj_t heap_in, mp_obj_t list_ref) {
mp_obj_utimeq_t *heap = utimeq_get_heap(heap_in);
if (heap->len == 0) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_IndexError, "empty heap"));
mp_raise_msg(&mp_type_IndexError, "empty heap");
}
mp_obj_list_t *ret = MP_OBJ_TO_PTR(list_ref);
if (!mp_obj_is_type(list_ref, &mp_type_list) || ret->len < 3) {
@ -167,7 +167,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_utimeq_heappop_obj, mod_utimeq_heappop);
STATIC mp_obj_t mod_utimeq_peektime(mp_obj_t heap_in) {
mp_obj_utimeq_t *heap = utimeq_get_heap(heap_in);
if (heap->len == 0) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_IndexError, "empty heap"));
mp_raise_msg(&mp_type_IndexError, "empty heap");
}
struct qentry *item = &heap->items[0];

View File

@ -196,7 +196,7 @@ STATIC mp_obj_t network_cyw43_scan(size_t n_args, const mp_obj_t *pos_args, mp_m
int scan_res = cyw43_wifi_scan(self->cyw, &opts, MP_OBJ_TO_PTR(res), network_cyw43_scan_cb);
if (scan_res < 0) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "STA must be active"));
mp_raise_msg(&mp_type_OSError, "STA must be active");
}
// Wait for scan to finish, with a 10s timeout

View File

@ -44,7 +44,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, "I/O operation on closed file"));
mp_raise_msg(&mp_type_ValueError, "I/O operation on closed file");
}
}
#else

View File

@ -48,7 +48,7 @@ STATIC mp_obj_t esp32_wake_on_touch(const mp_obj_t wake) {
if (machine_rtc_config.ext0_pin != -1) {
mp_raise_ValueError("no resources");
}
//nlr_raise(mp_obj_new_exception_msg(&mp_type_RuntimeError, "touchpad wakeup not available for this version of ESP-IDF"));
//mp_raise_msg(&mp_type_RuntimeError, "touchpad wakeup not available for this version of ESP-IDF");
machine_rtc_config.wake_on_touch = mp_obj_is_true(wake);
return mp_const_none;
@ -74,7 +74,7 @@ STATIC mp_obj_t esp32_wake_on_ext0(size_t n_args, const mp_obj_t *pos_args, mp_m
gpio_num_t pin_id = machine_pin_get_id(args[ARG_pin].u_obj);
if (pin_id != machine_rtc_config.ext0_pin) {
if (!RTC_IS_VALID_EXT_PIN(pin_id)) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "invalid pin"));
mp_raise_msg(&mp_type_ValueError, "invalid pin");
}
machine_rtc_config.ext0_pin = pin_id;
}
@ -109,7 +109,7 @@ STATIC mp_obj_t esp32_wake_on_ext1(size_t n_args, const mp_obj_t *pos_args, mp_m
gpio_num_t pin_id = machine_pin_get_id(elem[i]);
if (!RTC_IS_VALID_EXT_PIN(pin_id)) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "invalid pin"));
mp_raise_msg(&mp_type_ValueError, "invalid pin");
break;
}
ext1_pins |= (1ll << pin_id);

View File

@ -119,7 +119,7 @@ STATIC mp_obj_t machine_sleep_helper(wake_type_t wake_type, size_t n_args, const
if (machine_rtc_config.wake_on_touch) {
if (esp_sleep_enable_touchpad_wakeup() != ESP_OK) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_RuntimeError, "esp_sleep_enable_touchpad_wakeup() failed"));
mp_raise_msg(&mp_type_RuntimeError, "esp_sleep_enable_touchpad_wakeup() failed");
}
}

View File

@ -233,7 +233,7 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) {
/*void error_check(bool status, const char *msg) {
if (!status) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, msg));
mp_raise_msg(&mp_type_OSError, msg);
}
}
*/
@ -441,7 +441,7 @@ STATIC mp_obj_t esp_scan(mp_obj_t self_in) {
wifi_mode_t mode;
ESP_EXCEPTIONS(esp_wifi_get_mode(&mode));
if ((mode & WIFI_MODE_STA) == 0) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "STA must be active"));
mp_raise_msg(&mp_type_OSError, "STA must be active");
}
mp_obj_t list = mp_obj_new_list(0, NULL);

View File

@ -27,6 +27,7 @@
#include "stdio.h"
#include "py/runtime.h"
#include "py/gc.h"
#include "py/mpthread.h"
#include "py/mphal.h"
@ -135,7 +136,7 @@ void mp_thread_create_ex(void *(*entry)(void*), void *arg, size_t *stack_size, i
BaseType_t result = xTaskCreatePinnedToCore(freertos_entry, name, *stack_size / sizeof(StackType_t), arg, priority, &th->id, MP_TASK_COREID);
if (result != pdPASS) {
mp_thread_mutex_unlock(&thread_mutex);
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "can't create thread"));
mp_raise_msg(&mp_type_OSError, "can't create thread");
}
// adjust the stack_size to provide room to recover from hitting the limit

View File

@ -149,8 +149,7 @@ void ets_event_poll(void) {
void __assert_func(const char *file, int line, const char *func, const char *expr) {
printf("assert:%s:%d:%s: %s\n", file, line, func, expr);
nlr_raise(mp_obj_new_exception_msg(&mp_type_AssertionError,
"C-level assert"));
mp_raise_msg(&mp_type_AssertionError, "C-level assert");
}
void mp_hal_signal_input(void) {

View File

@ -384,7 +384,7 @@ STATIC mp_obj_t pyb_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
if (self->phys_port >= 16) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "pin does not have IRQ capabilities"));
mp_raise_msg(&mp_type_OSError, "pin does not have IRQ capabilities");
}
if (n_args > 1 || kw_args->used != 0) {

View File

@ -43,7 +43,7 @@
void error_check(bool status, const char *msg) {
if (!status) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, msg));
mp_raise_msg(&mp_type_OSError, msg);
}
}

View File

@ -229,8 +229,7 @@ STATIC void esp_scan_cb(void *result, STATUS status) {
STATIC mp_obj_t esp_scan(mp_obj_t self_in) {
require_if(self_in, STATION_IF);
if ((wifi_get_opmode() & STATION_MODE) == 0) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError,
"STA must be active"));
mp_raise_msg(&mp_type_OSError, "STA must be active");
}
mp_obj_t list = mp_obj_new_list(0, NULL);
esp_scan_list = &list;
@ -247,7 +246,7 @@ STATIC mp_obj_t esp_scan(mp_obj_t self_in) {
ets_loop_iter();
}
if (list == MP_OBJ_NULL) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "scan failed"));
mp_raise_msg(&mp_type_OSError, "scan failed");
}
return list;
}
@ -313,8 +312,7 @@ STATIC mp_obj_t esp_ifconfig(size_t n_args, const mp_obj_t *args) {
wifi_softap_dhcps_stop();
}
if (!wifi_set_ip_info(self->if_id, &info)) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError,
"wifi_set_ip_info() failed"));
mp_raise_msg(&mp_type_OSError, "wifi_set_ip_info() failed");
}
dns_setserver(0, &dns_addr);
if (restart_dhcp_server) {

View File

@ -227,8 +227,7 @@ STATIC mp_obj_t microbit_image_make_new(const mp_obj_type_t *type_in, mp_uint_t
return image_from_parsed_str(str, len);
}
} else {
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
"Image(s) takes a string."));
mp_raise_msg(&mp_type_TypeError, "Image(s) takes a string.");
}
}
@ -259,8 +258,7 @@ STATIC mp_obj_t microbit_image_make_new(const mp_obj_type_t *type_in, mp_uint_t
}
default: {
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
"Image() takes 0 to 3 arguments"));
mp_raise_msg(&mp_type_TypeError, "Image() takes 0 to 3 arguments");
}
}
}
@ -365,7 +363,7 @@ MP_DEFINE_CONST_FUN_OBJ_3(microbit_image_get_pixel_obj, microbit_image_get_pixel
/* Raise an exception if not mutable */
static void check_mutability(microbit_image_obj_t *self) {
if (self->base.five) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "image cannot be modified (try copying first)"));
mp_raise_msg(&mp_type_TypeError, "image cannot be modified (try copying first)");
}
}
@ -408,11 +406,10 @@ mp_obj_t microbit_image_blit(mp_uint_t n_args, const mp_obj_t *args) {
mp_obj_t src = args[1];
if (mp_obj_get_type(src) != &microbit_image_type) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "expecting an image"));
mp_raise_msg(&mp_type_TypeError, "expecting an image");
}
if (n_args == 7) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
"must specify both offsets"));
mp_raise_msg(&mp_type_TypeError, "must specify both offsets");
}
mp_int_t x = mp_obj_get_int(args[2]);
mp_int_t y = mp_obj_get_int(args[3]);

View File

@ -119,7 +119,7 @@ mp_obj_t mod_network_find_nic(const uint8_t *ip) {
return nic;
}
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "no available NIC"));
mp_raise_msg(&mp_type_OSError, "no available NIC");
}
STATIC mp_obj_t network_route(void) {

View File

@ -443,7 +443,7 @@ STATIC mp_obj_t cc3k_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
ReadWlanInterruptPin, SpiResumeSpi, SpiPauseSpi, WriteWlanPin);
if (wlan_start(0) != 0) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "failed to init CC3000 module"));
mp_raise_msg(&mp_type_OSError, "failed to init CC3000 module");
}
// set connection policy. this should be called explicitly by the user

View File

@ -425,7 +425,7 @@ STATIC mp_obj_t mod_usocket_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) {
}
if (!have_ip) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "no available NIC"));
mp_raise_msg(&mp_type_OSError, "no available NIC");
}
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(5, NULL));

View File

@ -75,7 +75,7 @@ void mp_thread_create(void *(*entry)(void*), void *arg, size_t *stack_size) {
uint32_t id = pyb_thread_new(th, stack, stack_len, entry, arg);
if (id == 0) {
mp_thread_mutex_unlock(&thread_mutex);
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "can't create thread"));
mp_raise_msg(&mp_type_OSError, "can't create thread");
}
mp_thread_mutex_unlock(&thread_mutex);

View File

@ -137,7 +137,7 @@ STATIC mp_fp_as_int_class_t mp_classify_fp_as_int(mp_float_t val) {
mp_obj_t mp_obj_new_int_from_float(mp_float_t val) {
int cl = fpclassify(val);
if (cl == FP_INFINITE) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OverflowError, "can't convert inf to int"));
mp_raise_msg(&mp_type_OverflowError, "can't convert inf to int");
} else if (cl == FP_NAN) {
mp_raise_ValueError("can't convert NaN to int");
} else {