Skip to content

Commit e72cda9

Browse files
committed
py: Convert occurrences of non-debug printf to mp_printf.
1 parent 5ae5ec9 commit e72cda9

File tree

7 files changed

+35
-34
lines changed

7 files changed

+35
-34
lines changed

py/emitbc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ void mp_emit_bc_end_pass(emit_t *emit) {
341341

342342
// check stack is back to zero size
343343
if (emit->stack_size != 0) {
344-
printf("ERROR: stack size not back to zero; got %d\n", emit->stack_size);
344+
mp_printf(&mp_plat_print, "ERROR: stack size not back to zero; got %d\n", emit->stack_size);
345345
}
346346

347347
*emit_get_cur_to_write_code_info(emit, 1) = 0; // end of line number info

py/emitnative.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ STATIC void emit_native_set_native_type(emit_t *emit, mp_uint_t op, mp_uint_t ar
571571
case MP_QSTR_ptr: type = VTYPE_PTR; break;
572572
case MP_QSTR_ptr8: type = VTYPE_PTR8; break;
573573
case MP_QSTR_ptr16: type = VTYPE_PTR16; break;
574-
default: printf("ViperTypeError: unknown type %s\n", qstr_str(arg2)); return;
574+
default: mp_printf(&mp_plat_print, "ViperTypeError: unknown type %s\n", qstr_str(arg2)); return;
575575
}
576576
if (op == MP_EMIT_NATIVE_TYPE_RETURN) {
577577
emit->return_vtype = type;
@@ -797,7 +797,7 @@ STATIC void emit_native_end_pass(emit_t *emit) {
797797

798798
// check stack is back to zero size
799799
if (emit->stack_size != 0) {
800-
printf("ERROR: stack size not back to zero; got %d\n", emit->stack_size);
800+
mp_printf(&mp_plat_print, "ERROR: stack size not back to zero; got %d\n", emit->stack_size);
801801
}
802802

803803
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) {
12881288
DEBUG_printf("load_fast(%s, " UINT_FMT ")\n", qstr_str(qst), local_num);
12891289
vtype_kind_t vtype = emit->local_vtype[local_num];
12901290
if (vtype == VTYPE_UNBOUND) {
1291-
printf("ViperTypeError: local %s used before type known\n", qstr_str(qst));
1291+
mp_printf(&mp_plat_print, "ViperTypeError: local %s used before type known\n", qstr_str(qst));
12921292
}
12931293
emit_native_pre(emit);
12941294
if (local_num == 0) {
@@ -1438,7 +1438,7 @@ STATIC void emit_native_load_subscr(emit_t *emit) {
14381438
break;
14391439
}
14401440
default:
1441-
printf("ViperTypeError: can't load from type %d\n", vtype_base);
1441+
mp_printf(&mp_plat_print, "ViperTypeError: can't load from type %d\n", vtype_base);
14421442
}
14431443
} else {
14441444
// index is not an immediate
@@ -1464,7 +1464,7 @@ STATIC void emit_native_load_subscr(emit_t *emit) {
14641464
break;
14651465
}
14661466
default:
1467-
printf("ViperTypeError: can't load from type %d\n", vtype_base);
1467+
mp_printf(&mp_plat_print, "ViperTypeError: can't load from type %d\n", vtype_base);
14681468
}
14691469
}
14701470
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)
14951495
emit->local_vtype[local_num] = vtype;
14961496
} else if (emit->local_vtype[local_num] != vtype) {
14971497
// type of local is not the same as object stored in it
1498-
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);
1498+
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);
14991499
}
15001500
}
15011501

@@ -1625,7 +1625,7 @@ STATIC void emit_native_store_subscr(emit_t *emit) {
16251625
break;
16261626
}
16271627
default:
1628-
printf("ViperTypeError: can't store to type %d\n", vtype_base);
1628+
mp_printf(&mp_plat_print, "ViperTypeError: can't store to type %d\n", vtype_base);
16291629
}
16301630
} else {
16311631
// index is not an immediate
@@ -1666,7 +1666,7 @@ STATIC void emit_native_store_subscr(emit_t *emit) {
16661666
break;
16671667
}
16681668
default:
1669-
printf("ViperTypeError: can't store to type %d\n", vtype_base);
1669+
mp_printf(&mp_plat_print, "ViperTypeError: can't store to type %d\n", vtype_base);
16701670
}
16711671
}
16721672

@@ -1778,7 +1778,7 @@ STATIC void emit_native_jump_helper(emit_t *emit, bool pop) {
17781778
}
17791779
break;
17801780
default:
1781-
printf("ViperTypeError: expecting a bool or pyobj, got %d\n", vtype);
1781+
mp_printf(&mp_plat_print, "ViperTypeError: expecting a bool or pyobj, got %d\n", vtype);
17821782
assert(0);
17831783
}
17841784
// 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) {
20562056
}
20572057
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
20582058
} else {
2059-
printf("ViperTypeError: can't do binary op between types %d and %d\n", vtype_lhs, vtype_rhs);
2059+
mp_printf(&mp_plat_print, "ViperTypeError: can't do binary op between types %d and %d\n", vtype_lhs, vtype_rhs);
20602060
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
20612061
}
20622062
}
@@ -2302,7 +2302,7 @@ STATIC void emit_native_return_value(emit_t *emit) {
23022302
vtype_kind_t vtype;
23032303
emit_pre_pop_reg(emit, &vtype, REG_RET);
23042304
if (vtype != emit->return_vtype) {
2305-
printf("ViperTypeError: incompatible return type\n");
2305+
mp_printf(&mp_plat_print, "ViperTypeError: incompatible return type\n");
23062306
}
23072307
}
23082308
} else {
@@ -2320,7 +2320,7 @@ STATIC void emit_native_raise_varargs(emit_t *emit, mp_uint_t n_args) {
23202320
vtype_kind_t vtype_exc;
23212321
emit_pre_pop_reg(emit, &vtype_exc, REG_ARG_1); // arg1 = object to raise
23222322
if (vtype_exc != VTYPE_PYOBJ) {
2323-
printf("ViperTypeError: must raise an object\n");
2323+
mp_printf(&mp_plat_print, "ViperTypeError: must raise an object\n");
23242324
}
23252325
// TODO probably make this 1 call to the runtime (which could even call convert, native_raise(obj, type))
23262326
emit_call(emit, MP_F_NATIVE_RAISE);

py/gc.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,9 @@ void *gc_realloc(void *ptr_in, mp_uint_t n_bytes) {
648648
void gc_dump_info(void) {
649649
gc_info_t info;
650650
gc_info(&info);
651-
printf("GC: total: " UINT_FMT ", used: " UINT_FMT ", free: " UINT_FMT "\n", info.total, info.used, info.free);
652-
printf(" No. of 1-blocks: " UINT_FMT ", 2-blocks: " UINT_FMT ", max blk sz: " UINT_FMT "\n",
651+
mp_printf(&mp_plat_print, "GC: total: " UINT_FMT ", used: " UINT_FMT ", free: " UINT_FMT "\n",
652+
info.total, info.used, info.free);
653+
mp_printf(&mp_plat_print, " No. of 1-blocks: " UINT_FMT ", 2-blocks: " UINT_FMT ", max blk sz: " UINT_FMT "\n",
653654
info.num_1block, info.num_2block, info.max_block);
654655
}
655656

@@ -658,7 +659,7 @@ void gc_dump_alloc_table(void) {
658659
#if !EXTENSIVE_HEAP_PROFILING
659660
// When comparing heap output we don't want to print the starting
660661
// pointer of the heap because it changes from run to run.
661-
printf("GC memory layout; from %p:", MP_STATE_MEM(gc_pool_start));
662+
mp_printf(&mp_plat_print, "GC memory layout; from %p:", MP_STATE_MEM(gc_pool_start));
662663
#endif
663664
for (mp_uint_t bl = 0; bl < MP_STATE_MEM(gc_alloc_table_byte_len) * BLOCKS_PER_ATB; bl++) {
664665
if (bl % DUMP_BYTES_PER_LINE == 0) {
@@ -671,7 +672,7 @@ void gc_dump_alloc_table(void) {
671672
}
672673
if (bl2 - bl >= 2 * DUMP_BYTES_PER_LINE) {
673674
// there are at least 2 lines containing only free blocks, so abbreviate their printing
674-
printf("\n (" UINT_FMT " lines all free)", (bl2 - bl) / DUMP_BYTES_PER_LINE);
675+
mp_printf(&mp_plat_print, "\n (" UINT_FMT " lines all free)", (bl2 - bl) / DUMP_BYTES_PER_LINE);
675676
bl = bl2 & (~(DUMP_BYTES_PER_LINE - 1));
676677
if (bl >= MP_STATE_MEM(gc_alloc_table_byte_len) * BLOCKS_PER_ATB) {
677678
// got to end of heap
@@ -682,9 +683,9 @@ void gc_dump_alloc_table(void) {
682683
// print header for new line of blocks
683684
// (the cast to uint32_t is for 16-bit ports)
684685
#if EXTENSIVE_HEAP_PROFILING
685-
printf("\n%05x: ", (uint)((bl * BYTES_PER_BLOCK) & (uint32_t)0xfffff));
686+
mp_printf(&mp_plat_print, "\n%05x: ", (uint)((bl * BYTES_PER_BLOCK) & (uint32_t)0xfffff));
686687
#else
687-
printf("\n%05x: ", (uint)(PTR_FROM_BLOCK(bl) & (uint32_t)0xfffff));
688+
mp_printf(&mp_plat_print, "\n%05x: ", (uint)(PTR_FROM_BLOCK(bl) & (uint32_t)0xfffff));
688689
#endif
689690
}
690691
int c = ' ';
@@ -752,9 +753,9 @@ void gc_dump_alloc_table(void) {
752753
case AT_TAIL: c = 't'; break;
753754
case AT_MARK: c = 'm'; break;
754755
}
755-
printf("%c", c);
756+
mp_printf(&mp_plat_print, "%c", c);
756757
}
757-
printf("\n");
758+
mp_print_str(&mp_plat_print, "\n");
758759
}
759760

760761
#if DEBUG_PRINT

py/modbuiltins.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -419,19 +419,19 @@ STATIC mp_obj_t mp_builtin_print(mp_uint_t n_args, const mp_obj_t *args, mp_map_
419419
#if MICROPY_PY_IO
420420
mp_stream_write(stream_obj, sep_data, sep_len);
421421
#else
422-
printf("%.*s", (int)sep_len, sep_data);
422+
mp_print_strn(&mp_plat_print, sep_data, sep_len, 0, 0, 0);
423423
#endif
424424
}
425425
#if MICROPY_PY_IO
426426
mp_obj_print_helper(&print, args[i], PRINT_STR);
427427
#else
428-
mp_obj_print(args[i], PRINT_STR);
428+
mp_obj_print_helper(&mp_plat_print, args[i], PRINT_STR);
429429
#endif
430430
}
431431
#if MICROPY_PY_IO
432432
mp_stream_write(stream_obj, end_data, end_len);
433433
#else
434-
printf("%.*s", (int)end_len, end_data);
434+
mp_print_strn(&mp_plat_print, end_data, end_len, 0, 0, 0);
435435
#endif
436436
return mp_const_none;
437437
}
@@ -443,8 +443,8 @@ STATIC mp_obj_t mp_builtin___repl_print__(mp_obj_t o) {
443443
mp_obj_print_helper(&mp_sys_stdout_print, o, PRINT_REPR);
444444
mp_print_str(&mp_sys_stdout_print, "\n");
445445
#else
446-
mp_obj_print(o, PRINT_REPR);
447-
printf("\n");
446+
mp_obj_print_helper(&mp_plat_print, o, PRINT_REPR);
447+
mp_print_str(&mp_plat_print, "\n");
448448
#endif
449449
}
450450
return mp_const_none;

py/modmicropython.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_mem_peak_obj, mp_micropython_mem
5656
mp_obj_t mp_micropython_mem_info(mp_uint_t n_args, const mp_obj_t *args) {
5757
(void)args;
5858
#if MICROPY_MEM_STATS
59-
printf("mem: total=" UINT_FMT ", current=" UINT_FMT ", peak=" UINT_FMT "\n",
59+
mp_printf(&mp_plat_print, "mem: total=" UINT_FMT ", current=" UINT_FMT ", peak=" UINT_FMT "\n",
6060
(mp_uint_t)m_get_total_bytes_allocated(), (mp_uint_t)m_get_current_bytes_allocated(), (mp_uint_t)m_get_peak_bytes_allocated());
6161
#endif
6262
#if MICROPY_STACK_CHECK
63-
printf("stack: " UINT_FMT " out of " INT_FMT "\n", mp_stack_usage(), MP_STATE_VM(stack_limit));
63+
mp_printf(&mp_plat_print, "stack: " UINT_FMT " out of " INT_FMT "\n", mp_stack_usage(), MP_STATE_VM(stack_limit));
6464
#else
65-
printf("stack: " UINT_FMT "\n", mp_stack_usage());
65+
mp_printf(&mp_plat_print, "stack: " UINT_FMT "\n", mp_stack_usage());
6666
#endif
6767
#if MICROPY_ENABLE_GC
6868
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)
8181
(void)args;
8282
mp_uint_t n_pool, n_qstr, n_str_data_bytes, n_total_bytes;
8383
qstr_pool_info(&n_pool, &n_qstr, &n_str_data_bytes, &n_total_bytes);
84-
printf("qstr pool: n_pool=" UINT_FMT ", n_qstr=" UINT_FMT ", n_str_data_bytes=" UINT_FMT ", n_total_bytes=" UINT_FMT "\n",
84+
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",
8585
n_pool, n_qstr, n_str_data_bytes, n_total_bytes);
8686
if (n_args == 1) {
8787
// arg given means dump qstr data

py/qstr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ void qstr_pool_info(mp_uint_t *n_pool, mp_uint_t *n_qstr, mp_uint_t *n_str_data_
235235
void qstr_dump_data(void) {
236236
for (qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL && pool != &const_pool; pool = pool->prev) {
237237
for (const byte **q = pool->qstrs, **q_top = pool->qstrs + pool->len; q < q_top; q++) {
238-
printf("Q(%s)\n", Q_GET_DATA(*q));
238+
mp_printf(&mp_plat_print, "Q(%s)\n", Q_GET_DATA(*q));
239239
}
240240
}
241241
}

py/warning.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
void mp_warning(const char *msg, ...) {
3636
va_list args;
3737
va_start(args, msg);
38-
printf("Warning: ");
39-
vprintf(msg, args);
40-
printf("\n");
38+
mp_print_str(&mp_plat_print, "Warning: ");
39+
mp_vprintf(&mp_plat_print, msg, args);
40+
mp_print_str(&mp_plat_print, "\n");
4141
}
4242

4343
void mp_emitter_warning(pass_kind_t pass, const char *msg) {

0 commit comments

Comments
 (0)