summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-02-16 18:11:42 +0200
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-02-16 18:20:49 +0200
commit44739e280e81c2ebf2491818eb5a6d0ef30c7c6b (patch)
treeb3dd81094d08289663452e9c9b744b37750e3869
parent1b694c082eeda7b147ac7873964a3dd7bb9583a3 (diff)
downloadmicropython-44739e280e81c2ebf2491818eb5a6d0ef30c7c6b.tar.gz
micropython-44739e280e81c2ebf2491818eb5a6d0ef30c7c6b.zip
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).
-rw-r--r--py/gc.c2
-rw-r--r--py/malloc.c2
-rw-r--r--py/misc.h3
-rw-r--r--py/qstr.c3
-rw-r--r--py/runtime.c4
-rw-r--r--stm/printf.c11
-rw-r--r--unix/main.c9
7 files changed, 28 insertions, 6 deletions
diff --git a/py/gc.c b/py/gc.c
index e66a6832d4..8c4bc691e8 100644
--- a/py/gc.c
+++ b/py/gc.c
@@ -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
diff --git a/py/malloc.c b/py/malloc.c
index 5699d86b64..41cf1fd131 100644
--- a/py/malloc.c
+++ b/py/malloc.c
@@ -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
diff --git a/py/misc.h b/py/misc.h
index 065b070892..989650c17a 100644
--- a/py/misc.h
+++ b/py/misc.h
@@ -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
diff --git a/py/qstr.c b/py/qstr.c
index e4f02236e6..a34479cbfd 100644
--- a/py/qstr.c
+++ b/py/qstr.c
@@ -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
diff --git a/py/runtime.c b/py/runtime.c
index 9d93dbf2ad..9fc0b97088 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -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
diff --git a/stm/printf.c b/stm/printf.c
index a0620018cc..7bac07ab72 100644
--- a/stm/printf.c
+++ b/stm/printf.c
@@ -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;
diff --git a/unix/main.c b/unix/main.c
index 8e6a76bbad..9d07b842b1 100644
--- a/unix/main.c
+++ b/unix/main.c
@@ -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;
+}