diff options
author | Javier Candeira <javier@candeira.com> | 2017-08-09 14:40:45 +1000 |
---|---|---|
committer | Javier Candeira <javier@candeira.com> | 2017-08-13 22:52:33 +1000 |
commit | 35a1fea90b2cae9d5cc8e9eab62ba4c67e8786db (patch) | |
tree | 26616de189a9154309287846bf76fb1cdab8ce51 /py | |
parent | b6a328956467339f568b19d9192fbbfdfa47a572 (diff) | |
download | micropython-35a1fea90b2cae9d5cc8e9eab62ba4c67e8786db.tar.gz micropython-35a1fea90b2cae9d5cc8e9eab62ba4c67e8786db.zip |
all: Raise exceptions via mp_raise_XXX
- Changed: ValueError, TypeError, NotImplementedError
- OSError invocations unchanged, because the corresponding utility
function takes ints, not strings like the long form invocation.
- OverflowError, IndexError and RuntimeError etc. not changed for now
until we decide whether to add new utility functions.
Diffstat (limited to 'py')
-rw-r--r-- | py/argcheck.c | 2 | ||||
-rw-r--r-- | py/emitnative.c | 8 | ||||
-rw-r--r-- | py/lexer.c | 2 | ||||
-rw-r--r-- | py/objarray.c | 6 | ||||
-rw-r--r-- | py/objlist.c | 4 | ||||
-rw-r--r-- | py/objstr.c | 8 | ||||
-rw-r--r-- | py/objstrunicode.c | 2 | ||||
-rw-r--r-- | py/objtuple.c | 2 | ||||
-rw-r--r-- | py/runtime.c | 2 | ||||
-rw-r--r-- | py/runtime.h | 2 |
10 files changed, 19 insertions, 19 deletions
diff --git a/py/argcheck.c b/py/argcheck.c index 22fd9cd2c7..0c5c5ca954 100644 --- a/py/argcheck.c +++ b/py/argcheck.c @@ -142,6 +142,6 @@ NORETURN void mp_arg_error_terse_mismatch(void) { #if MICROPY_CPYTHON_COMPAT NORETURN void mp_arg_error_unimpl_kw(void) { - mp_not_implemented("keyword argument(s) not yet implemented - use normal args instead"); + mp_raise_NotImplementedError("keyword argument(s) not yet implemented - use normal args instead"); } #endif diff --git a/py/emitnative.c b/py/emitnative.c index 5ed69ff9b0..7ce6196254 100644 --- a/py/emitnative.c +++ b/py/emitnative.c @@ -824,7 +824,7 @@ STATIC void emit_get_stack_pointer_to_reg_for_pop(emit_t *emit, mp_uint_t reg_de break; default: // not handled - mp_not_implemented("conversion to object"); + mp_raise_NotImplementedError("conversion to object"); } } @@ -2158,7 +2158,7 @@ STATIC void emit_native_call_function(emit_t *emit, mp_uint_t n_positional, mp_u break; default: // this can happen when casting a cast: int(int) - mp_not_implemented("casting"); + mp_raise_NotImplementedError("casting"); } } else { assert(vtype_fun == VTYPE_PYOBJ); @@ -2232,12 +2232,12 @@ STATIC void emit_native_raise_varargs(emit_t *emit, mp_uint_t n_args) { STATIC void emit_native_yield_value(emit_t *emit) { // not supported (for now) (void)emit; - mp_not_implemented("native yield"); + mp_raise_NotImplementedError("native yield"); } STATIC void emit_native_yield_from(emit_t *emit) { // not supported (for now) (void)emit; - mp_not_implemented("native yield from"); + mp_raise_NotImplementedError("native yield from"); } STATIC void emit_native_start_except_handler(emit_t *emit) { diff --git a/py/lexer.c b/py/lexer.c index 32b3567cc2..074d6f3561 100644 --- a/py/lexer.c +++ b/py/lexer.c @@ -341,7 +341,7 @@ STATIC void parse_string_literal(mp_lexer_t *lex, bool is_raw) { // 3MB of text; even gzip-compressed and with minimal structure, it'll take // roughly half a meg of storage. This form of Unicode escape may be added // later on, but it's definitely not a priority right now. -- CJA 20140607 - mp_not_implemented("unicode name escapes"); + mp_raise_NotImplementedError("unicode name escapes"); break; default: if (c >= '0' && c <= '7') { diff --git a/py/objarray.c b/py/objarray.c index 99146bd4c1..a31c536804 100644 --- a/py/objarray.c +++ b/py/objarray.c @@ -288,7 +288,7 @@ STATIC mp_obj_t array_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) // Otherwise, can only look for a scalar numeric value in an array if (MP_OBJ_IS_INT(rhs_in) || mp_obj_is_float(rhs_in)) { - mp_not_implemented(""); + mp_raise_NotImplementedError(""); } return mp_const_false; @@ -378,7 +378,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value } else if (MP_OBJ_IS_TYPE(index_in, &mp_type_slice)) { mp_bound_slice_t slice; if (!mp_seq_get_fast_slice_indexes(o->len, index_in, &slice)) { - mp_not_implemented("only slices with step=1 (aka None) are supported"); + mp_raise_NotImplementedError("only slices with step=1 (aka None) are supported"); } if (value != MP_OBJ_SENTINEL) { #if MICROPY_PY_ARRAY_SLICE_ASSIGN @@ -409,7 +409,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value src_len = bufinfo.len; src_items = bufinfo.buf; } else { - mp_not_implemented("array/bytes required on right side"); + mp_raise_NotImplementedError("array/bytes required on right side"); } // TODO: check src/dst compat diff --git a/py/objlist.c b/py/objlist.c index 5957c9d4ad..86d4300620 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -162,7 +162,7 @@ STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in); mp_bound_slice_t slice; if (!mp_seq_get_fast_slice_indexes(self->len, index, &slice)) { - mp_not_implemented(""); + mp_raise_NotImplementedError(""); } mp_int_t len_adj = slice.start - slice.stop; @@ -202,7 +202,7 @@ STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { mp_obj_get_array(value, &value_len, &value_items); mp_bound_slice_t slice_out; if (!mp_seq_get_fast_slice_indexes(self->len, index, &slice_out)) { - mp_not_implemented(""); + mp_raise_NotImplementedError(""); } mp_int_t len_adj = value_len - (slice_out.stop - slice_out.start); //printf("Len adj: %d\n", len_adj); diff --git a/py/objstr.c b/py/objstr.c index cc3dda59e5..d4c038a686 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -404,7 +404,7 @@ STATIC mp_obj_t bytes_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) { mp_bound_slice_t slice; if (!mp_seq_get_fast_slice_indexes(self_len, index, &slice)) { - mp_not_implemented("only slices with step=1 (aka None) are supported"); + mp_raise_NotImplementedError("only slices with step=1 (aka None) are supported"); } return mp_obj_new_str_of_type(type, self_data + slice.start, slice.stop - slice.start); } @@ -618,7 +618,7 @@ STATIC mp_obj_t str_rsplit(size_t n_args, const mp_obj_t *args) { mp_int_t idx = splits; if (sep == mp_const_none) { - mp_not_implemented("rsplit(None,n)"); + mp_raise_NotImplementedError("rsplit(None,n)"); } else { size_t sep_len; const char *sep_str = mp_obj_str_get_data(sep, &sep_len); @@ -742,7 +742,7 @@ STATIC mp_obj_t str_endswith(size_t n_args, const mp_obj_t *args) { GET_STR_DATA_LEN(args[0], str, str_len); GET_STR_DATA_LEN(args[1], suffix, suffix_len); if (n_args > 2) { - mp_not_implemented("start/end indices"); + mp_raise_NotImplementedError("start/end indices"); } if (suffix_len > str_len) { @@ -1044,7 +1044,7 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar arg = key_elem->value; } if (field_name < field_name_top) { - mp_not_implemented("attributes not supported yet"); + mp_raise_NotImplementedError("attributes not supported yet"); } } else { if (*arg_i < 0) { diff --git a/py/objstrunicode.c b/py/objstrunicode.c index 0cf791ff7c..036f7f3c14 100644 --- a/py/objstrunicode.c +++ b/py/objstrunicode.c @@ -188,7 +188,7 @@ STATIC mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { mp_obj_t ostart, ostop, ostep; mp_obj_slice_get(index, &ostart, &ostop, &ostep); if (ostep != mp_const_none && ostep != MP_OBJ_NEW_SMALL_INT(1)) { - mp_not_implemented("only slices with step=1 (aka None) are supported"); + mp_raise_NotImplementedError("only slices with step=1 (aka None) are supported"); } const byte *pstart, *pstop; diff --git a/py/objtuple.c b/py/objtuple.c index cbe6454943..765edb907c 100644 --- a/py/objtuple.c +++ b/py/objtuple.c @@ -181,7 +181,7 @@ mp_obj_t mp_obj_tuple_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) { mp_bound_slice_t slice; if (!mp_seq_get_fast_slice_indexes(self->len, index, &slice)) { - mp_not_implemented("only slices with step=1 (aka None) are supported"); + mp_raise_NotImplementedError("only slices with step=1 (aka None) are supported"); } mp_obj_tuple_t *res = MP_OBJ_TO_PTR(mp_obj_new_tuple(slice.stop - slice.start, NULL)); mp_seq_copy(res->items, self->items + slice.start, res->len, mp_obj_t); diff --git a/py/runtime.c b/py/runtime.c index 6a0db007e3..9c3edeb9c8 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -1439,6 +1439,6 @@ NORETURN void mp_raise_OSError(int errno_) { nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno_))); } -NORETURN void mp_not_implemented(const char *msg) { +NORETURN void mp_raise_NotImplementedError(const char *msg) { mp_raise_msg(&mp_type_NotImplementedError, msg); } diff --git a/py/runtime.h b/py/runtime.h index fe492885b1..428e2571cc 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -149,8 +149,8 @@ NORETURN void mp_raise_msg(const mp_obj_type_t *exc_type, const char *msg); //NORETURN void nlr_raise_msg_varg(const mp_obj_type_t *exc_type, const char *fmt, ...); NORETURN void mp_raise_ValueError(const char *msg); NORETURN void mp_raise_TypeError(const char *msg); +NORETURN void mp_raise_NotImplementedError(const char *msg); NORETURN void mp_raise_OSError(int errno_); -NORETURN void mp_not_implemented(const char *msg); // Raise NotImplementedError with given message NORETURN void mp_exc_recursion_depth(void); #if MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG |