From 65226ac4167c8289b7ece1d9a4661a4945388081 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 9 Jun 2019 13:49:53 -0400 Subject: [PATCH] Refactored the programmer error test hook to not needlessly pass in the prefix, suffix, or internal flag, and to allow passing in arbitrary data so we can get rid of the global state in the tests. This will make the tests a LOT easier. --- common/errors.c | 14 +++++++++----- common/testhooks.h | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/common/errors.c b/common/errors.c index 82ba26c6..c7a8448d 100644 --- a/common/errors.c +++ b/common/errors.c @@ -26,13 +26,13 @@ void uiprivInternalError(const char *fmt, ...) // TODO add debugging advice? #define programmerErrorSuffix "This likely means you are using libui incorrectly. Check your source code and try again. If you have received this warning in error, contact the libui authors." -static uiprivTestHookReportProgrammerErrorFunc reportProgrammerErrorTestHook = uiprivReportError; +static uiprivTestHookReportProgrammerErrorFunc reportProgrammerErrorTestHook = NULL; +static void *reportProgrammerErrorTestHookData = NULL; -void uiprivTestHookReportProgrammerError(uiprivTestHookReportProgrammerErrorFunc f) +void uiprivTestHookReportProgrammerError(uiprivTestHookReportProgrammerErrorFunc f, void *data) { - if (f == NULL) - f = uiprivReportError; reportProgrammerErrorTestHook = f; + reportProgrammerErrorTestHookData = data; } void uiprivProgrammerError(const char *fmt, ...) @@ -48,5 +48,9 @@ void uiprivProgrammerError(const char *fmt, ...) if (n >= 256) uiprivInternalError("programmer error string too long (%d)", n); va_end(ap); - (*reportProgrammerErrorTestHook)(programmerErrorPrefix, buf, programmerErrorSuffix, false); + if (reportProgrammerErrorTestHook != NULL) { + (*reportProgrammerErrorTestHook)(buf, reportProgrammerErrorTestHookData); + return; + } + uiprivReportError(programmerErrorPrefix, buf, programmerErrorSuffix, false); } diff --git a/common/testhooks.h b/common/testhooks.h index b1d9ce3d..986c6fc4 100644 --- a/common/testhooks.h +++ b/common/testhooks.h @@ -5,8 +5,8 @@ extern "C" { #endif // errors.c -typedef void (*uiprivTestHookReportProgrammerErrorFunc)(const char *prefix, const char *msg, const char *suffix, bool internal); -uiprivExtern void uiprivTestHookReportProgrammerError(uiprivTestHookReportProgrammerErrorFunc f); +typedef void (*uiprivTestHookReportProgrammerErrorFunc)(const char *msg, void *data); +uiprivExtern void uiprivTestHookReportProgrammerError(uiprivTestHookReportProgrammerErrorFunc f, void *data); #ifdef __cplusplus }