>From 40bba9c5cdb7060dd01d1c7d81140779e45a489d Mon Sep 17 00:00:00 2001 From: Danil Antonov <g.danil.a...@gmail.com> Date: Wed, 29 Mar 2017 12:39:40 +0300 Subject: [PATCH 31/43] display: made printf always compile in debug output
Wrapped printf calls inside debug macros (DPRINTF) in `if` statement. This will ensure that printf function will always compile even if debug output is turned off and, in turn, will prevent bitrot of the format strings. Signed-off-by: Danil Antonov <g.danil.a...@gmail.com> --- hw/display/sm501.c | 15 ++++++++++----- hw/display/ssd0303.c | 26 +++++++++++++++----------- hw/display/ssd0323.c | 28 +++++++++++++++------------- 3 files changed, 40 insertions(+), 29 deletions(-) diff --git a/hw/display/sm501.c b/hw/display/sm501.c index 040a0b9..ff16613 100644 --- a/hw/display/sm501.c +++ b/hw/display/sm501.c @@ -52,11 +52,16 @@ //#define DEBUG_SM501 //#define DEBUG_BITBLT -#ifdef DEBUG_SM501 -#define SM501_DPRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__) -#else -#define SM501_DPRINTF(fmt, ...) do {} while(0) -#endif +#ifndef DEBUG_SM501 +#define DEBUG_SM501 0 +#endif + +#define SM501_DPRINTF(fmt, ...) \ + do { \ + if (DEBUG_SM501) { \ + fprintf(stderr, fmt, ## __VA_ARGS__); \ + } \ + } while (0) #define MMIO_BASE_OFFSET 0x3e00000 diff --git a/hw/display/ssd0303.c b/hw/display/ssd0303.c index 68a80b9..35ce7c4 100644 --- a/hw/display/ssd0303.c +++ b/hw/display/ssd0303.c @@ -14,18 +14,22 @@ #include "hw/i2c/i2c.h" #include "ui/console.h" -//#define DEBUG_SSD0303 1 +#ifndef DEBUG_SSD0303 +#define DEBUG_SSD0303 0 +#endif -#ifdef DEBUG_SSD0303 -#define DPRINTF(fmt, ...) \ -do { printf("ssd0303: " fmt , ## __VA_ARGS__); } while (0) -#define BADF(fmt, ...) \ -do { fprintf(stderr, "ssd0303: error: " fmt , ## __VA_ARGS__); exit(1);} while (0) -#else -#define DPRINTF(fmt, ...) do {} while(0) -#define BADF(fmt, ...) \ -do { fprintf(stderr, "ssd0303: error: " fmt , ## __VA_ARGS__);} while (0) -#endif +#define DPRINTF(fmt, ...) do { \ + if (DEBUG_SSD0303) { \ + fprintf(stderr, "ssd0303: " fmt , ## __VA_ARGS__); \ + } \ +} while (0); + +#define BADF(fmt, ...) do { \ + fprintf(stderr, "ssd0303: error: " fmt , ## __VA_ARGS__); \ + if (DEBUG_SSD0303) { \ + exit(1); \ + } \ +} while (0); /* Scaling factor for pixels. */ #define MAGNIFY 4 diff --git a/hw/display/ssd0323.c b/hw/display/ssd0323.c index e182893..70b1e33 100644 --- a/hw/display/ssd0323.c +++ b/hw/display/ssd0323.c @@ -14,20 +14,22 @@ #include "hw/ssi/ssi.h" #include "ui/console.h" -//#define DEBUG_SSD0323 1 +#ifndef DEBUG_SSD0323 +#define DEBUG_SSD0323 0 +#endif -#ifdef DEBUG_SSD0323 -#define DPRINTF(fmt, ...) \ -do { printf("ssd0323: " fmt , ## __VA_ARGS__); } while (0) -#define BADF(fmt, ...) \ -do { \ - fprintf(stderr, "ssd0323: error: " fmt , ## __VA_ARGS__); abort(); \ -} while (0) -#else -#define DPRINTF(fmt, ...) do {} while(0) -#define BADF(fmt, ...) \ -do { fprintf(stderr, "ssd0323: error: " fmt , ## __VA_ARGS__);} while (0) -#endif +#define DPRINTF(fmt, ...) do { \ + if (DEBUG_SSD0323) { \ + fprintf(stderr, "ssd0323: " fmt , ## __VA_ARGS__); \ + } \ +} while (0); + +#define BADF(fmt, ...) do { \ + fprintf(stderr, "ssd0323: error: " fmt , ## __VA_ARGS__); \ + if (DEBUG_SSD0323) { \ + abort(); \ + } \ +} while (0); /* Scaling factor for pixels. */ #define MAGNIFY 4 -- 2.8.0.rc3