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.
pull/3920/merge
stijn 2018-07-03 12:22:39 +02:00 zatwierdzone przez Damien George
rodzic 1751f5ac7b
commit 8ad30fa433
1 zmienionych plików z 16 dodań i 16 usunięć

Wyświetl plik

@ -26,8 +26,6 @@
#include "py/mpconfig.h"
#if MICROPY_USE_INTERNAL_PRINTF
#include <stdint.h>
#include <string.h>
#include <stdarg.h>
@ -39,6 +37,22 @@
#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;