Commit 5ae5ec98 authored by Damien George's avatar Damien George
Browse files

py: Make mp_sys_stdout_print object, wrapping sys.stdout for mp_print*.

So now all printing should go via either mp_plat_print or
mp_sys_stdout_print.
parent 7f9d1d6a
...@@ -440,9 +440,8 @@ MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_print_obj, 0, mp_builtin_print); ...@@ -440,9 +440,8 @@ MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_print_obj, 0, mp_builtin_print);
STATIC mp_obj_t mp_builtin___repl_print__(mp_obj_t o) { STATIC mp_obj_t mp_builtin___repl_print__(mp_obj_t o) {
if (o != mp_const_none) { if (o != mp_const_none) {
#if MICROPY_PY_IO #if MICROPY_PY_IO
mp_print_t print = {&mp_sys_stdout_obj, (mp_print_strn_t)mp_stream_write}; mp_obj_print_helper(&mp_sys_stdout_print, o, PRINT_REPR);
mp_obj_print_helper(&print, o, PRINT_REPR); mp_print_str(&mp_sys_stdout_print, "\n");
mp_stream_write(&mp_sys_stdout_obj, "\n", 1);
#else #else
mp_obj_print(o, PRINT_REPR); mp_obj_print(o, PRINT_REPR);
printf("\n"); printf("\n");
......
...@@ -42,6 +42,10 @@ extern struct _mp_dummy_t mp_sys_stdin_obj; ...@@ -42,6 +42,10 @@ extern struct _mp_dummy_t mp_sys_stdin_obj;
extern struct _mp_dummy_t mp_sys_stdout_obj; extern struct _mp_dummy_t mp_sys_stdout_obj;
extern struct _mp_dummy_t mp_sys_stderr_obj; extern struct _mp_dummy_t mp_sys_stderr_obj;
#if MICROPY_PY_IO
const mp_print_t mp_sys_stdout_print = {&mp_sys_stdout_obj, (mp_print_strn_t)mp_stream_write};
#endif
/// \constant version - Python language version that this implementation conforms to, as a string /// \constant version - Python language version that this implementation conforms to, as a string
STATIC const MP_DEFINE_STR_OBJ(version_obj, "3.4.0"); STATIC const MP_DEFINE_STR_OBJ(version_obj, "3.4.0");
......
...@@ -47,10 +47,13 @@ typedef struct _mp_print_t { ...@@ -47,10 +47,13 @@ typedef struct _mp_print_t {
mp_print_strn_t print_strn; mp_print_strn_t print_strn;
} mp_print_t; } mp_print_t;
// Wrapper for platform print function, which wraps MP_PLAT_PRINT_STRN. // All (non-debug) prints go through one of the two interfaces below.
// All (non-debug) prints go through this interface (except some which // 1) Wrapper for platform print function, which wraps MP_PLAT_PRINT_STRN.
// go through mp_sys_stdout_obj if MICROPY_PY_IO is defined).
extern const mp_print_t mp_plat_print; extern const mp_print_t mp_plat_print;
#if MICROPY_PY_IO
// 2) Wrapper for printing to sys.stdout.
extern const mp_print_t mp_sys_stdout_print;
#endif
int mp_print_str(const mp_print_t *print, const char *str); int mp_print_str(const mp_print_t *print, const char *str);
int mp_print_strn(const mp_print_t *print, const char *str, mp_uint_t len, int flags, char fill, int width); int mp_print_strn(const mp_print_t *print, const char *str, mp_uint_t len, int flags, char fill, int width);
......
...@@ -73,12 +73,7 @@ void mp_obj_print_helper(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t ...@@ -73,12 +73,7 @@ void mp_obj_print_helper(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t
void mp_obj_print(mp_obj_t o_in, mp_print_kind_t kind) { void mp_obj_print(mp_obj_t o_in, mp_print_kind_t kind) {
#if MICROPY_PY_IO #if MICROPY_PY_IO
// defined per port; type of these is irrelevant, just need pointer mp_obj_print_helper(&mp_sys_stdout_print, o_in, kind);
extern struct _mp_dummy_t mp_sys_stdout_obj;
mp_print_t print;
print.data = &mp_sys_stdout_obj;
print.print_strn = (mp_print_strn_t)mp_stream_write;
mp_obj_print_helper(&print, o_in, kind);
#else #else
mp_obj_print_helper(&mp_plat_print, o_in, kind); mp_obj_print_helper(&mp_plat_print, o_in, kind);
#endif #endif
......
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