diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2015-02-17 00:12:42 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2015-02-17 00:13:01 +0200 |
commit | 1f91e92cc6774b79ea59643bb4ab27c1d33bda3a (patch) | |
tree | 06b45f7c1e2e94f9c072199e882f2db29216b572 | |
parent | eff10f66a65d0577aa9d10ee08b469cb9c83e1a3 (diff) | |
download | micropython-1f91e92cc6774b79ea59643bb4ab27c1d33bda3a.tar.gz micropython-1f91e92cc6774b79ea59643bb4ab27c1d33bda3a.zip |
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.
-rw-r--r-- | py/obj.c | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -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 |