Skip to content

mpprint: Add %R (print object) & %K (print exception). #17583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions py/modthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,8 @@ static void *thread_entry(void *args_in) {
// swallow exception silently
} else {
// print exception out
mp_printf(MICROPY_ERROR_PRINTER, "Unhandled exception in thread started by ");
mp_obj_print_helper(MICROPY_ERROR_PRINTER, args->fun, PRINT_REPR);
mp_printf(MICROPY_ERROR_PRINTER, "\n");
mp_obj_print_exception(MICROPY_ERROR_PRINTER, MP_OBJ_FROM_PTR(exc));
mp_printf(MICROPY_ERROR_PRINTER, "Unhandled exception in thread started by %R\n%K",
PRINT_REPR, args->fun, MP_OBJ_FROM_PTR(exc));
}
}

Expand Down
11 changes: 11 additions & 0 deletions py/mpprint.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,17 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args) {
chrs += mp_print_strn(print, &str, 1, flags, fill, width);
break;
}
case 'K': {
mp_obj_t obj = va_arg(args, mp_obj_t);
mp_obj_print_exception(print, obj);
break;
}
case 'R': {
mp_print_kind_t kind = va_arg(args, int);
mp_obj_t obj = va_arg(args, mp_obj_t);
mp_obj_print_helper(print, obj, kind);
break;
}
case 'q': {
qstr qst = va_arg(args, qstr);
size_t len;
Expand Down
3 changes: 1 addition & 2 deletions py/objattrtuple.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ void mp_obj_attrtuple_print_helper(const mp_print_t *print, const qstr *fields,
if (i > 0) {
mp_print_str(print, ", ");
}
mp_printf(print, "%q=", fields[i]);
mp_obj_print_helper(print, o->items[i], PRINT_REPR);
mp_printf(print, "%q=%R", fields[i], PRINT_REPR, o->items[i]);
}
mp_print_str(print, ")");
}
Expand Down
6 changes: 1 addition & 5 deletions py/objboundmeth.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ typedef struct _mp_obj_bound_meth_t {
static void bound_meth_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) {
(void)kind;
mp_obj_bound_meth_t *o = MP_OBJ_TO_PTR(o_in);
mp_printf(print, "<bound_method %p ", o);
mp_obj_print_helper(print, o->self, PRINT_REPR);
mp_print_str(print, ".");
mp_obj_print_helper(print, o->meth, PRINT_REPR);
mp_print_str(print, ">");
mp_printf(print, "<bound_method %p %R.%R>", o, PRINT_REPR, o->self, PRINT_REPR, o->meth);
}
#endif

Expand Down
8 changes: 1 addition & 7 deletions py/objcell.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,7 @@
static void cell_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) {
(void)kind;
mp_obj_cell_t *o = MP_OBJ_TO_PTR(o_in);
mp_printf(print, "<cell %p ", o->obj);
if (o->obj == MP_OBJ_NULL) {
mp_print_str(print, "(nil)");
} else {
mp_obj_print_helper(print, o->obj, PRINT_REPR);
}
mp_print_str(print, ">");
mp_printf(print, "<cell %p %R>", o->obj, PRINT_REPR, o->obj);
}
#endif

Expand Down
10 changes: 2 additions & 8 deletions py/objclosure.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,10 @@ static mp_obj_t closure_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const
static void closure_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) {
(void)kind;
mp_obj_closure_t *o = MP_OBJ_TO_PTR(o_in);
mp_print_str(print, "<closure ");
mp_obj_print_helper(print, o->fun, PRINT_REPR);
mp_printf(print, " at %p, n_closed=%u ", o, (int)o->n_closed);
mp_printf(print, "<closure %R at %p, n_closed=%u", PRINT_REPR, o->fun, o, (int)o->n_closed);
for (size_t i = 0; i < o->n_closed; i++) {
if (o->closed[i] == MP_OBJ_NULL) {
mp_print_str(print, "(nil)");
} else {
mp_obj_print_helper(print, o->closed[i], PRINT_REPR);
}
mp_print_str(print, " ");
mp_obj_print_helper(print, o->closed[i], PRINT_REPR);
}
mp_print_str(print, ">");
}
Expand Down
Loading
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