From e72cda99fd5fc9e7c6476eb8574c4401d3ef9560 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 11 Apr 2015 12:15:47 +0100 Subject: [PATCH] py: Convert occurrences of non-debug printf to mp_printf. --- py/emitbc.c | 2 +- py/emitnative.c | 24 ++++++++++++------------ py/gc.c | 17 +++++++++-------- py/modbuiltins.c | 10 +++++----- py/modmicropython.c | 8 ++++---- py/qstr.c | 2 +- py/warning.c | 6 +++--- 7 files changed, 35 insertions(+), 34 deletions(-) diff --git a/py/emitbc.c b/py/emitbc.c index 32d45db388..8d482afe52 100644 --- a/py/emitbc.c +++ b/py/emitbc.c @@ -341,7 +341,7 @@ void mp_emit_bc_end_pass(emit_t *emit) { // check stack is back to zero size if (emit->stack_size != 0) { - printf("ERROR: stack size not back to zero; got %d\n", emit->stack_size); + mp_printf(&mp_plat_print, "ERROR: stack size not back to zero; got %d\n", emit->stack_size); } *emit_get_cur_to_write_code_info(emit, 1) = 0; // end of line number info diff --git a/py/emitnative.c b/py/emitnative.c index ff57ef1a36..a42f09b9fd 100644 --- a/py/emitnative.c +++ b/py/emitnative.c @@ -571,7 +571,7 @@ STATIC void emit_native_set_native_type(emit_t *emit, mp_uint_t op, mp_uint_t ar case MP_QSTR_ptr: type = VTYPE_PTR; break; case MP_QSTR_ptr8: type = VTYPE_PTR8; break; case MP_QSTR_ptr16: type = VTYPE_PTR16; break; - default: printf("ViperTypeError: unknown type %s\n", qstr_str(arg2)); return; + default: mp_printf(&mp_plat_print, "ViperTypeError: unknown type %s\n", qstr_str(arg2)); return; } if (op == MP_EMIT_NATIVE_TYPE_RETURN) { emit->return_vtype = type; @@ -797,7 +797,7 @@ STATIC void emit_native_end_pass(emit_t *emit) { // check stack is back to zero size if (emit->stack_size != 0) { - printf("ERROR: stack size not back to zero; got %d\n", emit->stack_size); + mp_printf(&mp_plat_print, "ERROR: stack size not back to zero; got %d\n", emit->stack_size); } if (emit->pass == MP_PASS_EMIT) { @@ -1288,7 +1288,7 @@ STATIC void emit_native_load_fast(emit_t *emit, qstr qst, mp_uint_t local_num) { DEBUG_printf("load_fast(%s, " UINT_FMT ")\n", qstr_str(qst), local_num); vtype_kind_t vtype = emit->local_vtype[local_num]; if (vtype == VTYPE_UNBOUND) { - printf("ViperTypeError: local %s used before type known\n", qstr_str(qst)); + mp_printf(&mp_plat_print, "ViperTypeError: local %s used before type known\n", qstr_str(qst)); } emit_native_pre(emit); if (local_num == 0) { @@ -1438,7 +1438,7 @@ STATIC void emit_native_load_subscr(emit_t *emit) { break; } default: - printf("ViperTypeError: can't load from type %d\n", vtype_base); + mp_printf(&mp_plat_print, "ViperTypeError: can't load from type %d\n", vtype_base); } } else { // index is not an immediate @@ -1464,7 +1464,7 @@ STATIC void emit_native_load_subscr(emit_t *emit) { break; } default: - printf("ViperTypeError: can't load from type %d\n", vtype_base); + mp_printf(&mp_plat_print, "ViperTypeError: can't load from type %d\n", vtype_base); } } emit_post_push_reg(emit, VTYPE_INT, REG_RET); @@ -1495,7 +1495,7 @@ STATIC void emit_native_store_fast(emit_t *emit, qstr qst, mp_uint_t local_num) emit->local_vtype[local_num] = vtype; } else if (emit->local_vtype[local_num] != vtype) { // type of local is not the same as object stored in it - printf("ViperTypeError: type mismatch, local %s has type %d but source object has type %d\n", qstr_str(qst), emit->local_vtype[local_num], vtype); + mp_printf(&mp_plat_print, "ViperTypeError: type mismatch, local %s has type %d but source object has type %d\n", qstr_str(qst), emit->local_vtype[local_num], vtype); } } @@ -1625,7 +1625,7 @@ STATIC void emit_native_store_subscr(emit_t *emit) { break; } default: - printf("ViperTypeError: can't store to type %d\n", vtype_base); + mp_printf(&mp_plat_print, "ViperTypeError: can't store to type %d\n", vtype_base); } } else { // index is not an immediate @@ -1666,7 +1666,7 @@ STATIC void emit_native_store_subscr(emit_t *emit) { break; } default: - printf("ViperTypeError: can't store to type %d\n", vtype_base); + mp_printf(&mp_plat_print, "ViperTypeError: can't store to type %d\n", vtype_base); } } @@ -1778,7 +1778,7 @@ STATIC void emit_native_jump_helper(emit_t *emit, bool pop) { } break; default: - printf("ViperTypeError: expecting a bool or pyobj, got %d\n", vtype); + mp_printf(&mp_plat_print, "ViperTypeError: expecting a bool or pyobj, got %d\n", vtype); assert(0); } // For non-pop need to save the vtype so that emit_native_adjust_stack_size @@ -2056,7 +2056,7 @@ STATIC void emit_native_binary_op(emit_t *emit, mp_binary_op_t op) { } emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } else { - printf("ViperTypeError: can't do binary op between types %d and %d\n", vtype_lhs, vtype_rhs); + mp_printf(&mp_plat_print, "ViperTypeError: can't do binary op between types %d and %d\n", vtype_lhs, vtype_rhs); emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } } @@ -2302,7 +2302,7 @@ STATIC void emit_native_return_value(emit_t *emit) { vtype_kind_t vtype; emit_pre_pop_reg(emit, &vtype, REG_RET); if (vtype != emit->return_vtype) { - printf("ViperTypeError: incompatible return type\n"); + mp_printf(&mp_plat_print, "ViperTypeError: incompatible return type\n"); } } } else { @@ -2320,7 +2320,7 @@ STATIC void emit_native_raise_varargs(emit_t *emit, mp_uint_t n_args) { vtype_kind_t vtype_exc; emit_pre_pop_reg(emit, &vtype_exc, REG_ARG_1); // arg1 = object to raise if (vtype_exc != VTYPE_PYOBJ) { - printf("ViperTypeError: must raise an object\n"); + mp_printf(&mp_plat_print, "ViperTypeError: must raise an object\n"); } // TODO probably make this 1 call to the runtime (which could even call convert, native_raise(obj, type)) emit_call(emit, MP_F_NATIVE_RAISE); diff --git a/py/gc.c b/py/gc.c index 7e9b2c53c0..6cdafc03b1 100644 --- a/py/gc.c +++ b/py/gc.c @@ -648,8 +648,9 @@ void *gc_realloc(void *ptr_in, mp_uint_t n_bytes) { void gc_dump_info(void) { gc_info_t info; gc_info(&info); - printf("GC: total: " UINT_FMT ", used: " UINT_FMT ", free: " UINT_FMT "\n", info.total, info.used, info.free); - printf(" No. of 1-blocks: " UINT_FMT ", 2-blocks: " UINT_FMT ", max blk sz: " UINT_FMT "\n", + mp_printf(&mp_plat_print, "GC: total: " UINT_FMT ", used: " UINT_FMT ", free: " UINT_FMT "\n", + info.total, info.used, info.free); + mp_printf(&mp_plat_print, " No. of 1-blocks: " UINT_FMT ", 2-blocks: " UINT_FMT ", max blk sz: " UINT_FMT "\n", info.num_1block, info.num_2block, info.max_block); } @@ -658,7 +659,7 @@ void gc_dump_alloc_table(void) { #if !EXTENSIVE_HEAP_PROFILING // When comparing heap output we don't want to print the starting // pointer of the heap because it changes from run to run. - printf("GC memory layout; from %p:", MP_STATE_MEM(gc_pool_start)); + mp_printf(&mp_plat_print, "GC memory layout; from %p:", MP_STATE_MEM(gc_pool_start)); #endif for (mp_uint_t bl = 0; bl < MP_STATE_MEM(gc_alloc_table_byte_len) * BLOCKS_PER_ATB; bl++) { if (bl % DUMP_BYTES_PER_LINE == 0) { @@ -671,7 +672,7 @@ void gc_dump_alloc_table(void) { } if (bl2 - bl >= 2 * DUMP_BYTES_PER_LINE) { // there are at least 2 lines containing only free blocks, so abbreviate their printing - printf("\n (" UINT_FMT " lines all free)", (bl2 - bl) / DUMP_BYTES_PER_LINE); + mp_printf(&mp_plat_print, "\n (" UINT_FMT " lines all free)", (bl2 - bl) / DUMP_BYTES_PER_LINE); bl = bl2 & (~(DUMP_BYTES_PER_LINE - 1)); if (bl >= MP_STATE_MEM(gc_alloc_table_byte_len) * BLOCKS_PER_ATB) { // got to end of heap @@ -682,9 +683,9 @@ void gc_dump_alloc_table(void) { // print header for new line of blocks // (the cast to uint32_t is for 16-bit ports) #if EXTENSIVE_HEAP_PROFILING - printf("\n%05x: ", (uint)((bl * BYTES_PER_BLOCK) & (uint32_t)0xfffff)); + mp_printf(&mp_plat_print, "\n%05x: ", (uint)((bl * BYTES_PER_BLOCK) & (uint32_t)0xfffff)); #else - printf("\n%05x: ", (uint)(PTR_FROM_BLOCK(bl) & (uint32_t)0xfffff)); + mp_printf(&mp_plat_print, "\n%05x: ", (uint)(PTR_FROM_BLOCK(bl) & (uint32_t)0xfffff)); #endif } int c = ' '; @@ -752,9 +753,9 @@ void gc_dump_alloc_table(void) { case AT_TAIL: c = 't'; break; case AT_MARK: c = 'm'; break; } - printf("%c", c); + mp_printf(&mp_plat_print, "%c", c); } - printf("\n"); + mp_print_str(&mp_plat_print, "\n"); } #if DEBUG_PRINT diff --git a/py/modbuiltins.c b/py/modbuiltins.c index f001d7057f..877c655d6c 100644 --- a/py/modbuiltins.c +++ b/py/modbuiltins.c @@ -419,19 +419,19 @@ STATIC mp_obj_t mp_builtin_print(mp_uint_t n_args, const mp_obj_t *args, mp_map_ #if MICROPY_PY_IO mp_stream_write(stream_obj, sep_data, sep_len); #else - printf("%.*s", (int)sep_len, sep_data); + mp_print_strn(&mp_plat_print, sep_data, sep_len, 0, 0, 0); #endif } #if MICROPY_PY_IO mp_obj_print_helper(&print, args[i], PRINT_STR); #else - mp_obj_print(args[i], PRINT_STR); + mp_obj_print_helper(&mp_plat_print, args[i], PRINT_STR); #endif } #if MICROPY_PY_IO mp_stream_write(stream_obj, end_data, end_len); #else - printf("%.*s", (int)end_len, end_data); + mp_print_strn(&mp_plat_print, end_data, end_len, 0, 0, 0); #endif return mp_const_none; } @@ -443,8 +443,8 @@ STATIC mp_obj_t mp_builtin___repl_print__(mp_obj_t o) { mp_obj_print_helper(&mp_sys_stdout_print, o, PRINT_REPR); mp_print_str(&mp_sys_stdout_print, "\n"); #else - mp_obj_print(o, PRINT_REPR); - printf("\n"); + mp_obj_print_helper(&mp_plat_print, o, PRINT_REPR); + mp_print_str(&mp_plat_print, "\n"); #endif } return mp_const_none; diff --git a/py/modmicropython.c b/py/modmicropython.c index 1ed0936ce3..07389c8a7d 100644 --- a/py/modmicropython.c +++ b/py/modmicropython.c @@ -56,13 +56,13 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_mem_peak_obj, mp_micropython_mem mp_obj_t mp_micropython_mem_info(mp_uint_t n_args, const mp_obj_t *args) { (void)args; #if MICROPY_MEM_STATS - printf("mem: total=" UINT_FMT ", current=" UINT_FMT ", peak=" UINT_FMT "\n", + mp_printf(&mp_plat_print, "mem: total=" UINT_FMT ", current=" UINT_FMT ", peak=" UINT_FMT "\n", (mp_uint_t)m_get_total_bytes_allocated(), (mp_uint_t)m_get_current_bytes_allocated(), (mp_uint_t)m_get_peak_bytes_allocated()); #endif #if MICROPY_STACK_CHECK - printf("stack: " UINT_FMT " out of " INT_FMT "\n", mp_stack_usage(), MP_STATE_VM(stack_limit)); + mp_printf(&mp_plat_print, "stack: " UINT_FMT " out of " INT_FMT "\n", mp_stack_usage(), MP_STATE_VM(stack_limit)); #else - printf("stack: " UINT_FMT "\n", mp_stack_usage()); + mp_printf(&mp_plat_print, "stack: " UINT_FMT "\n", mp_stack_usage()); #endif #if MICROPY_ENABLE_GC gc_dump_info(); @@ -81,7 +81,7 @@ STATIC mp_obj_t mp_micropython_qstr_info(mp_uint_t n_args, const mp_obj_t *args) (void)args; mp_uint_t n_pool, n_qstr, n_str_data_bytes, n_total_bytes; qstr_pool_info(&n_pool, &n_qstr, &n_str_data_bytes, &n_total_bytes); - printf("qstr pool: n_pool=" UINT_FMT ", n_qstr=" UINT_FMT ", n_str_data_bytes=" UINT_FMT ", n_total_bytes=" UINT_FMT "\n", + mp_printf(&mp_plat_print, "qstr pool: n_pool=" UINT_FMT ", n_qstr=" UINT_FMT ", n_str_data_bytes=" UINT_FMT ", n_total_bytes=" UINT_FMT "\n", n_pool, n_qstr, n_str_data_bytes, n_total_bytes); if (n_args == 1) { // arg given means dump qstr data diff --git a/py/qstr.c b/py/qstr.c index 2d57f22221..b1ae6ac74c 100644 --- a/py/qstr.c +++ b/py/qstr.c @@ -235,7 +235,7 @@ void qstr_pool_info(mp_uint_t *n_pool, mp_uint_t *n_qstr, mp_uint_t *n_str_data_ void qstr_dump_data(void) { for (qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL && pool != &const_pool; pool = pool->prev) { for (const byte **q = pool->qstrs, **q_top = pool->qstrs + pool->len; q < q_top; q++) { - printf("Q(%s)\n", Q_GET_DATA(*q)); + mp_printf(&mp_plat_print, "Q(%s)\n", Q_GET_DATA(*q)); } } } diff --git a/py/warning.c b/py/warning.c index 469c19cea7..eae145bd3f 100644 --- a/py/warning.c +++ b/py/warning.c @@ -35,9 +35,9 @@ void mp_warning(const char *msg, ...) { va_list args; va_start(args, msg); - printf("Warning: "); - vprintf(msg, args); - printf("\n"); + mp_print_str(&mp_plat_print, "Warning: "); + mp_vprintf(&mp_plat_print, msg, args); + mp_print_str(&mp_plat_print, "\n"); } void mp_emitter_warning(pass_kind_t pass, const char *msg) {