Skip to content

Commit

Permalink
py/mpprint: Add %o/%r formatting code to print str()/repr() of an mp_…
Browse files Browse the repository at this point in the history
…obj_t.

Similar to existing "%q" to pring a qstr. The usefulness of such addition
was long discussed. In particular, it would be useful to dynamic modules,
to expose only mp_printf() to them, and not the all extra helper functions.

Change-Id: I2f7ca599111f7b7d5e65105f3c4572fd6c632895
  • Loading branch information
pfalcon committed Jan 27, 2019
1 parent fa5cf15 commit f3c0f8e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions py/mpprint.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,16 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args) {
break;
}
assert(!"unsupported fmt char");
break;
}
#endif
case 'o':
case 'r': {
mp_obj_t o = va_arg(args, mp_obj_t);
// TODO: doesn't update length in 'chrs'
mp_obj_print_helper(print, o, *fmt == 'o' ? PRINT_STR : PRINT_REPR);
break;
}
default:
// if it's not %% then it's an unsupported format character
assert(*fmt == '%' || !"unsupported fmt char");
Expand Down

0 comments on commit f3c0f8e

Please sign in to comment.