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.
pull/1130/head
Paul Sokolovsky 2015-02-17 00:12:42 +02:00
rodzic eff10f66a6
commit 1f91e92cc6
1 zmienionych plików z 9 dodań i 1 usunięć

Wyświetl plik

@ -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