Skip to content

Commit e2ac8bb

Browse files
dxxbdpgeorge
authored andcommitted
py: Add MICROPY_USE_INTERNAL_PRINTF option, defaults to enabled.
This new config option allows to control whether MicroPython uses its own internal printf or not (if not, an external one should be linked in). Accompanying this new option is the inclusion of lib/utils/printf.c in the core list of source files, so that ports no longer need to include it themselves.
1 parent cac8dc3 commit e2ac8bb

11 files changed

Lines changed: 14 additions & 6 deletions

File tree

bare-arm/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#define MICROPY_CPYTHON_COMPAT (0)
4343
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_NONE)
4444
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_NONE)
45+
#define MICROPY_USE_INTERNAL_PRINTF (0)
4546

4647
// type definitions for the specific machine
4748

cc3200/application.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ APP_LIB_SRC_C = $(addprefix lib/,\
154154
timeutils/timeutils.c \
155155
utils/pyexec.c \
156156
utils/pyhelp.c \
157-
utils/printf.c \
158157
)
159158

160159
APP_STM_SRC_C = $(addprefix stmhal/,\

esp8266/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ LIB_SRC_C = $(addprefix lib/,\
128128
timeutils/timeutils.c \
129129
utils/pyexec.c \
130130
utils/pyhelp.c \
131-
utils/printf.c \
132131
fatfs/ff.c \
133132
fatfs/option/ccsbcs.c \
134133
)

lib/utils/printf.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
* THE SOFTWARE.
2525
*/
2626

27+
#include "py/mpconfig.h"
28+
29+
#if MICROPY_USE_INTERNAL_PRINTF
30+
2731
#include <stdint.h>
2832
#include <string.h>
2933
#include <stdarg.h>
@@ -127,3 +131,5 @@ int snprintf(char *str, size_t size, const char *fmt, ...) {
127131
va_end(ap);
128132
return ret;
129133
}
134+
135+
#endif //MICROPY_USE_INTERNAL_PRINTF

minimal/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ SRC_C = \
4646
main.c \
4747
uart_core.c \
4848
lib/utils/stdout_helpers.c \
49-
lib/utils/printf.c \
5049
lib/utils/pyexec.c \
5150
lib/libc/string0.c \
5251
lib/mp-readline/readline.c \

py/mpconfig.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,11 @@ typedef double mp_float_t;
581581
#define MICROPY_USE_INTERNAL_ERRNO (0)
582582
#endif
583583

584+
// Whether to use internally defined *printf() functions (otherwise external ones)
585+
#ifndef MICROPY_USE_INTERNAL_PRINTF
586+
#define MICROPY_USE_INTERNAL_PRINTF (1)
587+
#endif
588+
584589
// Support for user-space VFS mount (selected ports)
585590
#ifndef MICROPY_FSUSERMOUNT
586591
#define MICROPY_FSUSERMOUNT (0)

py/py.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ PY_O_BASENAME = \
223223
../extmod/vfs_fat_misc.o \
224224
../extmod/moduos_dupterm.o \
225225
../lib/embed/abort_.o \
226+
../lib/utils/printf.o \
226227

227228
# prepend the build destination prefix to the py object files
228229
PY_O = $(addprefix $(PY_BUILD)/, $(PY_O_BASENAME))

qemu-arm/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#define MICROPY_PY_IO (0)
2424
#define MICROPY_PY_SYS_EXIT (1)
2525
#define MICROPY_PY_SYS_MAXSIZE (1)
26+
#define MICROPY_USE_INTERNAL_PRINTF (0)
2627

2728
// type definitions for the specific machine
2829

stmhal/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ SRC_LIB = $(addprefix lib/,\
111111
timeutils/timeutils.c \
112112
utils/pyexec.c \
113113
utils/pyhelp.c \
114-
utils/printf.c \
115114
)
116115

117116
SRC_C = \

teensy/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ LIB_SRC_C = $(addprefix lib/,\
110110
mp-readline/readline.c \
111111
utils/pyexec.c \
112112
utils/pyhelp.c \
113-
utils/printf.c \
114113
)
115114

116115
SRC_TEENSY = $(addprefix core/,\

0 commit comments

Comments
 (0)