From 3435f47385da407df742039d3ec00a4e0609c898 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 9 May 2025 14:43:31 -0700 Subject: [PATCH 1/2] Remove non-standard sys.print_exception() It already warned about it. Fixes #9451 --- py/modsys.c | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/py/modsys.c b/py/modsys.c index 2bb2606a0627b..4f9f8759dd322 100644 --- a/py/modsys.c +++ b/py/modsys.c @@ -170,29 +170,7 @@ static mp_obj_t mp_sys_exit(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_sys_exit_obj, 0, 1, mp_sys_exit); -static mp_obj_t mp_sys_print_exception(size_t n_args, const mp_obj_t *args) { - // CIRCUITPY-CHANGE - #if CIRCUITPY_WARNINGS - warnings_warn(&mp_type_FutureWarning, MP_ERROR_TEXT("%q moved from %q to %q"), MP_QSTR_print_exception, MP_QSTR_sys, MP_QSTR_traceback); - #endif - - #if MICROPY_PY_IO && MICROPY_PY_SYS_STDFILES - void *stream_obj = &mp_sys_stdout_obj; - if (n_args > 1) { - mp_get_stream_raise(args[1], MP_STREAM_OP_WRITE); - stream_obj = MP_OBJ_TO_PTR(args[1]); - } - - mp_print_t print = {stream_obj, mp_stream_write_adaptor}; - mp_obj_print_exception(&print, args[0]); - #else - (void)n_args; - mp_obj_print_exception(&mp_plat_print, args[0]); - #endif - - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_sys_print_exception_obj, 1, 2, mp_sys_print_exception); +// CIRCUITPY-CHANGE: Removed print_exception because it isn't in CPython. #if MICROPY_PY_SYS_EXC_INFO static mp_obj_t mp_sys_exc_info(void) { @@ -347,8 +325,6 @@ static const mp_rom_map_elem_t mp_module_sys_globals_table[] = { /* * Extensions to CPython */ - - { MP_ROM_QSTR(MP_QSTR_print_exception), MP_ROM_PTR(&mp_sys_print_exception_obj) }, #if MICROPY_PY_SYS_ATEXIT { MP_ROM_QSTR(MP_QSTR_atexit), MP_ROM_PTR(&mp_sys_atexit_obj) }, #endif From d82b91ec19a0d4043f4f4d2d3f1df903503bcd2a Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Mon, 12 May 2025 14:47:37 -0700 Subject: [PATCH 2/2] Remove old traceback type Both #1167 and #5072 add traceback types. #1167 added a bunch of named tuples in order to reproduce the traceback string. Since #5072 added traceback printing, we don't need the old way. So, rollback PR #1167 in favor of the newer traceback type. --- py/modsys.c | 4 +- py/objexcept.c | 125 ------------------------------------------------- 2 files changed, 3 insertions(+), 126 deletions(-) diff --git a/py/modsys.c b/py/modsys.c index 4f9f8759dd322..ff63f1e2f88cc 100644 --- a/py/modsys.c +++ b/py/modsys.c @@ -26,6 +26,7 @@ */ #include "py/builtin.h" +#include "py/objexcept.h" #include "py/objlist.h" #include "py/objmodule.h" #include "py/objtuple.h" @@ -187,7 +188,8 @@ static mp_obj_t mp_sys_exc_info(void) { t->items[0] = MP_OBJ_FROM_PTR(mp_obj_get_type(cur_exc)); t->items[1] = cur_exc; // CIRCUITPY-CHANGE: has traceback obj - t->items[2] = mp_obj_exception_get_traceback_obj(cur_exc); + mp_obj_exception_t *native_exc = mp_obj_exception_get_native(cur_exc); + t->items[2] = native_exc->traceback; return MP_OBJ_FROM_PTR(t); } MP_DEFINE_CONST_FUN_OBJ_0(mp_sys_exc_info_obj, mp_sys_exc_info); diff --git a/py/objexcept.c b/py/objexcept.c index 70fdc15df4e47..6a6b1e4d4a7a5 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -31,8 +31,6 @@ #include #include "py/objlist.h" -// CIRCUITPY-CHANGE -#include "py/objnamedtuple.h" #include "py/objstr.h" #include "py/objtuple.h" #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 *values = self->traceback->data; } } - -// CIRCUITPY-CHANGE: here until end -#if MICROPY_PY_SYS_EXC_INFO -static const mp_obj_namedtuple_type_t code_type_obj = { - NAMEDTUPLE_TYPE_BASE_AND_SLOTS(MP_QSTR_code), - .n_fields = 15, - .fields = { - MP_QSTR_co_argcount, - MP_QSTR_co_kwonlyargcount, - MP_QSTR_co_nlocals, - MP_QSTR_co_stacksize, - MP_QSTR_co_flags, - MP_QSTR_co_code, - MP_QSTR_co_consts, - MP_QSTR_co_names, - MP_QSTR_co_varnames, - MP_QSTR_co_freevars, - MP_QSTR_co_cellvars, - MP_QSTR_co_filename, - MP_QSTR_co_name, - MP_QSTR_co_firstlineno, - MP_QSTR_co_lnotab, - }, -}; - -static mp_obj_t code_make_new(qstr file, qstr block) { - mp_obj_t elems[15] = { - mp_obj_new_int(0), // co_argcount - mp_obj_new_int(0), // co_kwonlyargcount - mp_obj_new_int(0), // co_nlocals - mp_obj_new_int(0), // co_stacksize - mp_obj_new_int(0), // co_flags - mp_obj_new_bytearray(0, NULL), // co_code - mp_obj_new_tuple(0, NULL), // co_consts - mp_obj_new_tuple(0, NULL), // co_names - mp_obj_new_tuple(0, NULL), // co_varnames - mp_obj_new_tuple(0, NULL), // co_freevars - mp_obj_new_tuple(0, NULL), // co_cellvars - MP_OBJ_NEW_QSTR(file), // co_filename - MP_OBJ_NEW_QSTR(block), // co_name - mp_obj_new_int(1), // co_firstlineno - mp_obj_new_bytearray(0, NULL), // co_lnotab - }; - - return namedtuple_make_new((const mp_obj_type_t *)&code_type_obj, 15, 0, elems); -} - -static const mp_obj_namedtuple_type_t frame_type_obj = { - NAMEDTUPLE_TYPE_BASE_AND_SLOTS(MP_QSTR_frame), - .n_fields = 8, - .fields = { - MP_QSTR_f_back, - MP_QSTR_f_builtins, - MP_QSTR_f_code, - MP_QSTR_f_globals, - MP_QSTR_f_lasti, - MP_QSTR_f_lineno, - MP_QSTR_f_locals, - MP_QSTR_f_trace, - }, -}; - -static mp_obj_t frame_make_new(mp_obj_t f_code, int f_lineno) { - mp_obj_t elems[8] = { - mp_const_none, // f_back - mp_obj_new_dict(0), // f_builtins - f_code, // f_code - mp_obj_new_dict(0), // f_globals - mp_obj_new_int(0), // f_lasti - mp_obj_new_int(f_lineno), // f_lineno - mp_obj_new_dict(0), // f_locals - mp_const_none, // f_trace - }; - - return namedtuple_make_new((const mp_obj_type_t *)&frame_type_obj, 8, 0, elems); -} - -static const mp_obj_namedtuple_type_t traceback_type_obj = { - NAMEDTUPLE_TYPE_BASE_AND_SLOTS(MP_QSTR_traceback), - .n_fields = 4, - .fields = { - MP_QSTR_tb_frame, - MP_QSTR_tb_lasti, - MP_QSTR_tb_lineno, - MP_QSTR_tb_next, - }, -}; - -static mp_obj_t traceback_from_values(size_t *values, mp_obj_t tb_next) { - int lineno = values[1]; - - mp_obj_t elems[4] = { - frame_make_new(code_make_new(values[0], values[2]), lineno), - mp_obj_new_int(0), - mp_obj_new_int(lineno), - tb_next, - }; - - return namedtuple_make_new((const mp_obj_type_t *)&traceback_type_obj, 4, 0, elems); -}; - -mp_obj_t mp_obj_exception_get_traceback_obj(mp_obj_t self_in) { - mp_obj_exception_t *self = MP_OBJ_TO_PTR(self_in); - - if (!mp_obj_is_exception_instance(self)) { - return mp_const_none; - } - - size_t n, *values; - mp_obj_exception_get_traceback(self, &n, &values); - if (n == 0) { - return mp_const_none; - } - - mp_obj_t tb_next = mp_const_none; - - for (size_t i = 0; i < n; i += 3) { - tb_next = traceback_from_values(&values[i], tb_next); - } - - return tb_next; -} -#endif pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy