Make DEBUG_printf() a proper function, implementation is port-dependent.

In particular, unix outputs to stderr, to allow to run testsuite against
micropython built with debug output (by redirecting stderr to /dev/null).
This commit is contained in:
Paul Sokolovsky 2014-02-16 18:11:42 +02:00
parent 1b694c082e
commit 44739e280e
7 changed files with 28 additions and 6 deletions

View File

@ -10,7 +10,7 @@
#if 0 // print debugging info
#define DEBUG_PRINT (1)
#define DEBUG_printf(args...) printf(args)
#define DEBUG_printf DEBUG_printf
#else // don't print debugging info
#define DEBUG_printf(args...) (void)0
#endif

View File

@ -6,7 +6,7 @@
#include "mpconfig.h"
#if 0 // print debugging info
#define DEBUG_printf(args...) printf(args)
#define DEBUG_printf DEBUG_printf
#else // don't print debugging info
#define DEBUG_printf(args...) (void)0
#endif

View File

@ -117,4 +117,7 @@ void vstr_printf(vstr_t *vstr, const char *fmt, ...);
void vstr_vprintf(vstr_t *vstr, const char *fmt, va_list ap);
#endif
// Debugging helpers
int DEBUG_printf(const char *fmt, ...);
#endif // _INCLUDED_MINILIB_H

View File

@ -10,8 +10,7 @@
// also probably need to include the length in the string data, to allow null bytes in the string
#if 0 // print debugging info
#include <stdio.h>
#define DEBUG_printf(args...) printf(args)
#define DEBUG_printf DEBUG_printf
#else // don't print debugging info
#define DEBUG_printf(args...) (void)0
#endif

View File

@ -23,8 +23,8 @@
#if 0 // print debugging info
#define DEBUG_PRINT (1)
#define WRITE_CODE (1)
#define DEBUG_printf(args...) printf(args)
#define DEBUG_OP_printf(args...) printf(args)
#define DEBUG_printf DEBUG_printf
#define DEBUG_OP_printf(args...) DEBUG_printf(args)
#else // don't print debugging info
#define DEBUG_printf(args...) (void)0
#define DEBUG_OP_printf(args...) (void)0

View File

@ -267,6 +267,17 @@ int vprintf(const char *fmt, va_list ap) {
return pfenv_printf(&pfenv_stdout, fmt, ap);
}
#if MICROPY_DEBUG_PRINTERS
int DEBUG_printf(const char *fmt, ...) {
(void)stream;
va_list ap;
va_start(ap, fmt);
int ret = pfenv_printf(&pfenv_stdout, 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;

View File

@ -2,6 +2,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include "nlr.h"
#include "misc.h"
@ -374,3 +375,11 @@ uint mp_import_stat(const char *path) {
}
return MP_IMPORT_STAT_NO_EXIST;
}
int DEBUG_printf(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
int ret = vfprintf(stderr, fmt, ap);
va_end(ap);
return ret;
}