Skip to content

Commit 44739e2

Browse files
committed
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).
1 parent 1b694c0 commit 44739e2

File tree

7 files changed

+28
-6
lines changed

7 files changed

+28
-6
lines changed

py/gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#if 0 // print debugging info
1212
#define DEBUG_PRINT (1)
13-
#define DEBUG_printf(args...) printf(args)
13+
#define DEBUG_printf DEBUG_printf
1414
#else // don't print debugging info
1515
#define DEBUG_printf(args...) (void)0
1616
#endif

py/malloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "mpconfig.h"
77

88
#if 0 // print debugging info
9-
#define DEBUG_printf(args...) printf(args)
9+
#define DEBUG_printf DEBUG_printf
1010
#else // don't print debugging info
1111
#define DEBUG_printf(args...) (void)0
1212
#endif

py/misc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,7 @@ void vstr_printf(vstr_t *vstr, const char *fmt, ...);
117117
void vstr_vprintf(vstr_t *vstr, const char *fmt, va_list ap);
118118
#endif
119119

120+
// Debugging helpers
121+
int DEBUG_printf(const char *fmt, ...);
122+
120123
#endif // _INCLUDED_MINILIB_H

py/qstr.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
// also probably need to include the length in the string data, to allow null bytes in the string
1111

1212
#if 0 // print debugging info
13-
#include <stdio.h>
14-
#define DEBUG_printf(args...) printf(args)
13+
#define DEBUG_printf DEBUG_printf
1514
#else // don't print debugging info
1615
#define DEBUG_printf(args...) (void)0
1716
#endif

py/runtime.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
#if 0 // print debugging info
2424
#define DEBUG_PRINT (1)
2525
#define WRITE_CODE (1)
26-
#define DEBUG_printf(args...) printf(args)
27-
#define DEBUG_OP_printf(args...) printf(args)
26+
#define DEBUG_printf DEBUG_printf
27+
#define DEBUG_OP_printf(args...) DEBUG_printf(args)
2828
#else // don't print debugging info
2929
#define DEBUG_printf(args...) (void)0
3030
#define DEBUG_OP_printf(args...) (void)0

stm/printf.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,17 @@ int vprintf(const char *fmt, va_list ap) {
267267
return pfenv_printf(&pfenv_stdout, fmt, ap);
268268
}
269269

270+
#if MICROPY_DEBUG_PRINTERS
271+
int DEBUG_printf(const char *fmt, ...) {
272+
(void)stream;
273+
va_list ap;
274+
va_start(ap, fmt);
275+
int ret = pfenv_printf(&pfenv_stdout, fmt, ap);
276+
va_end(ap);
277+
return ret;
278+
}
279+
#endif
280+
270281
// need this because gcc optimises printf("%c", c) -> putchar(c), and printf("a") -> putchar('a')
271282
int putchar(int c) {
272283
char chr = c;

unix/main.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <stdio.h>
33
#include <string.h>
44
#include <stdlib.h>
5+
#include <stdarg.h>
56

67
#include "nlr.h"
78
#include "misc.h"
@@ -374,3 +375,11 @@ uint mp_import_stat(const char *path) {
374375
}
375376
return MP_IMPORT_STAT_NO_EXIST;
376377
}
378+
379+
int DEBUG_printf(const char *fmt, ...) {
380+
va_list ap;
381+
va_start(ap, fmt);
382+
int ret = vfprintf(stderr, fmt, ap);
383+
va_end(ap);
384+
return ret;
385+
}

0 commit comments

Comments
 (0)