Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

Commit f64e806

Browse files
eerimoqdpgeorge
authored andcommitted
lib/utils/pyhelp.c: Use mp_printf() instead of printf()
This patch introduces MP_PYTHON_PRINTER for general use.
1 parent 571e6f2 commit f64e806

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

lib/utils/pyhelp.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
#include "lib/utils/pyhelp.h"
3030

3131
STATIC void pyhelp_print_info_about_object(mp_obj_t name_o, mp_obj_t value) {
32-
printf(" ");
32+
mp_printf(MP_PYTHON_PRINTER, " ");
3333
mp_obj_print(name_o, PRINT_STR);
34-
printf(" -- ");
34+
mp_printf(MP_PYTHON_PRINTER, " -- ");
3535
mp_obj_print(value, PRINT_STR);
36-
printf("\n");
36+
mp_printf(MP_PYTHON_PRINTER, "\n");
3737
}
3838

3939
// Helper for 1-argument form of builtin help
@@ -57,9 +57,9 @@ STATIC void pyhelp_print_info_about_object(mp_obj_t name_o, mp_obj_t value) {
5757
//
5858
void pyhelp_print_obj(const mp_obj_t obj) {
5959
// try to print something sensible about the given object
60-
printf("object ");
60+
mp_printf(MP_PYTHON_PRINTER, "object ");
6161
mp_obj_print(obj, PRINT_STR);
62-
printf(" is of type %s\n", mp_obj_get_type_str(obj));
62+
mp_printf(MP_PYTHON_PRINTER, " is of type %s\n", mp_obj_get_type_str(obj));
6363

6464
mp_map_t *map = NULL;
6565
if (MP_OBJ_IS_TYPE(obj, &mp_type_module)) {

py/mpprint.h

+6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@
3939
#define PF_FLAG_ADD_PERCENT (0x100)
4040
#define PF_FLAG_SHOW_OCTAL_LETTER (0x200)
4141

42+
#if MICROPY_PY_IO
43+
# define MP_PYTHON_PRINTER &mp_sys_stdout_print
44+
#else
45+
# define MP_PYTHON_PRINTER &mp_plat_print
46+
#endif
47+
4248
typedef void (*mp_print_strn_t)(void *data, const char *str, size_t len);
4349

4450
typedef struct _mp_print_t {

0 commit comments

Comments
 (0)