Skip to content

Commit d82b91e

Browse files
committed
Remove old traceback type
Both micropython#1167 and micropython#5072 add traceback types. micropython#1167 added a bunch of named tuples in order to reproduce the traceback string. Since micropython#5072 added traceback printing, we don't need the old way. So, rollback PR micropython#1167 in favor of the newer traceback type.
1 parent 3435f47 commit d82b91e

File tree

2 files changed

+3
-126
lines changed

2 files changed

+3
-126
lines changed

py/modsys.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
*/
2727

2828
#include "py/builtin.h"
29+
#include "py/objexcept.h"
2930
#include "py/objlist.h"
3031
#include "py/objmodule.h"
3132
#include "py/objtuple.h"
@@ -187,7 +188,8 @@ static mp_obj_t mp_sys_exc_info(void) {
187188
t->items[0] = MP_OBJ_FROM_PTR(mp_obj_get_type(cur_exc));
188189
t->items[1] = cur_exc;
189190
// CIRCUITPY-CHANGE: has traceback obj
190-
t->items[2] = mp_obj_exception_get_traceback_obj(cur_exc);
191+
mp_obj_exception_t *native_exc = mp_obj_exception_get_native(cur_exc);
192+
t->items[2] = native_exc->traceback;
191193
return MP_OBJ_FROM_PTR(t);
192194
}
193195
MP_DEFINE_CONST_FUN_OBJ_0(mp_sys_exc_info_obj, mp_sys_exc_info);

py/objexcept.c

Lines changed: 0 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
#include <stdio.h>
3232

3333
#include "py/objlist.h"
34-
// CIRCUITPY-CHANGE
35-
#include "py/objnamedtuple.h"
3634
#include "py/objstr.h"
3735
#include "py/objtuple.h"
3836
#include "py/objtype.h"
@@ -729,126 +727,3 @@ void mp_obj_exception_get_traceback(mp_obj_t self_in, size_t *n, size_t **values
729727
*values = self->traceback->data;
730728
}
731729
}
732-
733-
// CIRCUITPY-CHANGE: here until end
734-
#if MICROPY_PY_SYS_EXC_INFO
735-
static const mp_obj_namedtuple_type_t code_type_obj = {
736-
NAMEDTUPLE_TYPE_BASE_AND_SLOTS(MP_QSTR_code),
737-
.n_fields = 15,
738-
.fields = {
739-
MP_QSTR_co_argcount,
740-
MP_QSTR_co_kwonlyargcount,
741-
MP_QSTR_co_nlocals,
742-
MP_QSTR_co_stacksize,
743-
MP_QSTR_co_flags,
744-
MP_QSTR_co_code,
745-
MP_QSTR_co_consts,
746-
MP_QSTR_co_names,
747-
MP_QSTR_co_varnames,
748-
MP_QSTR_co_freevars,
749-
MP_QSTR_co_cellvars,
750-
MP_QSTR_co_filename,
751-
MP_QSTR_co_name,
752-
MP_QSTR_co_firstlineno,
753-
MP_QSTR_co_lnotab,
754-
},
755-
};
756-
757-
static mp_obj_t code_make_new(qstr file, qstr block) {
758-
mp_obj_t elems[15] = {
759-
mp_obj_new_int(0), // co_argcount
760-
mp_obj_new_int(0), // co_kwonlyargcount
761-
mp_obj_new_int(0), // co_nlocals
762-
mp_obj_new_int(0), // co_stacksize
763-
mp_obj_new_int(0), // co_flags
764-
mp_obj_new_bytearray(0, NULL), // co_code
765-
mp_obj_new_tuple(0, NULL), // co_consts
766-
mp_obj_new_tuple(0, NULL), // co_names
767-
mp_obj_new_tuple(0, NULL), // co_varnames
768-
mp_obj_new_tuple(0, NULL), // co_freevars
769-
mp_obj_new_tuple(0, NULL), // co_cellvars
770-
MP_OBJ_NEW_QSTR(file), // co_filename
771-
MP_OBJ_NEW_QSTR(block), // co_name
772-
mp_obj_new_int(1), // co_firstlineno
773-
mp_obj_new_bytearray(0, NULL), // co_lnotab
774-
};
775-
776-
return namedtuple_make_new((const mp_obj_type_t *)&code_type_obj, 15, 0, elems);
777-
}
778-
779-
static const mp_obj_namedtuple_type_t frame_type_obj = {
780-
NAMEDTUPLE_TYPE_BASE_AND_SLOTS(MP_QSTR_frame),
781-
.n_fields = 8,
782-
.fields = {
783-
MP_QSTR_f_back,
784-
MP_QSTR_f_builtins,
785-
MP_QSTR_f_code,
786-
MP_QSTR_f_globals,
787-
MP_QSTR_f_lasti,
788-
MP_QSTR_f_lineno,
789-
MP_QSTR_f_locals,
790-
MP_QSTR_f_trace,
791-
},
792-
};
793-
794-
static mp_obj_t frame_make_new(mp_obj_t f_code, int f_lineno) {
795-
mp_obj_t elems[8] = {
796-
mp_const_none, // f_back
797-
mp_obj_new_dict(0), // f_builtins
798-
f_code, // f_code
799-
mp_obj_new_dict(0), // f_globals
800-
mp_obj_new_int(0), // f_lasti
801-
mp_obj_new_int(f_lineno), // f_lineno
802-
mp_obj_new_dict(0), // f_locals
803-
mp_const_none, // f_trace
804-
};
805-
806-
return namedtuple_make_new((const mp_obj_type_t *)&frame_type_obj, 8, 0, elems);
807-
}
808-
809-
static const mp_obj_namedtuple_type_t traceback_type_obj = {
810-
NAMEDTUPLE_TYPE_BASE_AND_SLOTS(MP_QSTR_traceback),
811-
.n_fields = 4,
812-
.fields = {
813-
MP_QSTR_tb_frame,
814-
MP_QSTR_tb_lasti,
815-
MP_QSTR_tb_lineno,
816-
MP_QSTR_tb_next,
817-
},
818-
};
819-
820-
static mp_obj_t traceback_from_values(size_t *values, mp_obj_t tb_next) {
821-
int lineno = values[1];
822-
823-
mp_obj_t elems[4] = {
824-
frame_make_new(code_make_new(values[0], values[2]), lineno),
825-
mp_obj_new_int(0),
826-
mp_obj_new_int(lineno),
827-
tb_next,
828-
};
829-
830-
return namedtuple_make_new((const mp_obj_type_t *)&traceback_type_obj, 4, 0, elems);
831-
};
832-
833-
mp_obj_t mp_obj_exception_get_traceback_obj(mp_obj_t self_in) {
834-
mp_obj_exception_t *self = MP_OBJ_TO_PTR(self_in);
835-
836-
if (!mp_obj_is_exception_instance(self)) {
837-
return mp_const_none;
838-
}
839-
840-
size_t n, *values;
841-
mp_obj_exception_get_traceback(self, &n, &values);
842-
if (n == 0) {
843-
return mp_const_none;
844-
}
845-
846-
mp_obj_t tb_next = mp_const_none;
847-
848-
for (size_t i = 0; i < n; i += 3) {
849-
tb_next = traceback_from_values(&values[i], tb_next);
850-
}
851-
852-
return tb_next;
853-
}
854-
#endif

0 commit comments

Comments
 (0)