diff --git a/box.c b/box.c index 53669d3b..56403991 100644 --- a/box.c +++ b/box.c @@ -196,7 +196,7 @@ static void boxAppend(uiBox *ss, uiControl *c, int stretchy) if (b->len >= b->cap) { b->cap += boxCapGrow; - b->controls = (boxControl *) uiRealloc(b->controls, b->cap * sizeof (boxControl), "boxControl[]"); + b->controls = (boxControl *) uiRealloc(b->controls, b->cap * sizeof (boxControl)); } b->controls[b->len].c = c; b->controls[b->len].stretchy = stretchy; diff --git a/darwin/alloc.m b/darwin/alloc.m index c445aaee..33bdfea0 100644 --- a/darwin/alloc.m +++ b/darwin/alloc.m @@ -2,7 +2,7 @@ #import #import "uipriv_darwin.h" -void *uiAlloc(size_t size, const char *type) +void *uiAlloc(size_t size) { void *out; @@ -15,12 +15,12 @@ void *uiAlloc(size_t size, const char *type) return out; } -void *uiRealloc(void *p, size_t size, const char *type) +void *uiRealloc(void *p, size_t size) { void *out; if (p == NULL) - return uiAlloc(size, type); + return uiAlloc(size); out = realloc(p, size); if (out == NULL) { fprintf(stderr, "memory exhausted in uiRealloc() reallocating %s\n", type); diff --git a/uipriv.h b/uipriv.h index 759bd629..7d70d381 100644 --- a/uipriv.h +++ b/uipriv.h @@ -3,10 +3,9 @@ extern uiInitOptions options; -// TODO remove the type name arguments -extern void *uiAlloc(size_t, const char *); -#define uiNew(T) ((T *) uiAlloc(sizeof (T), #T )) -extern void *uiRealloc(void *, size_t, const char *); +extern void *uiAlloc(size_t); +#define uiNew(T) ((T *) uiAlloc(sizeof (T))) +extern void *uiRealloc(void *, size_t); extern void uiFree(void *); extern void complain(const char *, ...); diff --git a/unix/alloc.c b/unix/alloc.c index 2021feb4..afde1741 100644 --- a/unix/alloc.c +++ b/unix/alloc.c @@ -2,7 +2,7 @@ #include #include "uipriv_unix.h" -void *uiAlloc(size_t size, const char *type) +void *uiAlloc(size_t size) { void *out; @@ -10,12 +10,12 @@ void *uiAlloc(size_t size, const char *type) return out; } -void *uiRealloc(void *p, size_t size, const char *type) +void *uiRealloc(void *p, size_t size) { void *out; if (p == NULL) - return uiAlloc(size, type); + return uiAlloc(size); // TODO fill with 0s out = g_realloc(p, size); return out; diff --git a/windows/alloc.c b/windows/alloc.c index c5225fbe..961ff5a0 100644 --- a/windows/alloc.c +++ b/windows/alloc.c @@ -15,27 +15,27 @@ int initAlloc(void) return heap != NULL; } -void *uiAlloc(size_t size, const char *type) +void *uiAlloc(size_t size) { void *out; out = HeapAlloc(heap, HEAP_ZERO_MEMORY, size); if (out == NULL) { - fprintf(stderr, "memory exhausted in uiAlloc() allocating %s\n", type); + fprintf(stderr, "memory exhausted in uiAlloc()\n"); abort(); } return out; } -void *uiRealloc(void *p, size_t size, const char *type) +void *uiRealloc(void *p, size_t size) { void *out; if (p == NULL) - return uiAlloc(size, type); + return uiAlloc(size); out = HeapReAlloc(heap, HEAP_ZERO_MEMORY, p, size); if (out == NULL) { - fprintf(stderr, "memory exhausted in uiRealloc() reallocating %s\n", type); + fprintf(stderr, "memory exhausted in uiRealloc()\n"); abort(); } return out; diff --git a/windows/init.c b/windows/init.c index f29e39a9..1905cc54 100644 --- a/windows/init.c +++ b/windows/init.c @@ -41,7 +41,7 @@ static const char *loadLastError(const char *message) } wmessage = toUTF16(message); n = _scwprintf(initErrorFormat, initErrorArgs); - wstr = (WCHAR *) uiAlloc((n + 1) * sizeof (WCHAR), "WCHAR[]"); + wstr = (WCHAR *) uiAlloc((n + 1) * sizeof (WCHAR)); snwprintf(wstr, n + 1, initErrorFormat, initErrorArgs); str = toUTF8(wstr); uiFree(wstr); diff --git a/windows/menu.c b/windows/menu.c index 5906fbb0..9c467941 100644 --- a/windows/menu.c +++ b/windows/menu.c @@ -118,7 +118,7 @@ static uiMenuItem *newItem(struct menu *m, int type, const char *name) if (m->len >= m->cap) { m->cap += grow; - m->items = (struct menuItem **) uiRealloc(m->items, m->cap * sizeof (struct menuItem *), "struct menuItem *[]"); + m->items = (struct menuItem **) uiRealloc(m->items, m->cap * sizeof (struct menuItem *)); } item = uiNew(struct menuItem); @@ -209,7 +209,7 @@ uiMenu *uiNewMenu(const char *name) complain("attempt to create a new menu after menus have been finalized"); if (len >= cap) { cap += grow; - menus = (struct menu **) uiRealloc(menus, cap * sizeof (struct menu *), "struct menu *[]"); + menus = (struct menu **) uiRealloc(menus, cap * sizeof (struct menu *)); } m = uiNew(struct menu); @@ -245,7 +245,7 @@ static void appendMenuItem(HMENU menu, struct menuItem *item) if (item->len >= item->cap) { item->cap += grow; - item->hmenus = (HMENU *) uiRealloc(item->hmenus, item->cap * sizeof (HMENU), "HMENU[]"); + item->hmenus = (HMENU *) uiRealloc(item->hmenus, item->cap * sizeof (HMENU)); } item->hmenus[item->len] = menu; item->len++; diff --git a/windows/tab.c b/windows/tab.c index f484938c..e5e011ed 100644 --- a/windows/tab.c +++ b/windows/tab.c @@ -156,8 +156,8 @@ static void tabAppendPage(uiTab *tt, const char *name, uiControl *child) if (t->len >= t->cap) { t->cap += tabCapGrow; - t->pages = (uiContainer **) uiRealloc(t->pages, t->cap * sizeof (uiContainer *), "uiContainer *[]"); - t->margined = (int *) uiRealloc(t->margined, t->cap * sizeof (int), "int[]"); + t->pages = (uiContainer **) uiRealloc(t->pages, t->cap * sizeof (uiContainer *)); + t->margined = (int *) uiRealloc(t->margined, t->cap * sizeof (int)); } n = SendMessageW(t->hwnd, TCM_GETITEMCOUNT, 0, 0); diff --git a/windows/text.c b/windows/text.c index 8d6d0b0a..d31f7a38 100644 --- a/windows/text.c +++ b/windows/text.c @@ -13,7 +13,7 @@ WCHAR *toUTF16(const char *str) n = MBTWC(str, NULL, 0); if (n == 0) logLastError("error figuring out number of characters to convert to in toUTF16()"); - wstr = (WCHAR *) uiAlloc(n * sizeof (WCHAR), "WCHAR[]"); + wstr = (WCHAR *) uiAlloc(n * sizeof (WCHAR)); if (MBTWC(str, wstr, n) != n) logLastError("error converting from UTF-8 to UTF-16 in toUTF16()"); return wstr; @@ -29,7 +29,7 @@ char *toUTF8(const WCHAR *wstr) n = WCTMB(wstr, NULL, 0); if (n == 0) logLastError("error figuring out number of characters to convert to in toUTF8()"); - str = (char *) uiAlloc(n * sizeof (char), "char[]"); + str = (char *) uiAlloc(n * sizeof (char)); if (WCTMB(wstr, str, n) != n) logLastError("error converting from UTF-16 to UTF-8 in toUTFF8()"); return str; @@ -42,7 +42,7 @@ WCHAR *windowText(HWND hwnd) n = SendMessageW(hwnd, WM_GETTEXTLENGTH, 0, 0); // WM_GETTEXTLENGTH does not include the null terminator - text = (WCHAR *) uiAlloc((n + 1) * sizeof (WCHAR), "WCHAR[]"); + text = (WCHAR *) uiAlloc((n + 1) * sizeof (WCHAR)); // note the comparison: the size includes the null terminator, but the return does not if (GetWindowTextW(hwnd, text, n + 1) != n) logLastError("error getting window text in windowText()"); diff --git a/windows/util.c b/windows/util.c index 63529e59..776a154a 100644 --- a/windows/util.c +++ b/windows/util.c @@ -16,7 +16,7 @@ intmax_t uiWindowsWindowTextWidth(HWND hwnd) len = SendMessageW(hwnd, WM_GETTEXTLENGTH, 0, 0); if (len == 0) // no text; nothing to do return 0; - text = (WCHAR *) uiAlloc((len + 1) * sizeof (WCHAR), "WCHAR[]"); + text = (WCHAR *) uiAlloc((len + 1) * sizeof (WCHAR)); // note the comparison: the size includes the null terminator, but the return does not if (GetWindowText(hwnd, text, len + 1) != len) logLastError("error getting window text in uiWindowsWindowTextWidth()");