Skip to content

Commit 1f91e92

Browse files
committed
py: Revamp mp_obj_print() to use Python streams.
Most of printing infrastructure now uses streams, but mp_obj_print() used libc's printf(), which led to weird buffering issues in output. So, switch mp_obj_print() to streams too, even though it may make sense to move it to a separate file, as it is purely a debugging function now.
1 parent eff10f6 commit 1f91e92

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

py/obj.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "py/runtime.h"
3838
#include "py/stackctrl.h"
3939
#include "py/pfenv.h"
40+
#include "py/stream.h" // for mp_obj_print
4041

4142
mp_obj_type_t *mp_obj_get_type(mp_const_obj_t o_in) {
4243
if (MP_OBJ_IS_SMALL_INT(o_in)) {
@@ -71,7 +72,14 @@ void mp_obj_print_helper(void (*print)(void *env, const char *fmt, ...), void *e
7172
}
7273

7374
void mp_obj_print(mp_obj_t o_in, mp_print_kind_t kind) {
74-
mp_obj_print_helper(printf_wrapper, NULL, o_in, kind);
75+
// defined per port; type of these is irrelevant, just need pointer
76+
extern mp_uint_t mp_sys_stdout_obj;
77+
78+
pfenv_t pfenv;
79+
pfenv.data = &mp_sys_stdout_obj;
80+
pfenv.print_strn = (void (*)(void *, const char *, mp_uint_t))mp_stream_write;
81+
82+
mp_obj_print_helper((void (*)(void *env, const char *fmt, ...))pfenv_printf, &pfenv, o_in, kind);
7583
}
7684

7785
// helper function to print an exception with traceback

0 commit comments

Comments
 (0)