diff --git a/py/builtin.h b/py/builtin.h index 70cc28ae14f0c9fdeb765730e11dc70bf58f55ca..ddd63a7dad7349345de294e2800a2a397bb0d243 100644 --- a/py/builtin.h +++ b/py/builtin.h @@ -30,6 +30,7 @@ mp_obj_t mp_builtin___import__(mp_uint_t n_args, const mp_obj_t *args); mp_obj_t mp_builtin_open(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kwargs); +mp_obj_t mp_micropython_mem_info(mp_uint_t n_args, const mp_obj_t *args); MP_DECLARE_CONST_FUN_OBJ(mp_builtin___build_class___obj); MP_DECLARE_CONST_FUN_OBJ(mp_builtin___import___obj); @@ -91,11 +92,6 @@ extern const mp_obj_module_t mp_module_gc; extern const mp_obj_dict_t mp_module_builtins_globals; -struct _dummy_t; -extern struct _dummy_t mp_sys_stdin_obj; -extern struct _dummy_t mp_sys_stdout_obj; -extern struct _dummy_t mp_sys_stderr_obj; - // extmod modules extern const mp_obj_module_t mp_module_uctypes; extern const mp_obj_module_t mp_module_uzlib; diff --git a/py/modbuiltins.c b/py/modbuiltins.c index 2a5b7a19cf9d28ed3efc09a9ea887b2320167ed4..b739503ade842486b66bfb4f9cdd793f1c18296c 100644 --- a/py/modbuiltins.c +++ b/py/modbuiltins.c @@ -406,6 +406,7 @@ STATIC mp_obj_t mp_builtin_print(mp_uint_t n_args, const mp_obj_t *args, mp_map_ end_data = mp_obj_str_get_data(end_elem->value, &end_len); } #if MICROPY_PY_IO + extern mp_uint_t mp_sys_stdout_obj; // type is irrelevant, just need pointer mp_obj_t stream_obj = &mp_sys_stdout_obj; mp_map_elem_t *file_elem = mp_map_lookup(kwargs, MP_OBJ_NEW_QSTR(MP_QSTR_file), MP_MAP_LOOKUP); if (file_elem != NULL && file_elem->value != mp_const_none) { diff --git a/py/modsys.c b/py/modsys.c index 51bd6bfbb44b18df16bcf0ba5597e679966d90d2..51e10dae54eff0743d1e64866e478a301a7fcd4d 100644 --- a/py/modsys.c +++ b/py/modsys.c @@ -37,6 +37,11 @@ /// \module sys - system specific functions +// defined per port; type of these is irrelevant, just need pointer +extern mp_uint_t mp_sys_stdin_obj; +extern mp_uint_t mp_sys_stdout_obj; +extern mp_uint_t mp_sys_stderr_obj; + // These two lists must be initialised per port (after the call to mp_init). // TODO document these properly, they aren't constants or functions... /// \constant path - a mutable list of directories to search for imported modules diff --git a/py/obj.c b/py/obj.c index e58330a9d59da1e5e8b7f64b94ed65652e14834c..1133914bb9131f81685ac87e288143269703ac95 100644 --- a/py/obj.c +++ b/py/obj.c @@ -36,6 +36,7 @@ #include "py/runtime0.h" #include "py/runtime.h" #include "py/stackctrl.h" +#include "py/pfenv.h" mp_obj_type_t *mp_obj_get_type(mp_const_obj_t o_in) { if (MP_OBJ_IS_SMALL_INT(o_in)) { @@ -52,13 +53,6 @@ const char *mp_obj_get_type_str(mp_const_obj_t o_in) { return qstr_str(mp_obj_get_type(o_in)->name); } -void printf_wrapper(void *env, const char *fmt, ...) { - va_list args; - va_start(args, fmt); - vprintf(fmt, args); - va_end(args); -} - void mp_obj_print_helper(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) { // There can be data structures nested too deep, or just recursive MP_STACK_CHECK(); diff --git a/py/pfenv.h b/py/pfenv.h index 074c0012f81394aabecba6006210df8e3ded0181..01258f82021b33a9bcd27f441f0d6894e67d8be5 100644 --- a/py/pfenv.h +++ b/py/pfenv.h @@ -26,6 +26,8 @@ #ifndef __MICROPY_INCLUDED_PY_PFENV_H__ #define __MICROPY_INCLUDED_PY_PFENV_H__ +#include <stdarg.h> + #include "py/obj.h" #define PF_FLAG_LEFT_ADJUST (0x001) @@ -54,7 +56,7 @@ int pfenv_print_mp_int(const pfenv_t *pfenv, mp_obj_t x, int sgn, int base, int int pfenv_print_float(const pfenv_t *pfenv, mp_float_t f, char fmt, int flags, char fill, int width, int prec); #endif -//int pfenv_vprintf(const pfenv_t *pfenv, const char *fmt, va_list args); +int pfenv_vprintf(const pfenv_t *pfenv, const char *fmt, va_list args); int pfenv_printf(const pfenv_t *pfenv, const char *fmt, ...); // Wrapper for system printf diff --git a/py/pfenv_printf.c b/py/pfenv_printf.c index 39bf321ce3fae471221eac93970fa049baea5bac..a68788a7f65c9ab55769ccf0d301679c8d6e1034 100644 --- a/py/pfenv_printf.c +++ b/py/pfenv_printf.c @@ -27,6 +27,7 @@ #include <assert.h> #include <string.h> #include <stdarg.h> +#include <stdio.h> #include "py/pfenv.h" @@ -193,3 +194,10 @@ int pfenv_printf(const pfenv_t *pfenv, const char *fmt, ...) { va_end(ap); return ret; } + +void printf_wrapper(void *env, const char *fmt, ...) { + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} diff --git a/py/warning.c b/py/warning.c index 4cce1776649ef4cecd54d355cf05eec5e0c349f8..469c19cea7df6fc9142c201347d527044edafcde 100644 --- a/py/warning.c +++ b/py/warning.c @@ -27,8 +27,8 @@ #include <stdarg.h> #include <stdio.h> -#include "py/obj.h" #include "py/emit.h" +#include "py/runtime.h" #if MICROPY_WARNINGS diff --git a/stmhal/printf.c b/stmhal/printf.c index a239e898c96749255b73662bc8d08ea6307888ad..f7a4f1038f9c8581f5cd5709fd65d8660f0a5c22 100644 --- a/stmhal/printf.c +++ b/stmhal/printf.c @@ -36,8 +36,6 @@ #include "py/formatfloat.h" #endif -int pfenv_vprintf(const pfenv_t *pfenv, const char *fmt, va_list args); - STATIC void stdout_print_strn(void *dummy_env, const char *str, mp_uint_t len) { stdout_tx_strn_cooked(str, len); } diff --git a/unix/file.c b/unix/file.c index b62154baaac76ded2e3fe4078daffc83c05a41a0..7f1b285a5d13524de9b0279b086777de1226553c 100644 --- a/unix/file.c +++ b/unix/file.c @@ -34,6 +34,7 @@ #include "py/nlr.h" #include "py/runtime.h" #include "py/stream.h" +#include "py/builtin.h" #ifdef _WIN32 #define fsync _commit diff --git a/unix/gccollect.c b/unix/gccollect.c index f8bcbf965decd7f213911243b57e583f3e3e24a0..16bfc3b48677bc5817f93654ec6d7cade250d2f0 100644 --- a/unix/gccollect.c +++ b/unix/gccollect.c @@ -51,7 +51,7 @@ STATIC void gc_helper_get_regs(regs_t arr) { #ifdef __x86_64__ typedef mp_uint_t regs_t[6]; -void gc_helper_get_regs(regs_t arr) { +STATIC void gc_helper_get_regs(regs_t arr) { register long rbx asm ("rbx"); register long rbp asm ("rbp"); register long r12 asm ("r12"); diff --git a/unix/main.c b/unix/main.c index 3dd71eff8c6c057ecc6996741bd07e802c461e9b..d635127783e13ee1f13139027c324c3d3434a30d 100644 --- a/unix/main.c +++ b/unix/main.c @@ -482,7 +482,6 @@ int main(int argc, char **argv) { } if (mp_verbose_flag) { - extern mp_obj_t mp_micropython_mem_info(mp_uint_t n_args, const mp_obj_t *args); mp_micropython_mem_info(0, NULL); }