diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2015-04-25 03:17:41 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2015-04-25 03:49:23 +0300 |
commit | 8b85d14b92a65e92862861038c0fe96e6c616c3e (patch) | |
tree | 237c7a0bad20fb8a31944a6bc7bbc51a97689d3a /py/modsys.c | |
parent | cf5b6f6974a1ca7d835803a744d1daae12876dac (diff) |
modsys: Add basic sys.exc_info() implementation.
The implementation is very basic and non-compliant and provided solely for
CPython compatibility. The function itself is bad Python2 heritage, its
usage is discouraged.
Diffstat (limited to 'py/modsys.c')
-rw-r--r-- | py/modsys.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/py/modsys.c b/py/modsys.c index 182ae13ec..aad0fb8d7 100644 --- a/py/modsys.c +++ b/py/modsys.c @@ -121,6 +121,26 @@ STATIC mp_obj_t mp_sys_print_exception(mp_uint_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_sys_print_exception_obj, 1, 2, mp_sys_print_exception); +#if MICROPY_PY_SYS_EXC_INFO +STATIC mp_obj_t mp_sys_exc_info(void) { + mp_obj_t cur_exc = MP_STATE_VM(cur_exception); + mp_obj_tuple_t *t = mp_obj_new_tuple(3, NULL); + + if (cur_exc == MP_OBJ_NULL) { + t->items[0] = mp_const_none; + t->items[1] = mp_const_none; + t->items[2] = mp_const_none; + return t; + } + + t->items[0] = mp_obj_get_type(cur_exc); + t->items[1] = cur_exc; + t->items[2] = mp_const_none; + return t; +} +MP_DEFINE_CONST_FUN_OBJ_0(mp_sys_exc_info_obj, mp_sys_exc_info); +#endif + STATIC const mp_map_elem_t mp_module_sys_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_sys) }, @@ -163,6 +183,10 @@ STATIC const mp_map_elem_t mp_module_sys_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_stderr), (mp_obj_t)&mp_sys_stderr_obj }, #endif + #if MICROPY_PY_SYS_EXC_INFO + { MP_OBJ_NEW_QSTR(MP_QSTR_exc_info), (mp_obj_t)&mp_sys_exc_info_obj }, + #endif + /* * Extensions to CPython */ |