From 1f91e92cc6774b79ea59643bb4ab27c1d33bda3a Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Tue, 17 Feb 2015 00:12:42 +0200 Subject: [PATCH] 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. --- py/obj.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/py/obj.c b/py/obj.c index 4d363e8a69..dad27b8772 100644 --- a/py/obj.c +++ b/py/obj.c @@ -37,6 +37,7 @@ #include "py/runtime.h" #include "py/stackctrl.h" #include "py/pfenv.h" +#include "py/stream.h" // for mp_obj_print mp_obj_type_t *mp_obj_get_type(mp_const_obj_t o_in) { 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 } void mp_obj_print(mp_obj_t o_in, mp_print_kind_t kind) { - mp_obj_print_helper(printf_wrapper, NULL, o_in, kind); + // defined per port; type of these is irrelevant, just need pointer + extern mp_uint_t mp_sys_stdout_obj; + + pfenv_t pfenv; + pfenv.data = &mp_sys_stdout_obj; + pfenv.print_strn = (void (*)(void *, const char *, mp_uint_t))mp_stream_write; + + mp_obj_print_helper((void (*)(void *env, const char *fmt, ...))pfenv_printf, &pfenv, o_in, kind); } // helper function to print an exception with traceback