Commit 1f91e92c authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

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.
parent eff10f66
......@@ -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; = &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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment