41 #define TRACEBACK_ENTRY_LEN (3) 44 #define EMG_TRACEBACK_ALLOC (2 * TRACEBACK_ENTRY_LEN) 51 #if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF 52 # if MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE > 0 53 #define mp_emergency_exception_buf_size MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE 62 #define mp_emergency_exception_buf_size MP_STATE_VM(mp_emergency_exception_buf_size) 65 mp_emergency_exception_buf_size = 0;
76 int old_size = mp_emergency_exception_buf_size;
77 void *old_buf =
MP_STATE_VM(mp_emergency_exception_buf);
82 mp_emergency_exception_buf_size = size;
86 if (old_buf !=
NULL) {
92 #endif // MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF 115 }
else if (o->
args->
len == 1) {
116 #if MICROPY_PY_UERRNO 120 if (qst != MP_QSTR_NULL) {
143 o_exc->
base.type = type;
154 #if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF 158 if (o_tuple ==
NULL && mp_emergency_exception_buf_size >=
165 if (o_tuple ==
NULL) {
171 o_tuple->
len = n_args;
177 o_exc->
args = o_tuple;
185 if (self->args->len == 0) {
188 return self->args->items[0];
203 self->traceback_len = 0;
208 if (
attr == MP_QSTR_args) {
231 .
name = MP_QSTR_BaseException,
238 #define MP_DEFINE_EXCEPTION(exc_name, base_name) \ 239 const mp_obj_type_t mp_type_ ## exc_name = { \ 241 .name = MP_QSTR_ ## exc_name, \ 242 .print = mp_obj_exception_print, \ 243 .make_new = mp_obj_exception_make_new, \ 244 .attr = exception_attr, \ 245 .parent = &mp_type_ ## base_name, \ 254 #if MICROPY_PY_ASYNC_AWAIT 278 #if MICROPY_PY_BUILTINS_TIMEOUTERROR 307 #if MICROPY_EMIT_NATIVE 311 #if MICROPY_PY_BUILTINS_STR_UNICODE 363 size_t new_alloc = pr->
alloc +
len + 16;
365 if (new_buf ==
NULL) {
369 pr->
alloc = new_alloc;
388 size_t o_str_alloc =
strlen(fmt) + 1;
391 bool used_emg_buf =
false;
392 #if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF 396 if ((o_str ==
NULL || o_str_buf ==
NULL)
402 o_str_buf = (
byte*)&o_str[1];
404 + mp_emergency_exception_buf_size - o_str_buf;
413 if (o_str_buf ==
NULL) {
416 o_str->
len = o_str_alloc - 1;
420 struct _exc_printer_t exc_pr = {!used_emg_buf, o_str_alloc, 0, o_str_buf};
426 exc_pr.
buf[exc_pr.
len] =
'\0';
468 #define GET_NATIVE_EXCEPTION(self, self_in) \ 470 assert(mp_obj_is_exception_instance(self_in)); \ 471 mp_obj_exception_t *self; \ 472 if (mp_obj_is_native_exception_instance(self_in)) { \ 473 self = MP_OBJ_TO_PTR(self_in); \ 475 self = MP_OBJ_TO_PTR(((mp_obj_instance_t*)MP_OBJ_TO_PTR(self_in))->subobj[0]); \ 482 self->traceback_data =
NULL;
491 if (self->traceback_data ==
NULL) {
493 if (self->traceback_data ==
NULL) {
494 #if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF 497 size_t *tb = (
size_t*)
MP_STATE_VM(mp_emergency_exception_buf);
498 self->traceback_data = tb;
512 self->traceback_len = 0;
514 #if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF 515 if (self->traceback_data == (
size_t*)
MP_STATE_VM(mp_emergency_exception_buf)) {
521 size_t *tb_data =
m_renew_maybe(
size_t, self->traceback_data, self->traceback_alloc,
523 if (tb_data ==
NULL) {
526 self->traceback_data = tb_data;
530 size_t *tb_data = &
self->traceback_data[
self->traceback_len];
540 if (self->traceback_data ==
NULL) {
544 *n =
self->traceback_len;
545 *values =
self->traceback_data;
#define m_renew_maybe(type, ptr, old_num, new_num, allow_move)
mp_obj_t mp_obj_new_exception_msg(const mp_obj_type_t *exc_type, const char *msg)
mp_obj_t mp_obj_exception_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args)
const char * qstr_str(qstr q)
mp_obj_t mp_obj_new_tuple(size_t n, const mp_obj_t *items)
mp_make_new_fun_t make_new
mp_obj_t mp_alloc_emergency_exception_buf(mp_obj_t size_in)
#define MP_OBJ_IS_TYPE(o, t)
STATIC const uint8_t attr[]
void mp_obj_exception_get_traceback(mp_obj_t self_in, size_t *n, size_t **values)
#define m_del(type, ptr, num)
#define GET_NATIVE_EXCEPTION(self, self_in)
#define TRACEBACK_ENTRY_LEN
mp_obj_t mp_obj_new_exception_arg1(const mp_obj_type_t *exc_type, mp_obj_t arg)
const mp_obj_type_t mp_type_StopIteration
mp_obj_t mp_obj_new_exception(const mp_obj_type_t *exc_type)
mp_obj_type_t * mp_obj_get_type(mp_const_obj_t o_in)
int mp_print_str(const mp_print_t *print, const char *str)
#define MP_OBJ_FROM_PTR(p)
void mp_arg_check_num(size_t n_args, size_t n_kw, size_t n_args_min, size_t n_args_max, bool takes_kw)
void mp_obj_tuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind)
void mp_obj_exception_clear_traceback(mp_obj_t self_in)
mp_obj_t mp_obj_new_exception_msg_varg(const mp_obj_type_t *exc_type, const char *fmt,...)
#define EMG_TRACEBACK_ALLOC
mp_int_t mp_obj_get_int(mp_const_obj_t arg)
#define MP_OBJ_SMALL_INT_VALUE(o)
bool mp_obj_is_subclass_fast(mp_const_obj_t object, mp_const_obj_t classinfo)
#define MP_DEFINE_EXCEPTION(exc_name, base_name)
#define MICROPY_BEGIN_ATOMIC_SECTION()
size_t strlen(const char *s)
#define m_new_maybe(type, num)
const mp_obj_type_t mp_type_OSError
void mp_init_emergency_exception_buf(void)
void mp_obj_print_helper(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind)
const mp_obj_exception_t mp_const_GeneratorExit_obj
const mp_obj_type_t mp_type_str
const mp_obj_type_t mp_type_MemoryError
const mp_obj_type_t mp_type_GeneratorExit
#define m_new_obj_maybe(type)
bool mp_obj_is_exception_type(mp_obj_t self_in)
STATIC mp_obj_t exc___init__(size_t n_args, const mp_obj_t *args)
STATIC void exc_add_strn(void *data, const char *str, size_t len)
const mp_obj_type_t mp_type_type
const mp_obj_type_t mp_type_BaseException
STATIC const mp_rom_map_elem_t exc_locals_dict_table[]
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(exc___init___obj, 1, MP_OBJ_FUN_ARGS_MAX, exc___init__)
mp_uint_t qstr_compute_hash(const byte *data, size_t len)
bool mp_obj_is_exception_instance(mp_obj_t self_in)
mp_obj_t mp_obj_new_exception_args(const mp_obj_type_t *exc_type, size_t n_args, const mp_obj_t *args)
__builtin_va_list va_list
const mp_obj_type_t mp_type_tuple
void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qstr block)
#define MP_OBJ_FUN_ARGS_MAX
#define MICROPY_END_ATOMIC_SECTION(state)
int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args)
bool mp_obj_exception_match(mp_obj_t exc, mp_const_obj_t exc_type)
int mp_printf(const mp_print_t *print, const char *fmt,...)
STATIC void mp_obj_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind)
#define va_start(ap, last)
STATIC void exception_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest)
void * memcpy(void *dst, const void *src, size_t n)
const struct _mp_obj_tuple_t mp_const_empty_tuple_obj
#define m_new_obj_var_maybe(obj_type, var_type, var_num)
const mp_obj_exception_t mp_const_MemoryError_obj
mp_obj_t mp_obj_exception_get_value(mp_obj_t self_in)
STATIC MP_DEFINE_CONST_DICT(exc_locals_dict, exc_locals_dict_table)