py: Use mp_raise_msg helper function where appropriate.
Saves the following number of bytes of code space: 176 for bare-arm, 352 for minimal, 272 for unix x86-64, 140 for stmhal, 120 for esp8266.
This commit is contained in:
parent
6caca3259f
commit
7d0d7215d2
@ -37,8 +37,7 @@ void mp_arg_check_num(size_t n_args, size_t n_kw, size_t n_args_min, size_t n_ar
|
|||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
mp_arg_error_terse_mismatch();
|
mp_arg_error_terse_mismatch();
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
mp_raise_msg(&mp_type_TypeError, "function does not take keyword arguments");
|
||||||
"function does not take keyword arguments"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,8 +115,7 @@ void mp_arg_parse_all(size_t n_pos, const mp_obj_t *pos, mp_map_t *kws, size_t n
|
|||||||
mp_arg_error_terse_mismatch();
|
mp_arg_error_terse_mismatch();
|
||||||
} else {
|
} else {
|
||||||
// TODO better error message
|
// TODO better error message
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
mp_raise_msg(&mp_type_TypeError, "extra positional arguments given");
|
||||||
"extra positional arguments given"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (kws_found < kws->used) {
|
if (kws_found < kws->used) {
|
||||||
@ -125,8 +123,7 @@ void mp_arg_parse_all(size_t n_pos, const mp_obj_t *pos, mp_map_t *kws, size_t n
|
|||||||
mp_arg_error_terse_mismatch();
|
mp_arg_error_terse_mismatch();
|
||||||
} else {
|
} else {
|
||||||
// TODO better error message
|
// TODO better error message
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
mp_raise_msg(&mp_type_TypeError, "extra keyword arguments given");
|
||||||
"extra keyword arguments given"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -139,7 +136,7 @@ void mp_arg_parse_all_kw_array(size_t n_pos, size_t n_kw, const mp_obj_t *args,
|
|||||||
|
|
||||||
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE || _MSC_VER
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE || _MSC_VER
|
||||||
NORETURN void mp_arg_error_terse_mismatch(void) {
|
NORETURN void mp_arg_error_terse_mismatch(void) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "argument num/types mismatch"));
|
mp_raise_msg(&mp_type_TypeError, "argument num/types mismatch");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
5
py/bc.c
5
py/bc.c
@ -185,7 +185,7 @@ void mp_setup_code_state(mp_code_state_t *code_state, mp_obj_fun_bc_t *self, siz
|
|||||||
}
|
}
|
||||||
// Didn't find name match with positional args
|
// Didn't find name match with positional args
|
||||||
if ((scope_flags & MP_SCOPE_FLAG_VARKEYWORDS) == 0) {
|
if ((scope_flags & MP_SCOPE_FLAG_VARKEYWORDS) == 0) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "function does not take keyword arguments"));
|
mp_raise_msg(&mp_type_TypeError, "function does not take keyword arguments");
|
||||||
}
|
}
|
||||||
mp_obj_dict_store(dict, kwargs[2 * i], kwargs[2 * i + 1]);
|
mp_obj_dict_store(dict, kwargs[2 * i], kwargs[2 * i + 1]);
|
||||||
continue2:;
|
continue2:;
|
||||||
@ -234,8 +234,7 @@ continue2:;
|
|||||||
} else {
|
} else {
|
||||||
// no keyword arguments given
|
// no keyword arguments given
|
||||||
if (n_kwonly_args != 0) {
|
if (n_kwonly_args != 0) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
mp_raise_msg(&mp_type_TypeError, "function missing keyword-only argument");
|
||||||
"function missing keyword-only argument"));
|
|
||||||
}
|
}
|
||||||
if ((scope_flags & MP_SCOPE_FLAG_VARKEYWORDS) != 0) {
|
if ((scope_flags & MP_SCOPE_FLAG_VARKEYWORDS) != 0) {
|
||||||
*var_pos_kw_args = mp_obj_new_dict(0);
|
*var_pos_kw_args = mp_obj_new_dict(0);
|
||||||
|
@ -95,7 +95,7 @@ STATIC mp_obj_t mp_builtin_compile(size_t n_args, const mp_obj_t *args) {
|
|||||||
case MP_QSTR_exec: parse_input_kind = MP_PARSE_FILE_INPUT; break;
|
case MP_QSTR_exec: parse_input_kind = MP_PARSE_FILE_INPUT; break;
|
||||||
case MP_QSTR_eval: parse_input_kind = MP_PARSE_EVAL_INPUT; break;
|
case MP_QSTR_eval: parse_input_kind = MP_PARSE_EVAL_INPUT; break;
|
||||||
default:
|
default:
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "bad compile mode"));
|
mp_raise_msg(&mp_type_ValueError, "bad compile mode");
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_code_t *code = m_new_obj(mp_obj_code_t);
|
mp_obj_code_t *code = m_new_obj(mp_obj_code_t);
|
||||||
|
@ -138,7 +138,7 @@ STATIC void do_load_from_lexer(mp_obj_t module_obj, mp_lexer_t *lex, const char
|
|||||||
if (lex == NULL) {
|
if (lex == NULL) {
|
||||||
// we verified the file exists using stat, but lexer could still fail
|
// we verified the file exists using stat, but lexer could still fail
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ImportError, "module not found"));
|
mp_raise_msg(&mp_type_ImportError, "module not found");
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ImportError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ImportError,
|
||||||
"no module named '%s'", fname));
|
"no module named '%s'", fname));
|
||||||
@ -340,7 +340,7 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
|
|||||||
DEBUG_printf("Warning: no dots in current module name and level>0\n");
|
DEBUG_printf("Warning: no dots in current module name and level>0\n");
|
||||||
p = this_name + this_name_l;
|
p = this_name + this_name_l;
|
||||||
} else if (level != -1) {
|
} else if (level != -1) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ImportError, "Invalid relative import"));
|
mp_raise_msg(&mp_type_ImportError, "invalid relative import");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint new_mod_l = (mod_len == 0 ? (size_t)(p - this_name) : (size_t)(p - this_name) + 1 + mod_len);
|
uint new_mod_l = (mod_len == 0 ? (size_t)(p - this_name) : (size_t)(p - this_name) + 1 + mod_len);
|
||||||
@ -355,7 +355,7 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
|
|||||||
DEBUG_printf("Resolved base name for relative import: '%s'\n", qstr_str(new_mod_q));
|
DEBUG_printf("Resolved base name for relative import: '%s'\n", qstr_str(new_mod_q));
|
||||||
if (new_mod_q == MP_QSTR_) {
|
if (new_mod_q == MP_QSTR_) {
|
||||||
// CPython raises SystemError
|
// CPython raises SystemError
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ImportError, "cannot perform relative import"));
|
mp_raise_msg(&mp_type_ImportError, "cannot perform relative import");
|
||||||
}
|
}
|
||||||
module_name = MP_OBJ_NEW_QSTR(new_mod_q);
|
module_name = MP_OBJ_NEW_QSTR(new_mod_q);
|
||||||
mod_str = new_mod;
|
mod_str = new_mod;
|
||||||
@ -425,7 +425,7 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
|
|||||||
#endif
|
#endif
|
||||||
// couldn't find the file, so fail
|
// couldn't find the file, so fail
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ImportError, "module not found"));
|
mp_raise_msg(&mp_type_ImportError, "module not found");
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ImportError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ImportError,
|
||||||
"no module named '%q'", mod_name));
|
"no module named '%q'", mod_name));
|
||||||
|
@ -178,7 +178,7 @@ STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) {
|
|||||||
str[3] = (c & 0x3F) | 0x80;
|
str[3] = (c & 0x3F) | 0x80;
|
||||||
len = 4;
|
len = 4;
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "chr() arg not in range(0x110000)"));
|
mp_raise_msg(&mp_type_ValueError, "chr() arg not in range(0x110000)");
|
||||||
}
|
}
|
||||||
return mp_obj_new_str(str, len, true);
|
return mp_obj_new_str(str, len, true);
|
||||||
#else
|
#else
|
||||||
@ -187,7 +187,7 @@ STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) {
|
|||||||
char str[1] = {ord};
|
char str[1] = {ord};
|
||||||
return mp_obj_new_str(str, 1, true);
|
return mp_obj_new_str(str, 1, true);
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "chr() arg not in range(256)"));
|
mp_raise_msg(&mp_type_ValueError, "chr() arg not in range(256)");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -286,7 +286,7 @@ STATIC mp_obj_t mp_builtin_min_max(size_t n_args, const mp_obj_t *args, mp_map_t
|
|||||||
if (default_elem != NULL) {
|
if (default_elem != NULL) {
|
||||||
best_obj = default_elem->value;
|
best_obj = default_elem->value;
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "arg is an empty sequence"));
|
mp_raise_msg(&mp_type_ValueError, "arg is an empty sequence");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return best_obj;
|
return best_obj;
|
||||||
@ -507,8 +507,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_sum_obj, 1, 2, mp_builtin_sum);
|
|||||||
|
|
||||||
STATIC mp_obj_t mp_builtin_sorted(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
|
STATIC mp_obj_t mp_builtin_sorted(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
|
||||||
if (n_args > 1) {
|
if (n_args > 1) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
mp_raise_msg(&mp_type_TypeError, "must use keyword argument for key function");
|
||||||
"must use keyword argument for key function"));
|
|
||||||
}
|
}
|
||||||
mp_obj_t self = mp_type_list.make_new(&mp_type_list, 1, 0, args);
|
mp_obj_t self = mp_type_list.make_new(&mp_type_list, 1, 0, args);
|
||||||
mp_obj_list_sort(1, &self, kwargs);
|
mp_obj_list_sort(1, &self, kwargs);
|
||||||
|
@ -239,7 +239,7 @@ STATIC mp_obj_t mod_thread_start_new_thread(size_t n_args, const mp_obj_t *args)
|
|||||||
} else {
|
} else {
|
||||||
// positional and keyword arguments
|
// positional and keyword arguments
|
||||||
if (mp_obj_get_type(args[2]) != &mp_type_dict) {
|
if (mp_obj_get_type(args[2]) != &mp_type_dict) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "expecting a dict for keyword args"));
|
mp_raise_msg(&mp_type_TypeError, "expecting a dict for keyword args");
|
||||||
}
|
}
|
||||||
mp_map_t *map = &((mp_obj_dict_t*)MP_OBJ_TO_PTR(args[2]))->map;
|
mp_map_t *map = &((mp_obj_dict_t*)MP_OBJ_TO_PTR(args[2]))->map;
|
||||||
th_args = m_new_obj_var(thread_entry_args_t, mp_obj_t, pos_args_len + 2 * map->used);
|
th_args = m_new_obj_var(thread_entry_args_t, mp_obj_t, pos_args_len + 2 * map->used);
|
||||||
|
31
py/obj.c
31
py/obj.c
@ -233,8 +233,7 @@ mp_int_t mp_obj_get_int(mp_const_obj_t arg) {
|
|||||||
return mp_obj_int_get_checked(arg);
|
return mp_obj_int_get_checked(arg);
|
||||||
} else {
|
} else {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
mp_raise_msg(&mp_type_TypeError, "can't convert to int");
|
||||||
"can't convert to int"));
|
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||||
"can't convert %s to int", mp_obj_get_type_str(arg)));
|
"can't convert %s to int", mp_obj_get_type_str(arg)));
|
||||||
@ -282,8 +281,7 @@ mp_float_t mp_obj_get_float(mp_obj_t arg) {
|
|||||||
return mp_obj_float_get(arg);
|
return mp_obj_float_get(arg);
|
||||||
} else {
|
} else {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
mp_raise_msg(&mp_type_TypeError, "can't convert to float");
|
||||||
"can't convert to float"));
|
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||||
"can't convert %s to float", mp_obj_get_type_str(arg)));
|
"can't convert %s to float", mp_obj_get_type_str(arg)));
|
||||||
@ -312,8 +310,7 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) {
|
|||||||
mp_obj_complex_get(arg, real, imag);
|
mp_obj_complex_get(arg, real, imag);
|
||||||
} else {
|
} else {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
mp_raise_msg(&mp_type_TypeError, "can't convert to complex");
|
||||||
"can't convert to complex"));
|
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||||
"can't convert %s to complex", mp_obj_get_type_str(arg)));
|
"can't convert %s to complex", mp_obj_get_type_str(arg)));
|
||||||
@ -331,8 +328,7 @@ void mp_obj_get_array(mp_obj_t o, mp_uint_t *len, mp_obj_t **items) {
|
|||||||
mp_obj_list_get(o, len, items);
|
mp_obj_list_get(o, len, items);
|
||||||
} else {
|
} else {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
mp_raise_msg(&mp_type_TypeError, "expected tuple/list");
|
||||||
"expected tuple/list"));
|
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||||
"object '%s' is not a tuple or list", mp_obj_get_type_str(o)));
|
"object '%s' is not a tuple or list", mp_obj_get_type_str(o)));
|
||||||
@ -346,8 +342,7 @@ void mp_obj_get_array_fixed_n(mp_obj_t o, mp_uint_t len, mp_obj_t **items) {
|
|||||||
mp_obj_get_array(o, &seq_len, items);
|
mp_obj_get_array(o, &seq_len, items);
|
||||||
if (seq_len != len) {
|
if (seq_len != len) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
|
mp_raise_msg(&mp_type_ValueError, "tuple/list has wrong length");
|
||||||
"tuple/list has wrong length"));
|
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
|
||||||
"requested length %d but object has length %d", (int)len, (int)seq_len));
|
"requested length %d but object has length %d", (int)len, (int)seq_len));
|
||||||
@ -362,8 +357,7 @@ mp_uint_t mp_get_index(const mp_obj_type_t *type, mp_uint_t len, mp_obj_t index,
|
|||||||
i = MP_OBJ_SMALL_INT_VALUE(index);
|
i = MP_OBJ_SMALL_INT_VALUE(index);
|
||||||
} else if (!mp_obj_get_int_maybe(index, &i)) {
|
} else if (!mp_obj_get_int_maybe(index, &i)) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
mp_raise_msg(&mp_type_TypeError, "indices must be integers");
|
||||||
"indices must be integers"));
|
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||||
"%q indices must be integers, not %s",
|
"%q indices must be integers, not %s",
|
||||||
@ -383,7 +377,7 @@ mp_uint_t mp_get_index(const mp_obj_type_t *type, mp_uint_t len, mp_obj_t index,
|
|||||||
} else {
|
} else {
|
||||||
if (i < 0 || (mp_uint_t)i >= len) {
|
if (i < 0 || (mp_uint_t)i >= len) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_IndexError, "index out of range"));
|
mp_raise_msg(&mp_type_IndexError, "index out of range");
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_IndexError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_IndexError,
|
||||||
"%q index out of range", type->name));
|
"%q index out of range", type->name));
|
||||||
@ -416,8 +410,7 @@ mp_obj_t mp_obj_len(mp_obj_t o_in) {
|
|||||||
mp_obj_t len = mp_obj_len_maybe(o_in);
|
mp_obj_t len = mp_obj_len_maybe(o_in);
|
||||||
if (len == MP_OBJ_NULL) {
|
if (len == MP_OBJ_NULL) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
mp_raise_msg(&mp_type_TypeError, "object has no len");
|
||||||
"object has no len"));
|
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||||
"object of type '%s' has no len()", mp_obj_get_type_str(o_in)));
|
"object of type '%s' has no len()", mp_obj_get_type_str(o_in)));
|
||||||
@ -458,8 +451,7 @@ mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
|
|||||||
}
|
}
|
||||||
if (value == MP_OBJ_NULL) {
|
if (value == MP_OBJ_NULL) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
mp_raise_msg(&mp_type_TypeError, "object does not support item deletion");
|
||||||
"object does not support item deletion"));
|
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||||
"'%s' object does not support item deletion", mp_obj_get_type_str(base)));
|
"'%s' object does not support item deletion", mp_obj_get_type_str(base)));
|
||||||
@ -474,8 +466,7 @@ mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
mp_raise_msg(&mp_type_TypeError, "object does not support item assignment");
|
||||||
"object does not support item assignment"));
|
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||||
"'%s' object does not support item assignment", mp_obj_get_type_str(base)));
|
"'%s' object does not support item assignment", mp_obj_get_type_str(base)));
|
||||||
@ -504,7 +495,7 @@ bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
|
|||||||
|
|
||||||
void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
|
void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
|
||||||
if (!mp_get_buffer(obj, bufinfo, flags)) {
|
if (!mp_get_buffer(obj, bufinfo, flags)) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "object with buffer protocol required"));
|
mp_raise_msg(&mp_type_TypeError, "object with buffer protocol required");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ STATIC void array_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t
|
|||||||
STATIC mp_obj_array_t *array_new(char typecode, mp_uint_t n) {
|
STATIC mp_obj_array_t *array_new(char typecode, mp_uint_t n) {
|
||||||
int typecode_size = mp_binary_get_size('@', typecode, NULL);
|
int typecode_size = mp_binary_get_size('@', typecode, NULL);
|
||||||
if (typecode_size == 0) {
|
if (typecode_size == 0) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "bad typecode"));
|
mp_raise_msg(&mp_type_ValueError, "bad typecode");
|
||||||
}
|
}
|
||||||
mp_obj_array_t *o = m_new_obj(mp_obj_array_t);
|
mp_obj_array_t *o = m_new_obj(mp_obj_array_t);
|
||||||
#if MICROPY_PY_BUILTINS_BYTEARRAY && MICROPY_PY_ARRAY
|
#if MICROPY_PY_BUILTINS_BYTEARRAY && MICROPY_PY_ARRAY
|
||||||
@ -395,7 +395,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
|
|||||||
mp_obj_array_t *src_slice = MP_OBJ_TO_PTR(value);
|
mp_obj_array_t *src_slice = MP_OBJ_TO_PTR(value);
|
||||||
if (item_sz != mp_binary_get_size('@', src_slice->typecode & TYPECODE_MASK, NULL)) {
|
if (item_sz != mp_binary_get_size('@', src_slice->typecode & TYPECODE_MASK, NULL)) {
|
||||||
compat_error:
|
compat_error:
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "lhs and rhs should be compatible"));
|
mp_raise_msg(&mp_type_ValueError, "lhs and rhs should be compatible");
|
||||||
}
|
}
|
||||||
src_len = src_slice->len;
|
src_len = src_slice->len;
|
||||||
src_items = src_slice->items;
|
src_items = src_slice->items;
|
||||||
|
@ -197,7 +197,7 @@ mp_obj_t mp_obj_complex_binary_op(mp_uint_t op, mp_float_t lhs_real, mp_float_t
|
|||||||
case MP_BINARY_OP_INPLACE_TRUE_DIVIDE:
|
case MP_BINARY_OP_INPLACE_TRUE_DIVIDE:
|
||||||
if (rhs_imag == 0) {
|
if (rhs_imag == 0) {
|
||||||
if (rhs_real == 0) {
|
if (rhs_real == 0) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ZeroDivisionError, "complex division by zero"));
|
mp_raise_msg(&mp_type_ZeroDivisionError, "complex division by zero");
|
||||||
}
|
}
|
||||||
lhs_real /= rhs_real;
|
lhs_real /= rhs_real;
|
||||||
lhs_imag /= rhs_real;
|
lhs_imag /= rhs_real;
|
||||||
@ -226,7 +226,7 @@ mp_obj_t mp_obj_complex_binary_op(mp_uint_t op, mp_float_t lhs_real, mp_float_t
|
|||||||
lhs_real = 1;
|
lhs_real = 1;
|
||||||
rhs_real = 0;
|
rhs_real = 0;
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ZeroDivisionError, "0.0 to a complex power"));
|
mp_raise_msg(&mp_type_ZeroDivisionError, "0.0 to a complex power");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mp_float_t ln1 = MICROPY_FLOAT_C_FUN(log)(abs1);
|
mp_float_t ln1 = MICROPY_FLOAT_C_FUN(log)(abs1);
|
||||||
|
@ -343,7 +343,7 @@ STATIC mp_obj_t dict_popitem(mp_obj_t self_in) {
|
|||||||
mp_uint_t cur = 0;
|
mp_uint_t cur = 0;
|
||||||
mp_map_elem_t *next = dict_iter_next(self, &cur);
|
mp_map_elem_t *next = dict_iter_next(self, &cur);
|
||||||
if (next == NULL) {
|
if (next == NULL) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_KeyError, "popitem(): dictionary is empty"));
|
mp_raise_msg(&mp_type_KeyError, "popitem(): dictionary is empty");
|
||||||
}
|
}
|
||||||
self->map.used--;
|
self->map.used--;
|
||||||
mp_obj_t items[] = {next->key, next->value};
|
mp_obj_t items[] = {next->key, next->value};
|
||||||
@ -385,9 +385,7 @@ STATIC mp_obj_t dict_update(size_t n_args, const mp_obj_t *args, mp_map_t *kwarg
|
|||||||
if (key == MP_OBJ_STOP_ITERATION
|
if (key == MP_OBJ_STOP_ITERATION
|
||||||
|| value == MP_OBJ_STOP_ITERATION
|
|| value == MP_OBJ_STOP_ITERATION
|
||||||
|| stop != MP_OBJ_STOP_ITERATION) {
|
|| stop != MP_OBJ_STOP_ITERATION) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(
|
mp_raise_msg(&mp_type_ValueError, "dictionary update sequence has the wrong length");
|
||||||
&mp_type_ValueError,
|
|
||||||
"dictionary update sequence has the wrong length"));
|
|
||||||
} else {
|
} else {
|
||||||
mp_map_lookup(&self->map, key, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)->value = value;
|
mp_map_lookup(&self->map, key, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)->value = value;
|
||||||
}
|
}
|
||||||
|
@ -198,7 +198,7 @@ mp_obj_t mp_obj_float_binary_op(mp_uint_t op, mp_float_t lhs_val, mp_obj_t rhs_i
|
|||||||
case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE:
|
case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE:
|
||||||
if (rhs_val == 0) {
|
if (rhs_val == 0) {
|
||||||
zero_division_error:
|
zero_division_error:
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ZeroDivisionError, "division by zero"));
|
mp_raise_msg(&mp_type_ZeroDivisionError, "division by zero");
|
||||||
}
|
}
|
||||||
// Python specs require that x == (x//y)*y + (x%y) so we must
|
// Python specs require that x == (x//y)*y + (x%y) so we must
|
||||||
// call divmod to compute the correct floor division, which
|
// call divmod to compute the correct floor division, which
|
||||||
|
@ -105,7 +105,7 @@ mp_vm_return_kind_t mp_obj_gen_resume(mp_obj_t self_in, mp_obj_t send_value, mp_
|
|||||||
}
|
}
|
||||||
if (self->code_state.sp == self->code_state.state - 1) {
|
if (self->code_state.sp == self->code_state.state - 1) {
|
||||||
if (send_value != mp_const_none) {
|
if (send_value != mp_const_none) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "can't send non-None value to a just-started generator"));
|
mp_raise_msg(&mp_type_TypeError, "can't send non-None value to a just-started generator");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
*self->code_state.sp = send_value;
|
*self->code_state.sp = send_value;
|
||||||
@ -157,7 +157,7 @@ STATIC mp_obj_t gen_resume_and_raise(mp_obj_t self_in, mp_obj_t send_value, mp_o
|
|||||||
|
|
||||||
case MP_VM_RETURN_YIELD:
|
case MP_VM_RETURN_YIELD:
|
||||||
if (throw_value != MP_OBJ_NULL && mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(mp_obj_get_type(throw_value)), MP_OBJ_FROM_PTR(&mp_type_GeneratorExit))) {
|
if (throw_value != MP_OBJ_NULL && mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(mp_obj_get_type(throw_value)), MP_OBJ_FROM_PTR(&mp_type_GeneratorExit))) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_RuntimeError, "generator ignored GeneratorExit"));
|
mp_raise_msg(&mp_type_RuntimeError, "generator ignored GeneratorExit");
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
@ -209,7 +209,7 @@ STATIC mp_obj_t gen_instance_close(mp_obj_t self_in) {
|
|||||||
mp_obj_t ret;
|
mp_obj_t ret;
|
||||||
switch (mp_obj_gen_resume(self_in, mp_const_none, MP_OBJ_FROM_PTR(&mp_const_GeneratorExit_obj), &ret)) {
|
switch (mp_obj_gen_resume(self_in, mp_const_none, MP_OBJ_FROM_PTR(&mp_const_GeneratorExit_obj), &ret)) {
|
||||||
case MP_VM_RETURN_YIELD:
|
case MP_VM_RETURN_YIELD:
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_RuntimeError, "generator ignored GeneratorExit"));
|
mp_raise_msg(&mp_type_RuntimeError, "generator ignored GeneratorExit");
|
||||||
|
|
||||||
// Swallow StopIteration & GeneratorExit (== successful close), and re-raise any other
|
// Swallow StopIteration & GeneratorExit (== successful close), and re-raise any other
|
||||||
case MP_VM_RETURN_EXCEPTION:
|
case MP_VM_RETURN_EXCEPTION:
|
||||||
|
10
py/objint.c
10
py/objint.c
@ -294,19 +294,19 @@ mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
|
|||||||
|
|
||||||
// This is called only with strings whose value doesn't fit in SMALL_INT
|
// This is called only with strings whose value doesn't fit in SMALL_INT
|
||||||
mp_obj_t mp_obj_new_int_from_str_len(const char **str, mp_uint_t len, bool neg, mp_uint_t base) {
|
mp_obj_t mp_obj_new_int_from_str_len(const char **str, mp_uint_t len, bool neg, mp_uint_t base) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OverflowError, "long int not supported in this build"));
|
mp_raise_msg(&mp_type_OverflowError, "long int not supported in this build");
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is called when an integer larger than a SMALL_INT is needed (although val might still fit in a SMALL_INT)
|
// This is called when an integer larger than a SMALL_INT is needed (although val might still fit in a SMALL_INT)
|
||||||
mp_obj_t mp_obj_new_int_from_ll(long long val) {
|
mp_obj_t mp_obj_new_int_from_ll(long long val) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OverflowError, "small int overflow"));
|
mp_raise_msg(&mp_type_OverflowError, "small int overflow");
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is called when an integer larger than a SMALL_INT is needed (although val might still fit in a SMALL_INT)
|
// This is called when an integer larger than a SMALL_INT is needed (although val might still fit in a SMALL_INT)
|
||||||
mp_obj_t mp_obj_new_int_from_ull(unsigned long long val) {
|
mp_obj_t mp_obj_new_int_from_ull(unsigned long long val) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OverflowError, "small int overflow"));
|
mp_raise_msg(&mp_type_OverflowError, "small int overflow");
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,7 +316,7 @@ mp_obj_t mp_obj_new_int_from_uint(mp_uint_t value) {
|
|||||||
if ((value & ~MP_SMALL_INT_POSITIVE_MASK) == 0) {
|
if ((value & ~MP_SMALL_INT_POSITIVE_MASK) == 0) {
|
||||||
return MP_OBJ_NEW_SMALL_INT(value);
|
return MP_OBJ_NEW_SMALL_INT(value);
|
||||||
}
|
}
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OverflowError, "small int overflow"));
|
mp_raise_msg(&mp_type_OverflowError, "small int overflow");
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,7 +342,7 @@ mp_obj_t mp_obj_new_int(mp_int_t value) {
|
|||||||
if (MP_SMALL_INT_FITS(value)) {
|
if (MP_SMALL_INT_FITS(value)) {
|
||||||
return MP_OBJ_NEW_SMALL_INT(value);
|
return MP_OBJ_NEW_SMALL_INT(value);
|
||||||
}
|
}
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OverflowError, "small int overflow"));
|
mp_raise_msg(&mp_type_OverflowError, "small int overflow");
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,8 +234,7 @@ mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
|
|||||||
case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE: {
|
case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE: {
|
||||||
if (mpz_is_zero(zrhs)) {
|
if (mpz_is_zero(zrhs)) {
|
||||||
zero_division_error:
|
zero_division_error:
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ZeroDivisionError,
|
mp_raise_msg(&mp_type_ZeroDivisionError, "division by zero");
|
||||||
"division by zero"));
|
|
||||||
}
|
}
|
||||||
mpz_t rem; mpz_init_zero(&rem);
|
mpz_t rem; mpz_init_zero(&rem);
|
||||||
mpz_divmod_inpl(&res->mpz, &rem, zlhs, zrhs);
|
mpz_divmod_inpl(&res->mpz, &rem, zlhs, zrhs);
|
||||||
@ -272,7 +271,7 @@ mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
|
|||||||
case MP_BINARY_OP_INPLACE_RSHIFT: {
|
case MP_BINARY_OP_INPLACE_RSHIFT: {
|
||||||
mp_int_t irhs = mp_obj_int_get_checked(rhs_in);
|
mp_int_t irhs = mp_obj_int_get_checked(rhs_in);
|
||||||
if (irhs < 0) {
|
if (irhs < 0) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "negative shift count"));
|
mp_raise_msg(&mp_type_ValueError, "negative shift count");
|
||||||
}
|
}
|
||||||
if (op == MP_BINARY_OP_LSHIFT || op == MP_BINARY_OP_INPLACE_LSHIFT) {
|
if (op == MP_BINARY_OP_LSHIFT || op == MP_BINARY_OP_INPLACE_LSHIFT) {
|
||||||
mpz_shl_inpl(&res->mpz, zlhs, irhs);
|
mpz_shl_inpl(&res->mpz, zlhs, irhs);
|
||||||
@ -398,7 +397,7 @@ mp_int_t mp_obj_int_get_checked(mp_const_obj_t self_in) {
|
|||||||
return value;
|
return value;
|
||||||
} else {
|
} else {
|
||||||
// overflow
|
// overflow
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OverflowError, "overflow converting long int to machine word"));
|
mp_raise_msg(&mp_type_OverflowError, "overflow converting long int to machine word");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -266,7 +266,7 @@ STATIC mp_obj_t list_pop(size_t n_args, const mp_obj_t *args) {
|
|||||||
mp_check_self(MP_OBJ_IS_TYPE(args[0], &mp_type_list));
|
mp_check_self(MP_OBJ_IS_TYPE(args[0], &mp_type_list));
|
||||||
mp_obj_list_t *self = MP_OBJ_TO_PTR(args[0]);
|
mp_obj_list_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||||
if (self->len == 0) {
|
if (self->len == 0) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_IndexError, "pop from empty list"));
|
mp_raise_msg(&mp_type_IndexError, "pop from empty list");
|
||||||
}
|
}
|
||||||
mp_uint_t index = mp_get_index(self->base.type, self->len, n_args == 1 ? MP_OBJ_NEW_SMALL_INT(-1) : args[1], false);
|
mp_uint_t index = mp_get_index(self->base.type, self->len, n_args == 1 ? MP_OBJ_NEW_SMALL_INT(-1) : args[1], false);
|
||||||
mp_obj_t ret = self->items[index];
|
mp_obj_t ret = self->items[index];
|
||||||
|
@ -73,7 +73,7 @@ STATIC void namedtuple_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
|||||||
} else {
|
} else {
|
||||||
// delete/store attribute
|
// delete/store attribute
|
||||||
// provide more detailed error message than we'd get by just returning
|
// provide more detailed error message than we'd get by just returning
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_AttributeError, "can't set attribute"));
|
mp_raise_msg(&mp_type_AttributeError, "can't set attribute");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,8 +50,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(object___init___obj, object___init__);
|
|||||||
|
|
||||||
STATIC mp_obj_t object___new__(mp_obj_t cls) {
|
STATIC mp_obj_t object___new__(mp_obj_t cls) {
|
||||||
if (!MP_OBJ_IS_TYPE(cls, &mp_type_type) || !mp_obj_is_instance_type((mp_obj_type_t*)MP_OBJ_TO_PTR(cls))) {
|
if (!MP_OBJ_IS_TYPE(cls, &mp_type_type) || !mp_obj_is_instance_type((mp_obj_type_t*)MP_OBJ_TO_PTR(cls))) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
mp_raise_msg(&mp_type_TypeError, "__new__ arg must be a user-type");
|
||||||
"__new__ arg must be a user-type"));
|
|
||||||
}
|
}
|
||||||
mp_obj_t o = MP_OBJ_SENTINEL;
|
mp_obj_t o = MP_OBJ_SENTINEL;
|
||||||
mp_obj_t res = mp_obj_instance_make_new(MP_OBJ_TO_PTR(cls), 1, 0, &o);
|
mp_obj_t res = mp_obj_instance_make_new(MP_OBJ_TO_PTR(cls), 1, 0, &o);
|
||||||
|
@ -68,7 +68,7 @@ STATIC void check_set(mp_obj_t o) {
|
|||||||
if (MP_OBJ_IS_TYPE(o, &mp_type_frozenset)) {
|
if (MP_OBJ_IS_TYPE(o, &mp_type_frozenset)) {
|
||||||
// Mutable method called on frozenset; emulate CPython behavior, eg:
|
// Mutable method called on frozenset; emulate CPython behavior, eg:
|
||||||
// AttributeError: 'frozenset' object has no attribute 'add'
|
// AttributeError: 'frozenset' object has no attribute 'add'
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_AttributeError, "'frozenset' has no such attribute"));
|
mp_raise_msg(&mp_type_AttributeError, "'frozenset' has no such attribute");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
mp_check_self(MP_OBJ_IS_TYPE(o, &mp_type_set));
|
mp_check_self(MP_OBJ_IS_TYPE(o, &mp_type_set));
|
||||||
@ -389,7 +389,7 @@ STATIC mp_obj_t set_pop(mp_obj_t self_in) {
|
|||||||
mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in);
|
mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
mp_obj_t obj = mp_set_remove_first(&self->set);
|
mp_obj_t obj = mp_set_remove_first(&self->set);
|
||||||
if (obj == MP_OBJ_NULL) {
|
if (obj == MP_OBJ_NULL) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_KeyError, "pop from an empty set"));
|
mp_raise_msg(&mp_type_KeyError, "pop from an empty set");
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
#if MICROPY_CPYTHON_COMPAT
|
#if MICROPY_CPYTHON_COMPAT
|
||||||
STATIC void check_stringio_is_open(const mp_obj_stringio_t *o) {
|
STATIC void check_stringio_is_open(const mp_obj_stringio_t *o) {
|
||||||
if (o->vstr == NULL) {
|
if (o->vstr == NULL) {
|
||||||
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
|
#else
|
||||||
|
21
py/objtype.c
21
py/objtype.c
@ -311,8 +311,7 @@ mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, size
|
|||||||
}
|
}
|
||||||
if (init_ret != mp_const_none) {
|
if (init_ret != mp_const_none) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
mp_raise_msg(&mp_type_TypeError, "__init__() should return None");
|
||||||
"__init__() should return None"));
|
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||||
"__init__() should return None, not '%s'", mp_obj_get_type_str(init_ret)));
|
"__init__() should return None, not '%s'", mp_obj_get_type_str(init_ret)));
|
||||||
@ -508,7 +507,7 @@ STATIC void mp_obj_instance_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *des
|
|||||||
// the code.
|
// the code.
|
||||||
const mp_obj_t *proxy = mp_obj_property_get(member);
|
const mp_obj_t *proxy = mp_obj_property_get(member);
|
||||||
if (proxy[0] == mp_const_none) {
|
if (proxy[0] == mp_const_none) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_AttributeError, "unreadable attribute"));
|
mp_raise_msg(&mp_type_AttributeError, "unreadable attribute");
|
||||||
} else {
|
} else {
|
||||||
dest[0] = mp_call_function_n_kw(proxy[0], 1, 0, &self_in);
|
dest[0] = mp_call_function_n_kw(proxy[0], 1, 0, &self_in);
|
||||||
}
|
}
|
||||||
@ -710,8 +709,7 @@ mp_obj_t mp_obj_instance_call(mp_obj_t self_in, size_t n_args, size_t n_kw, cons
|
|||||||
mp_obj_t call = mp_obj_instance_get_call(self_in);
|
mp_obj_t call = mp_obj_instance_get_call(self_in);
|
||||||
if (call == MP_OBJ_NULL) {
|
if (call == MP_OBJ_NULL) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
mp_raise_msg(&mp_type_TypeError, "object not callable");
|
||||||
"object not callable"));
|
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||||
"'%s' object is not callable", mp_obj_get_type_str(self_in)));
|
"'%s' object is not callable", mp_obj_get_type_str(self_in)));
|
||||||
@ -793,7 +791,7 @@ STATIC mp_obj_t type_make_new(const mp_obj_type_t *type_in, size_t n_args, size_
|
|||||||
return mp_obj_new_type(mp_obj_str_get_qstr(args[0]), args[1], args[2]);
|
return mp_obj_new_type(mp_obj_str_get_qstr(args[0]), args[1], args[2]);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "type takes 1 or 3 arguments"));
|
mp_raise_msg(&mp_type_TypeError, "type takes 1 or 3 arguments");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -804,7 +802,7 @@ STATIC mp_obj_t type_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp
|
|||||||
|
|
||||||
if (self->make_new == NULL) {
|
if (self->make_new == NULL) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "cannot create instance"));
|
mp_raise_msg(&mp_type_TypeError, "cannot create instance");
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||||
"cannot create '%q' instances", self->name));
|
"cannot create '%q' instances", self->name));
|
||||||
@ -892,8 +890,7 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict)
|
|||||||
// TODO: Verify with CPy, tested on function type
|
// TODO: Verify with CPy, tested on function type
|
||||||
if (t->make_new == NULL) {
|
if (t->make_new == NULL) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
mp_raise_msg(&mp_type_TypeError, "type is not an acceptable base type");
|
||||||
"type is not an acceptable base type"));
|
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||||
"type '%q' is not an acceptable base type", t->name));
|
"type '%q' is not an acceptable base type", t->name));
|
||||||
@ -927,7 +924,7 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict)
|
|||||||
const mp_obj_type_t *native_base;
|
const mp_obj_type_t *native_base;
|
||||||
uint num_native_bases = instance_count_native_bases(o, &native_base);
|
uint num_native_bases = instance_count_native_bases(o, &native_base);
|
||||||
if (num_native_bases > 1) {
|
if (num_native_bases > 1) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "multiple bases have instance lay-out conflict"));
|
mp_raise_msg(&mp_type_TypeError, "multiple bases have instance lay-out conflict");
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_map_t *locals_map = &o->locals_dict->map;
|
mp_map_t *locals_map = &o->locals_dict->map;
|
||||||
@ -1074,7 +1071,7 @@ STATIC mp_obj_t mp_obj_is_subclass(mp_obj_t object, mp_obj_t classinfo) {
|
|||||||
} else if (MP_OBJ_IS_TYPE(classinfo, &mp_type_tuple)) {
|
} else if (MP_OBJ_IS_TYPE(classinfo, &mp_type_tuple)) {
|
||||||
mp_obj_tuple_get(classinfo, &len, &items);
|
mp_obj_tuple_get(classinfo, &len, &items);
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "issubclass() arg 2 must be a class or a tuple of classes"));
|
mp_raise_msg(&mp_type_TypeError, "issubclass() arg 2 must be a class or a tuple of classes");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint i = 0; i < len; i++) {
|
for (uint i = 0; i < len; i++) {
|
||||||
@ -1088,7 +1085,7 @@ STATIC mp_obj_t mp_obj_is_subclass(mp_obj_t object, mp_obj_t classinfo) {
|
|||||||
|
|
||||||
STATIC mp_obj_t mp_builtin_issubclass(mp_obj_t object, mp_obj_t classinfo) {
|
STATIC mp_obj_t mp_builtin_issubclass(mp_obj_t object, mp_obj_t classinfo) {
|
||||||
if (!MP_OBJ_IS_TYPE(object, &mp_type_type)) {
|
if (!MP_OBJ_IS_TYPE(object, &mp_type_type)) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "issubclass() arg 1 must be a class"));
|
mp_raise_msg(&mp_type_TypeError, "issubclass() arg 1 must be a class");
|
||||||
}
|
}
|
||||||
return mp_obj_is_subclass(object, classinfo);
|
return mp_obj_is_subclass(object, classinfo);
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "py/nlr.h"
|
#include "py/runtime.h"
|
||||||
#include "py/parsenumbase.h"
|
#include "py/parsenumbase.h"
|
||||||
#include "py/parsenum.h"
|
#include "py/parsenum.h"
|
||||||
#include "py/smallint.h"
|
#include "py/smallint.h"
|
||||||
@ -55,7 +55,7 @@ mp_obj_t mp_parse_num_integer(const char *restrict str_, size_t len, int base, m
|
|||||||
// check radix base
|
// check radix base
|
||||||
if ((base != 0 && base < 2) || base > 36) {
|
if ((base != 0 && base < 2) || base > 36) {
|
||||||
// this won't be reached if lex!=NULL
|
// this won't be reached if lex!=NULL
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "int() arg 2 must be >= 2 and <= 36"));
|
mp_raise_msg(&mp_type_ValueError, "int() arg 2 must be >= 2 and <= 36");
|
||||||
}
|
}
|
||||||
|
|
||||||
// skip leading space
|
// skip leading space
|
||||||
|
53
py/runtime.c
53
py/runtime.c
@ -138,8 +138,7 @@ mp_obj_t mp_load_global(qstr qst) {
|
|||||||
elem = mp_map_lookup((mp_map_t*)&mp_module_builtins_globals.map, MP_OBJ_NEW_QSTR(qst), MP_MAP_LOOKUP);
|
elem = mp_map_lookup((mp_map_t*)&mp_module_builtins_globals.map, MP_OBJ_NEW_QSTR(qst), MP_MAP_LOOKUP);
|
||||||
if (elem == NULL) {
|
if (elem == NULL) {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_NameError,
|
mp_raise_msg(&mp_type_NameError, "name not defined");
|
||||||
"name not defined"));
|
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_NameError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_NameError,
|
||||||
"name '%q' is not defined", qst));
|
"name '%q' is not defined", qst));
|
||||||
@ -230,8 +229,7 @@ mp_obj_t mp_unary_op(mp_uint_t op, mp_obj_t arg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
mp_raise_msg(&mp_type_TypeError, "unsupported type for operator");
|
||||||
"unsupported type for operator"));
|
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||||
"unsupported type for %q: '%s'",
|
"unsupported type for %q: '%s'",
|
||||||
@ -323,7 +321,7 @@ mp_obj_t mp_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) {
|
|||||||
case MP_BINARY_OP_INPLACE_LSHIFT: {
|
case MP_BINARY_OP_INPLACE_LSHIFT: {
|
||||||
if (rhs_val < 0) {
|
if (rhs_val < 0) {
|
||||||
// negative shift not allowed
|
// negative shift not allowed
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "negative shift count"));
|
mp_raise_msg(&mp_type_ValueError, "negative shift count");
|
||||||
} else if (rhs_val >= (mp_int_t)BITS_PER_WORD || lhs_val > (MP_SMALL_INT_MAX >> rhs_val) || lhs_val < (MP_SMALL_INT_MIN >> rhs_val)) {
|
} else if (rhs_val >= (mp_int_t)BITS_PER_WORD || lhs_val > (MP_SMALL_INT_MAX >> rhs_val) || lhs_val < (MP_SMALL_INT_MIN >> rhs_val)) {
|
||||||
// left-shift will overflow, so use higher precision integer
|
// left-shift will overflow, so use higher precision integer
|
||||||
lhs = mp_obj_new_int_from_ll(lhs_val);
|
lhs = mp_obj_new_int_from_ll(lhs_val);
|
||||||
@ -338,7 +336,7 @@ mp_obj_t mp_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) {
|
|||||||
case MP_BINARY_OP_INPLACE_RSHIFT:
|
case MP_BINARY_OP_INPLACE_RSHIFT:
|
||||||
if (rhs_val < 0) {
|
if (rhs_val < 0) {
|
||||||
// negative shift not allowed
|
// negative shift not allowed
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "negative shift count"));
|
mp_raise_msg(&mp_type_ValueError, "negative shift count");
|
||||||
} else {
|
} else {
|
||||||
// standard precision is enough for right-shift
|
// standard precision is enough for right-shift
|
||||||
if (rhs_val >= (mp_int_t)BITS_PER_WORD) {
|
if (rhs_val >= (mp_int_t)BITS_PER_WORD) {
|
||||||
@ -414,7 +412,7 @@ mp_obj_t mp_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) {
|
|||||||
lhs = mp_obj_new_float(lhs_val);
|
lhs = mp_obj_new_float(lhs_val);
|
||||||
goto generic_binary_op;
|
goto generic_binary_op;
|
||||||
#else
|
#else
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "negative power with no float support"));
|
mp_raise_msg(&mp_type_ValueError, "negative power with no float support");
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
mp_int_t ans = 1;
|
mp_int_t ans = 1;
|
||||||
@ -515,8 +513,7 @@ mp_obj_t mp_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
mp_raise_msg(&mp_type_TypeError, "object not iterable");
|
||||||
"object not iterable"));
|
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||||
"'%s' object is not iterable", mp_obj_get_type_str(rhs)));
|
"'%s' object is not iterable", mp_obj_get_type_str(rhs)));
|
||||||
@ -538,8 +535,7 @@ generic_binary_op:
|
|||||||
|
|
||||||
unsupported_op:
|
unsupported_op:
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
mp_raise_msg(&mp_type_TypeError, "unsupported type for operator");
|
||||||
"unsupported type for operator"));
|
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||||
"unsupported types for %q: '%s', '%s'",
|
"unsupported types for %q: '%s', '%s'",
|
||||||
@ -547,7 +543,7 @@ unsupported_op:
|
|||||||
}
|
}
|
||||||
|
|
||||||
zero_division:
|
zero_division:
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ZeroDivisionError, "division by zero"));
|
mp_raise_msg(&mp_type_ZeroDivisionError, "division by zero");
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t mp_call_function_0(mp_obj_t fun) {
|
mp_obj_t mp_call_function_0(mp_obj_t fun) {
|
||||||
@ -581,8 +577,7 @@ mp_obj_t mp_call_function_n_kw(mp_obj_t fun_in, mp_uint_t n_args, mp_uint_t n_kw
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
mp_raise_msg(&mp_type_TypeError, "object not callable");
|
||||||
"object not callable"));
|
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||||
"'%s' object is not callable", mp_obj_get_type_str(fun_in)));
|
"'%s' object is not callable", mp_obj_get_type_str(fun_in)));
|
||||||
@ -813,16 +808,14 @@ void mp_unpack_sequence(mp_obj_t seq_in, mp_uint_t num, mp_obj_t *items) {
|
|||||||
|
|
||||||
too_short:
|
too_short:
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
|
mp_raise_msg(&mp_type_ValueError, "wrong number of values to unpack");
|
||||||
"wrong number of values to unpack"));
|
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
|
||||||
"need more than %d values to unpack", (int)seq_len));
|
"need more than %d values to unpack", (int)seq_len));
|
||||||
}
|
}
|
||||||
too_long:
|
too_long:
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
|
mp_raise_msg(&mp_type_ValueError, "wrong number of values to unpack");
|
||||||
"wrong number of values to unpack"));
|
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
|
||||||
"too many values to unpack (expected %d)", (int)num));
|
"too many values to unpack (expected %d)", (int)num));
|
||||||
@ -888,8 +881,7 @@ void mp_unpack_ex(mp_obj_t seq_in, mp_uint_t num_in, mp_obj_t *items) {
|
|||||||
|
|
||||||
too_short:
|
too_short:
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
|
mp_raise_msg(&mp_type_ValueError, "wrong number of values to unpack");
|
||||||
"wrong number of values to unpack"));
|
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
|
||||||
"need more than %d values to unpack", (int)seq_len));
|
"need more than %d values to unpack", (int)seq_len));
|
||||||
@ -928,8 +920,7 @@ STATIC mp_obj_t checked_fun_call(mp_obj_t self_in, size_t n_args, size_t n_kw, c
|
|||||||
const mp_obj_type_t *arg0_type = mp_obj_get_type(args[0]);
|
const mp_obj_type_t *arg0_type = mp_obj_get_type(args[0]);
|
||||||
if (arg0_type != self->type) {
|
if (arg0_type != self->type) {
|
||||||
if (MICROPY_ERROR_REPORTING != MICROPY_ERROR_REPORTING_DETAILED) {
|
if (MICROPY_ERROR_REPORTING != MICROPY_ERROR_REPORTING_DETAILED) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
mp_raise_msg(&mp_type_TypeError, "argument has wrong type");
|
||||||
"argument has wrong type"));
|
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||||
"argument should be a '%q' not a '%q'", self->type->name, arg0_type->name));
|
"argument should be a '%q' not a '%q'", self->type->name, arg0_type->name));
|
||||||
@ -1045,8 +1036,7 @@ void mp_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest) {
|
|||||||
if (dest[0] == MP_OBJ_NULL) {
|
if (dest[0] == MP_OBJ_NULL) {
|
||||||
// no attribute/method called attr
|
// no attribute/method called attr
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_AttributeError,
|
mp_raise_msg(&mp_type_AttributeError, "no such attribute");
|
||||||
"no such attribute"));
|
|
||||||
} else {
|
} else {
|
||||||
// following CPython, we give a more detailed error message for type objects
|
// following CPython, we give a more detailed error message for type objects
|
||||||
if (MP_OBJ_IS_TYPE(base, &mp_type_type)) {
|
if (MP_OBJ_IS_TYPE(base, &mp_type_type)) {
|
||||||
@ -1074,8 +1064,7 @@ void mp_store_attr(mp_obj_t base, qstr attr, mp_obj_t value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_AttributeError,
|
mp_raise_msg(&mp_type_AttributeError, "no such attribute");
|
||||||
"no such attribute"));
|
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_AttributeError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_AttributeError,
|
||||||
"'%s' object has no attribute '%q'",
|
"'%s' object has no attribute '%q'",
|
||||||
@ -1105,8 +1094,7 @@ mp_obj_t mp_getiter(mp_obj_t o_in) {
|
|||||||
|
|
||||||
// object not iterable
|
// object not iterable
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
mp_raise_msg(&mp_type_TypeError, "object not iterable");
|
||||||
"object not iterable"));
|
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||||
"'%s' object is not iterable", mp_obj_get_type_str(o_in)));
|
"'%s' object is not iterable", mp_obj_get_type_str(o_in)));
|
||||||
@ -1128,8 +1116,7 @@ mp_obj_t mp_iternext_allow_raise(mp_obj_t o_in) {
|
|||||||
return mp_call_method_n_kw(0, 0, dest);
|
return mp_call_method_n_kw(0, 0, dest);
|
||||||
} else {
|
} else {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
mp_raise_msg(&mp_type_TypeError, "object not an iterator");
|
||||||
"object not an iterator"));
|
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||||
"'%s' object is not an iterator", mp_obj_get_type_str(o_in)));
|
"'%s' object is not an iterator", mp_obj_get_type_str(o_in)));
|
||||||
@ -1165,8 +1152,7 @@ mp_obj_t mp_iternext(mp_obj_t o_in) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
|
mp_raise_msg(&mp_type_TypeError, "object not an iterator");
|
||||||
"object not an iterator"));
|
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||||
"'%s' object is not an iterator", mp_obj_get_type_str(o_in)));
|
"'%s' object is not an iterator", mp_obj_get_type_str(o_in)));
|
||||||
@ -1384,8 +1370,7 @@ void *m_malloc_fail(size_t num_bytes) {
|
|||||||
// dummy
|
// dummy
|
||||||
#if MICROPY_ENABLE_GC
|
#if MICROPY_ENABLE_GC
|
||||||
} else if (gc_is_locked()) {
|
} else if (gc_is_locked()) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_MemoryError,
|
mp_raise_msg(&mp_type_MemoryError, "memory allocation failed, heap is locked");
|
||||||
"memory allocation failed, heap is locked"));
|
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_MemoryError,
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_MemoryError,
|
||||||
|
@ -235,7 +235,7 @@ mp_obj_t mp_seq_index_obj(const mp_obj_t *items, mp_uint_t len, mp_uint_t n_args
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "object not in sequence"));
|
mp_raise_msg(&mp_type_ValueError, "object not in sequence");
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t mp_seq_count_obj(const mp_obj_t *items, mp_uint_t len, mp_obj_t value) {
|
mp_obj_t mp_seq_count_obj(const mp_obj_t *items, mp_uint_t len, mp_obj_t value) {
|
||||||
|
@ -101,7 +101,7 @@ const mp_stream_p_t *mp_get_stream_raise(mp_obj_t self_in, int flags) {
|
|||||||
|| ((flags & MP_STREAM_OP_WRITE) && stream_p->write == NULL)
|
|| ((flags & MP_STREAM_OP_WRITE) && stream_p->write == NULL)
|
||||||
|| ((flags & MP_STREAM_OP_IOCTL) && stream_p->ioctl == NULL)) {
|
|| ((flags & MP_STREAM_OP_IOCTL) && stream_p->ioctl == NULL)) {
|
||||||
// CPython: io.UnsupportedOperation, OSError subclass
|
// CPython: io.UnsupportedOperation, OSError subclass
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "stream operation not supported"));
|
mp_raise_msg(&mp_type_OSError, "stream operation not supported");
|
||||||
}
|
}
|
||||||
return stream_p;
|
return stream_p;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user