Skip to content

Commit 1eca328

Browse files
pfalcondpgeorge
authored andcommitted
builtin: Reimplement __repl_print__() in terms of print().
Before, __repl_print__() used libc printf(), while print() used uPy streams and own printf() implementation. This led to subtle, but confusing differences in output when just doing "foo" vs "print(foo)" on interactive prompt.
1 parent e5dbe1e commit 1eca328

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

py/builtin.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,6 @@ STATIC mp_obj_t mp_builtin___build_class__(mp_uint_t n_args, const mp_obj_t *arg
8989
}
9090
MP_DEFINE_CONST_FUN_OBJ_VAR(mp_builtin___build_class___obj, 2, mp_builtin___build_class__);
9191

92-
STATIC mp_obj_t mp_builtin___repl_print__(mp_obj_t o) {
93-
if (o != mp_const_none) {
94-
mp_obj_print(o, PRINT_REPR);
95-
printf("\n");
96-
}
97-
return mp_const_none;
98-
}
99-
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin___repl_print___obj, mp_builtin___repl_print__);
100-
10192
STATIC mp_obj_t mp_builtin_abs(mp_obj_t o_in) {
10293
if (MP_OBJ_IS_SMALL_INT(o_in)) {
10394
mp_int_t val = MP_OBJ_SMALL_INT_VALUE(o_in);
@@ -452,6 +443,14 @@ STATIC mp_obj_t mp_builtin_print(mp_uint_t n_args, const mp_obj_t *args, mp_map_
452443
}
453444
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_print_obj, 0, mp_builtin_print);
454445

446+
STATIC mp_obj_t mp_builtin___repl_print__(mp_obj_t o) {
447+
if (o != mp_const_none) {
448+
mp_builtin_print(1, &o, (mp_map_t*)&mp_const_empty_map);
449+
}
450+
return mp_const_none;
451+
}
452+
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin___repl_print___obj, mp_builtin___repl_print__);
453+
455454
STATIC mp_obj_t mp_builtin_repr(mp_obj_t o_in) {
456455
vstr_t *vstr = vstr_new();
457456
mp_obj_print_helper((void (*)(void *env, const char *fmt, ...))vstr_printf, vstr, o_in, PRINT_REPR);

0 commit comments

Comments
 (0)