Skip to content

Commit c3280d8

Browse files
committed
unix: Use printf() implementation in terms of mp_printf().
In other words, unix port now uses overriden printf(), instead of using libc's. This should remove almost all dependency on libc stdio (which is bloated).
1 parent ede1f54 commit c3280d8

4 files changed

Lines changed: 9 additions & 8 deletions

File tree

lib/utils/printf.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,14 @@ int vprintf(const char *fmt, va_list ap) {
5151
int DEBUG_printf(const char *fmt, ...) {
5252
va_list ap;
5353
va_start(ap, fmt);
54+
#if MICROPY_DEBUG_STDERR
55+
// Printing debug to stderr may give a chance tests which
56+
// check stdout to pass, etc.
57+
extern const mp_print_t mp_stderr_print;
58+
int ret = mp_vprintf(&mp_stderr_print, fmt, ap);
59+
#else
5460
int ret = mp_vprintf(&mp_plat_print, fmt, ap);
61+
#endif
5562
va_end(ap);
5663
return ret;
5764
}

unix/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ endif
129129

130130
LIB_SRC_C = $(addprefix lib/,\
131131
$(LIB_SRC_C_EXTRA) \
132+
utils/printf.c \
132133
)
133134

134135
OBJ = $(PY_O)

unix/main.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -574,14 +574,6 @@ uint mp_import_stat(const char *path) {
574574
return MP_IMPORT_STAT_NO_EXIST;
575575
}
576576

577-
int DEBUG_printf(const char *fmt, ...) {
578-
va_list ap;
579-
va_start(ap, fmt);
580-
int ret = mp_vprintf(&mp_stderr_print, fmt, ap);
581-
va_end(ap);
582-
return ret;
583-
}
584-
585577
void nlr_jump_fail(void *val) {
586578
printf("FATAL: uncaught NLR %p\n", val);
587579
exit(1);

unix/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#define MICROPY_MALLOC_USES_ALLOCATED_SIZE (1)
5151
#define MICROPY_MEM_STATS (1)
5252
#define MICROPY_DEBUG_PRINTERS (1)
53+
#define MICROPY_DEBUG_STDERR (1)
5354
#define MICROPY_USE_READLINE_HISTORY (1)
5455
#define MICROPY_HELPER_REPL (1)
5556
#define MICROPY_REPL_EMACS_KEYS (1)

0 commit comments

Comments
 (0)