From a6c1e1ed170b0c7ca5039f030a4113ecfb829c50 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Mon, 27 May 2019 11:02:23 -0400 Subject: [PATCH] Fixed build errors. Now to fix runtime errors. --- common/alloc.c | 8 ++++---- common/errors.c | 4 ++++ common/events.c | 18 +++++++++--------- common/uipriv.h | 19 +++++++++++++------ test/lib/testingpriv.c | 14 +++++++++----- test/lib/testingpriv.h | 2 +- windows/winapi.hpp | 2 ++ 7 files changed, 42 insertions(+), 25 deletions(-) diff --git a/common/alloc.c b/common/alloc.c index 94b18515..5fca95f5 100644 --- a/common/alloc.c +++ b/common/alloc.c @@ -15,13 +15,13 @@ void *uiprivAlloc(size_t n, const char *what) return p; } -void *uiprivRealloc(void *p, size_t old, size_t new, const char *what) +void *uiprivRealloc(void *p, size_t nOld, size_t nNew, const char *what) { - p = realloc(p, new); + p = realloc(p, nNew); if (p == NULL) uiprivInternalError("memory exhausted reallocating %s", what); - if (new > old) - memset(((uint8_t *) p) + old, 0, new - old); + if (nNew > nOld) + memset(((uint8_t *) p) + nOld, 0, nNew - nOld); return p; } diff --git a/common/errors.c b/common/errors.c index a4d398d8..91bdcfd8 100644 --- a/common/errors.c +++ b/common/errors.c @@ -1,4 +1,8 @@ // 12 may 2019 +// TODO get rid of the need for this (it temporarily silences noise so I can find actual build issues) +#ifdef _MSC_VER +#define _CRT_SECURE_NO_WARNINGS +#endif #include #include #include "ui.h" diff --git a/common/events.c b/common/events.c index 77dcde9c..d8d1c948 100644 --- a/common/events.c +++ b/common/events.c @@ -37,7 +37,7 @@ uiEvent *uiNewEvent(const uiEventOptions *options) uiEvent *e; if (options == NULL) { - uiprivProgrammerError(uiprivProgrammerErrorNullPointer, "uiEventOptions", __func__); + uiprivProgrammerError(uiprivProgrammerErrorNullPointer, "uiEventOptions", uiprivFunc); return NULL; } if (options->Size != sizeof (uiEventOptions)) { @@ -52,11 +52,11 @@ uiEvent *uiNewEvent(const uiEventOptions *options) } #define checkEventNonnull(e, ret) if ((e) == NULL) { \ - uiprivProgrammerError(uiprivProgrammerErrorNullPointer, "uiEvent", __func__); \ + uiprivProgrammerError(uiprivProgrammerErrorNullPointer, "uiEvent", uiprivFunc); \ return ret; \ } #define checkEventNotFiring(e, ret) if ((e)->firing) { \ - uiprivProgrammerError(uiprivProgrammerErrorChangingEventDuringFire, __func__); \ + uiprivProgrammerError(uiprivProgrammerErrorChangingEventDuringFire, uiprivFunc); \ return ret; \ } @@ -81,10 +81,10 @@ int uiEventAddHandler(uiEvent *e, uiEventHandler handler, void *sender, void *da checkEventNonnull(e, 0); checkEventNotFiring(e, 0); if (handler == NULL) { - uiprivProgrammerError(uiprivProgrammerErrorNullPointer, "uiEventHandler", __func__); + uiprivProgrammerError(uiprivProgrammerErrorNullPointer, "uiEventHandler", uiprivFunc); return 0; } - if (!checkEventSender(e, sender, __func__)) + if (!checkEventSender(e, sender, uiprivFunc)) return 0; id = 0; @@ -125,7 +125,7 @@ void uiEventDeleteHandler(uiEvent *e, int id) checkEventNonnull(e, /* nothing */); checkEventNotFiring(e, /* nothing */); - h = findHandler(e, id, __func__); + h = findHandler(e, id, uiprivFunc); if (h == NULL) return; @@ -143,7 +143,7 @@ void uiEventFire(uiEvent *e, void *sender, void *args) uiprivProgrammerError(uiprivProgrammerErrorRecursiveEventFire); return; } - if (!checkEventSender(e, sender, __func__)) + if (!checkEventSender(e, sender, uiprivFunc)) return; e->firing = true; @@ -161,7 +161,7 @@ bool uiEventHandlerBlocked(const uiEvent *e, int id) struct handler *h; checkEventNonnull(e, false); - h = findHandler(e, id, __func__); + h = findHandler(e, id, uiprivFunc); if (h == NULL) return false; return h->blocked; @@ -173,7 +173,7 @@ void uiEventSetHandlerBlocked(uiEvent *e, int id, bool blocked) checkEventNonnull(e, /* nothing */); checkEventNotFiring(e, /* nothing */); - h = findHandler(e, id, __func__); + h = findHandler(e, id, uiprivFunc); if (h == NULL) return; h->blocked = blocked; diff --git a/common/uipriv.h b/common/uipriv.h index 66f1143b..eb5ca28e 100644 --- a/common/uipriv.h +++ b/common/uipriv.h @@ -4,6 +4,13 @@ extern "C" { #endif +// TODO figure out why this is needed despite what https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2013/b0084kay(v=vs.120) says +#ifdef _MSC_VER +#define uiprivFunc __FUNCTION__ +#else +#define uiprivFunc __func__ +#endif + // init.c extern const char **uiprivSysInitErrors(void); extern int uiprivSysInit(void *options, uiInitError *err); @@ -12,7 +19,7 @@ extern int uiprivInitReturnErrorf(uiInitError *err, const char *msg, ...); // alloc.c extern void *uiprivAlloc(size_t n, const char *what); -extern void *uiprivRealloc(void *p, size_t old, size_t new, const char *what); +extern void *uiprivRealloc(void *p, size_t nOld, size_t nNew, const char *what); extern void uiprivFree(void *p); typedef struct uiprivArray uiprivArray; struct uiprivArray { @@ -44,12 +51,12 @@ extern void uiprivArrayQsort(uiprivArray *arr, int (*compare)(const void *, cons extern void uiprivInternalError(const char *fmt, ...); enum { uiprivProgrammerErrorWrongStructSize, // arguments: size_t badSize, const char *structName - uiprivProgrammerErrorIndexOutOfRange, // arguments: int badIndex, __func__ - uiprivProgrammerErrorNullPointer, // arguments: const char *paramDesc, __func__ - uiprivProgrammerErrorIntIDNotFound, // arguments: const char *idDesc, int badID, __func__ + uiprivProgrammerErrorIndexOutOfRange, // arguments: int badIndex, uiprivFunc + uiprivProgrammerErrorNullPointer, // arguments: const char *paramDesc, uiprivFunc + uiprivProgrammerErrorIntIDNotFound, // arguments: const char *idDesc, int badID, uiprivFunc // TODO type mismatch - uiprivProgrammerErrorBadSenderForEvent, // arguments: const char *senderDesc, const char *eventDesc, __func__ - uiprivProgrammerErrorChangingEventDuringFire, // arguments: __func__ + uiprivProgrammerErrorBadSenderForEvent, // arguments: const char *senderDesc, const char *eventDesc, uiprivFunc + uiprivProgrammerErrorChangingEventDuringFire, // arguments: uiprivFunc uiprivProgrammerErrorRecursiveEventFire, // no arguments uiprivNumProgrammerErrors, }; diff --git a/test/lib/testingpriv.c b/test/lib/testingpriv.c index 481397ce..2bf7c7e6 100644 --- a/test/lib/testingpriv.c +++ b/test/lib/testingpriv.c @@ -1,4 +1,8 @@ // 19 may 2019 +// TODO get rid of the need for this (it temporarily silences noise so I can find actual build issues) +#ifdef _MSC_VER +#define _CRT_SECURE_NO_WARNINGS +#endif #include #include #include @@ -28,13 +32,13 @@ void *testingprivAlloc(size_t n, const char *what) return p; } -void *testingprivRealloc(void *p, size_t old, size_t new, const char *what) +void *testingprivRealloc(void *p, size_t nOld, size_t nNew, const char *what) { - p = realloc(p, new); + p = realloc(p, nNew); if (p == NULL) testingprivInternalError("memory exhausted reallocating %s", what); - if (new > old) - memset(((uint8_t *) p) + old, 0, new - old); + if (nNew > nOld) + memset(((uint8_t *) p) + nOld, 0, nNew - nOld); return p; } @@ -223,7 +227,7 @@ void testingprivOutbufAppendOutbuf(testingprivOutbuf *o, testingprivOutbuf *src) char *buf; size_t n; int hasTrailingBlankLine; - size_t trailingBlankLinePos; + size_t trailingBlankLinePos = 0; // silence incorrect MSVC warning char *lineStart, *lineEnd; buf = src->buf.buf; diff --git a/test/lib/testingpriv.h b/test/lib/testingpriv.h index 82f13501..c7a48143 100644 --- a/test/lib/testingpriv.h +++ b/test/lib/testingpriv.h @@ -5,7 +5,7 @@ extern void testingprivInternalError(const char *fmt, ...); extern void *testingprivAlloc(size_t n, const char *what); #define testingprivNew(T) ((T *) testingprivAlloc(sizeof (T), #T)) #define testingprivNewArray(T, n) ((T *) testingprivAlloc(n * sizeof (T), #T "[]")) -extern void *testingprivRealloc(void *p, size_t old, size_t new, const char *what); +extern void *testingprivRealloc(void *p, size_t nOld, size_t nNew, const char *what); #define testingprivResizeArray(x, T, old, new) ((T *) testingprivRealloc(x, old * sizeof (T), new * sizeof (T), #T "[]")) extern void testingprivFree(void *p); diff --git a/windows/winapi.hpp b/windows/winapi.hpp index ab6cdd19..b6bf5636 100644 --- a/windows/winapi.hpp +++ b/windows/winapi.hpp @@ -31,4 +31,6 @@ // Microsoft's resource compiler will segfault if we feed it headers it was not designed to handle #ifndef RC_INVOKED #include + +#include #endif