diff --git a/extmod/misc.h b/extmod/misc.h index 032fcba613..39bfd5ecb5 100644 --- a/extmod/misc.h +++ b/extmod/misc.h @@ -27,6 +27,13 @@ // This file contains cumulative declarations for extmod/ . +#include #include "py/runtime.h" MP_DECLARE_CONST_FUN_OBJ(mp_uos_dupterm_obj); + +#if MICROPY_PY_OS_DUPTERM +void mp_uos_dupterm_tx_strn(const char *str, size_t len); +#else +#define mp_uos_dupterm_tx_strn(s, l) +#endif diff --git a/extmod/moduos_dupterm.c b/extmod/moduos_dupterm.c index d20986279a..7fe8524a56 100644 --- a/extmod/moduos_dupterm.c +++ b/extmod/moduos_dupterm.c @@ -34,6 +34,15 @@ #if MICROPY_PY_OS_DUPTERM +void mp_uos_dupterm_tx_strn(const char *str, size_t len) { + if (MP_STATE_PORT(term_obj) != MP_OBJ_NULL) { + mp_obj_t write_m[3]; + mp_load_method(MP_STATE_PORT(term_obj), MP_QSTR_write, write_m); + write_m[2] = mp_obj_new_bytearray_by_ref(len, (char*)str); + mp_call_method_n_kw(1, 0, write_m); + } +} + STATIC mp_obj_t mp_uos_dupterm(mp_uint_t n_args, const mp_obj_t *args) { if (n_args == 0) { if (MP_STATE_PORT(term_obj) == MP_OBJ_NULL) { diff --git a/unix/main.c b/unix/main.c index c305c37283..9f787595d0 100644 --- a/unix/main.c +++ b/unix/main.c @@ -45,6 +45,7 @@ #include "py/gc.h" #include "py/stackctrl.h" #include "py/mphal.h" +#include "extmod/misc.h" #include "genhdr/mpversion.h" #include "input.h" @@ -61,7 +62,7 @@ long heap_size = 1024*1024 * (sizeof(mp_uint_t) / 4); STATIC void stderr_print_strn(void *env, const char *str, size_t len) { (void)env; ssize_t dummy = write(STDERR_FILENO, str, len); - mp_hal_dupterm_tx_strn(str, len); + mp_uos_dupterm_tx_strn(str, len); (void)dummy; } diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h index b5f1a45871..035c62883d 100644 --- a/unix/mpconfigport.h +++ b/unix/mpconfigport.h @@ -243,13 +243,6 @@ extern const struct _mp_obj_fun_builtin_t mp_builtin_open_obj; #define MP_STATE_PORT MP_STATE_VM -#if MICROPY_PY_OS_DUPTERM -#include -void mp_hal_dupterm_tx_strn(const char *str, size_t len); -#else -#define mp_hal_dupterm_tx_strn(s, l) -#endif - #define MICROPY_PORT_ROOT_POINTERS \ const char *readline_hist[50]; \ mp_obj_t keyboard_interrupt_obj; \ diff --git a/unix/unix_mphal.c b/unix/unix_mphal.c index 16e80b7ef8..9da8680562 100644 --- a/unix/unix_mphal.c +++ b/unix/unix_mphal.c @@ -32,6 +32,7 @@ #include "py/mpstate.h" #include "py/mphal.h" #include "py/runtime.h" +#include "extmod/misc.h" #ifndef _WIN32 #include @@ -107,17 +108,6 @@ void mp_hal_stdio_mode_orig(void) { #endif -#if MICROPY_PY_OS_DUPTERM -void mp_hal_dupterm_tx_strn(const char *str, size_t len) { - if (MP_STATE_PORT(term_obj) != MP_OBJ_NULL) { - mp_obj_t write_m[3]; - mp_load_method(MP_STATE_PORT(term_obj), MP_QSTR_write, write_m); - write_m[2] = mp_obj_new_bytearray_by_ref(len, (char*)str); - mp_call_method_n_kw(1, 0, write_m); - } -} -#endif - int mp_hal_stdin_rx_chr(void) { unsigned char c; #if MICROPY_PY_OS_DUPTERM @@ -152,7 +142,7 @@ int mp_hal_stdin_rx_chr(void) { void mp_hal_stdout_tx_strn(const char *str, size_t len) { int ret = write(1, str, len); - mp_hal_dupterm_tx_strn(str, len); + mp_uos_dupterm_tx_strn(str, len); (void)ret; // to suppress compiler warning }