lib/utils/printf: Make DEBUG_printf implementation more accessible.
The definition of DEBUG_printf doesn't depend on
MICROPY_USE_INTERNAL_PRINTF so move it out of that preprocessor
block and compile it conditionally just depending on the
MICROPY_DEBUG_PRINTERS macro. This allows a port to use DEBUG_printf
while providing it's own printf definition.
#include "py/mpconfig.h"
-#if MICROPY_USE_INTERNAL_PRINTF
-
#include <stdint.h>
#include <string.h>
#include <stdarg.h>
#include "py/formatfloat.h"
#endif
+#if MICROPY_DEBUG_PRINTERS
+int DEBUG_printf(const char *fmt, ...) {
+ va_list ap;
+ va_start(ap, fmt);
+ #ifndef MICROPY_DEBUG_PRINTER_DEST
+ #define MICROPY_DEBUG_PRINTER_DEST mp_plat_print
+ #endif
+ extern const mp_print_t MICROPY_DEBUG_PRINTER_DEST;
+ int ret = mp_vprintf(&MICROPY_DEBUG_PRINTER_DEST, fmt, ap);
+ va_end(ap);
+ return ret;
+}
+#endif
+
+#if MICROPY_USE_INTERNAL_PRINTF
+
#undef putchar // Some stdlibs have a #define for putchar
int printf(const char *fmt, ...);
int vprintf(const char *fmt, va_list ap);
@@ -59,20 +73,6 @@ int vprintf(const char *fmt, va_list ap) {
return mp_vprintf(&mp_plat_print, fmt, ap);
}
-#if MICROPY_DEBUG_PRINTERS
-int DEBUG_printf(const char *fmt, ...) {
- va_list ap;
- va_start(ap, fmt);
- #ifndef MICROPY_DEBUG_PRINTER_DEST
- #define MICROPY_DEBUG_PRINTER_DEST mp_plat_print
- #endif
- extern const mp_print_t MICROPY_DEBUG_PRINTER_DEST;
- int ret = mp_vprintf(&MICROPY_DEBUG_PRINTER_DEST, fmt, ap);
- va_end(ap);
- return ret;
-}
-#endif
-
// need this because gcc optimises printf("%c", c) -> putchar(c), and printf("a") -> putchar('a')
int putchar(int c) {
char chr = c;
