From a105522e0af6b7a8128bd9cda891ef606d1168ab Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 9 Jun 2015 12:38:06 -0400 Subject: [PATCH] Added more robust debugger logging to the Windows backend, PROPERLY this time. --- redo/windows/GNUmakeinc.mk | 1 + redo/windows/logging.c | 58 ++++++++++++++++++++++++++++++++++++++ redo/windows/util.c | 13 --------- 3 files changed, 59 insertions(+), 13 deletions(-) create mode 100644 redo/windows/logging.c diff --git a/redo/windows/GNUmakeinc.mk b/redo/windows/GNUmakeinc.mk index 790a795e..11064eab 100644 --- a/redo/windows/GNUmakeinc.mk +++ b/redo/windows/GNUmakeinc.mk @@ -15,6 +15,7 @@ osCFILES = \ windows/group.c \ windows/init.c \ windows/label.c \ + windows/logging.c \ windows/main.c \ windows/menu.c \ windows/parent.c \ diff --git a/redo/windows/logging.c b/redo/windows/logging.c new file mode 100644 index 00000000..e9bd0059 --- /dev/null +++ b/redo/windows/logging.c @@ -0,0 +1,58 @@ +// 9 june 2015 +#include "uipriv_windows.h" + +// We can't use the private heap for these functions, since they are allowed to be run before uiInit() or after uiUninit(). + +static void nomemlog(void) +{ + OutputDebugStringW(L"[libui] memory exhausted logging message"); + DebugBreak(); + abort(); // just in case +} + +void uiLog(const char *format, ...) +{ + va_list ap; + + va_start(ap, format); + uiLogv(format, ap); + va_end(ap); +} + +void uiLogv(const char *format, va_list ap) +{ + va_list ap2; + int n; + char *buf; + + va_copy(ap2, ap); + n = _vscprintf(format, ap2); + va_end(ap2); + // "[libui] message\0" == (8 + n + 1) + buf = (char *) malloc((8 + n + 1) + if (buf == NULL) + nomemlog(); + buf[0] = '['; + buf[1] = 'l'; + buf[2] = 'i'; + buf[3] = 'b'; + buf[4] = 'u'; + buf[5] = 'i'; + buf[6] = ']'; + buf[7] = ' '; + vsnprintf_s(buf + 8, n + 1, n, format, ap); + // breaking the rules: we can't reliably tell that the encoding of debugging messages is UTF-8 like we could with everything else :/ + OutputDebugStringA(buf); + free(buf); +} + +void complain(const char *format, ...) +{ + va_list ap; + + va_start(ap, format); + uiLogv(format, av); + va_end(ap); + DebugBreak(); + abort(); // just in case +} diff --git a/redo/windows/util.c b/redo/windows/util.c index eb5a0e30..082c9143 100644 --- a/redo/windows/util.c +++ b/redo/windows/util.c @@ -34,19 +34,6 @@ int windowClassOf(HWND hwnd, ...) return -1; } -void complain(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - fprintf(stderr, "[libui] "); - vfprintf(stderr, fmt, ap); - fprintf(stderr, "\n"); - va_end(ap); - DebugBreak(); - abort(); // just in case -} - // wrapper around MapWindowRect() that handles the complex error handling void mapWindowRect(HWND from, HWND to, RECT *r) {