Removed the typename argument from uiAlloc() and uiRealloc().

This commit is contained in:
Pietro Gagliardi 2015-05-03 19:52:24 -04:00
parent 325f16cfb3
commit fd4c559e86
10 changed files with 25 additions and 26 deletions

2
box.c
View File

@ -196,7 +196,7 @@ static void boxAppend(uiBox *ss, uiControl *c, int stretchy)
if (b->len >= b->cap) { if (b->len >= b->cap) {
b->cap += boxCapGrow; 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].c = c;
b->controls[b->len].stretchy = stretchy; b->controls[b->len].stretchy = stretchy;

View File

@ -2,7 +2,7 @@
#import <stdio.h> #import <stdio.h>
#import "uipriv_darwin.h" #import "uipriv_darwin.h"
void *uiAlloc(size_t size, const char *type) void *uiAlloc(size_t size)
{ {
void *out; void *out;
@ -15,12 +15,12 @@ void *uiAlloc(size_t size, const char *type)
return out; return out;
} }
void *uiRealloc(void *p, size_t size, const char *type) void *uiRealloc(void *p, size_t size)
{ {
void *out; void *out;
if (p == NULL) if (p == NULL)
return uiAlloc(size, type); return uiAlloc(size);
out = realloc(p, size); out = realloc(p, size);
if (out == NULL) { if (out == NULL) {
fprintf(stderr, "memory exhausted in uiRealloc() reallocating %s\n", type); fprintf(stderr, "memory exhausted in uiRealloc() reallocating %s\n", type);

View File

@ -3,10 +3,9 @@
extern uiInitOptions options; extern uiInitOptions options;
// TODO remove the type name arguments extern void *uiAlloc(size_t);
extern void *uiAlloc(size_t, const char *); #define uiNew(T) ((T *) uiAlloc(sizeof (T)))
#define uiNew(T) ((T *) uiAlloc(sizeof (T), #T )) extern void *uiRealloc(void *, size_t);
extern void *uiRealloc(void *, size_t, const char *);
extern void uiFree(void *); extern void uiFree(void *);
extern void complain(const char *, ...); extern void complain(const char *, ...);

View File

@ -2,7 +2,7 @@
#include <stdio.h> #include <stdio.h>
#include "uipriv_unix.h" #include "uipriv_unix.h"
void *uiAlloc(size_t size, const char *type) void *uiAlloc(size_t size)
{ {
void *out; void *out;
@ -10,12 +10,12 @@ void *uiAlloc(size_t size, const char *type)
return out; return out;
} }
void *uiRealloc(void *p, size_t size, const char *type) void *uiRealloc(void *p, size_t size)
{ {
void *out; void *out;
if (p == NULL) if (p == NULL)
return uiAlloc(size, type); return uiAlloc(size);
// TODO fill with 0s // TODO fill with 0s
out = g_realloc(p, size); out = g_realloc(p, size);
return out; return out;

View File

@ -15,27 +15,27 @@ int initAlloc(void)
return heap != NULL; return heap != NULL;
} }
void *uiAlloc(size_t size, const char *type) void *uiAlloc(size_t size)
{ {
void *out; void *out;
out = HeapAlloc(heap, HEAP_ZERO_MEMORY, size); out = HeapAlloc(heap, HEAP_ZERO_MEMORY, size);
if (out == NULL) { if (out == NULL) {
fprintf(stderr, "memory exhausted in uiAlloc() allocating %s\n", type); fprintf(stderr, "memory exhausted in uiAlloc()\n");
abort(); abort();
} }
return out; return out;
} }
void *uiRealloc(void *p, size_t size, const char *type) void *uiRealloc(void *p, size_t size)
{ {
void *out; void *out;
if (p == NULL) if (p == NULL)
return uiAlloc(size, type); return uiAlloc(size);
out = HeapReAlloc(heap, HEAP_ZERO_MEMORY, p, size); out = HeapReAlloc(heap, HEAP_ZERO_MEMORY, p, size);
if (out == NULL) { if (out == NULL) {
fprintf(stderr, "memory exhausted in uiRealloc() reallocating %s\n", type); fprintf(stderr, "memory exhausted in uiRealloc()\n");
abort(); abort();
} }
return out; return out;

View File

@ -41,7 +41,7 @@ static const char *loadLastError(const char *message)
} }
wmessage = toUTF16(message); wmessage = toUTF16(message);
n = _scwprintf(initErrorFormat, initErrorArgs); 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); snwprintf(wstr, n + 1, initErrorFormat, initErrorArgs);
str = toUTF8(wstr); str = toUTF8(wstr);
uiFree(wstr); uiFree(wstr);

View File

@ -118,7 +118,7 @@ static uiMenuItem *newItem(struct menu *m, int type, const char *name)
if (m->len >= m->cap) { if (m->len >= m->cap) {
m->cap += grow; 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); 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"); complain("attempt to create a new menu after menus have been finalized");
if (len >= cap) { if (len >= cap) {
cap += grow; 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); m = uiNew(struct menu);
@ -245,7 +245,7 @@ static void appendMenuItem(HMENU menu, struct menuItem *item)
if (item->len >= item->cap) { if (item->len >= item->cap) {
item->cap += grow; 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->hmenus[item->len] = menu;
item->len++; item->len++;

View File

@ -156,8 +156,8 @@ static void tabAppendPage(uiTab *tt, const char *name, uiControl *child)
if (t->len >= t->cap) { if (t->len >= t->cap) {
t->cap += tabCapGrow; t->cap += tabCapGrow;
t->pages = (uiContainer **) uiRealloc(t->pages, t->cap * sizeof (uiContainer *), "uiContainer *[]"); t->pages = (uiContainer **) uiRealloc(t->pages, t->cap * sizeof (uiContainer *));
t->margined = (int *) uiRealloc(t->margined, t->cap * sizeof (int), "int[]"); t->margined = (int *) uiRealloc(t->margined, t->cap * sizeof (int));
} }
n = SendMessageW(t->hwnd, TCM_GETITEMCOUNT, 0, 0); n = SendMessageW(t->hwnd, TCM_GETITEMCOUNT, 0, 0);

View File

@ -13,7 +13,7 @@ WCHAR *toUTF16(const char *str)
n = MBTWC(str, NULL, 0); n = MBTWC(str, NULL, 0);
if (n == 0) if (n == 0)
logLastError("error figuring out number of characters to convert to in toUTF16()"); 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) if (MBTWC(str, wstr, n) != n)
logLastError("error converting from UTF-8 to UTF-16 in toUTF16()"); logLastError("error converting from UTF-8 to UTF-16 in toUTF16()");
return wstr; return wstr;
@ -29,7 +29,7 @@ char *toUTF8(const WCHAR *wstr)
n = WCTMB(wstr, NULL, 0); n = WCTMB(wstr, NULL, 0);
if (n == 0) if (n == 0)
logLastError("error figuring out number of characters to convert to in toUTF8()"); 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) if (WCTMB(wstr, str, n) != n)
logLastError("error converting from UTF-16 to UTF-8 in toUTFF8()"); logLastError("error converting from UTF-16 to UTF-8 in toUTFF8()");
return str; return str;
@ -42,7 +42,7 @@ WCHAR *windowText(HWND hwnd)
n = SendMessageW(hwnd, WM_GETTEXTLENGTH, 0, 0); n = SendMessageW(hwnd, WM_GETTEXTLENGTH, 0, 0);
// WM_GETTEXTLENGTH does not include the null terminator // 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 // note the comparison: the size includes the null terminator, but the return does not
if (GetWindowTextW(hwnd, text, n + 1) != n) if (GetWindowTextW(hwnd, text, n + 1) != n)
logLastError("error getting window text in windowText()"); logLastError("error getting window text in windowText()");

View File

@ -16,7 +16,7 @@ intmax_t uiWindowsWindowTextWidth(HWND hwnd)
len = SendMessageW(hwnd, WM_GETTEXTLENGTH, 0, 0); len = SendMessageW(hwnd, WM_GETTEXTLENGTH, 0, 0);
if (len == 0) // no text; nothing to do if (len == 0) // no text; nothing to do
return 0; 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 // note the comparison: the size includes the null terminator, but the return does not
if (GetWindowText(hwnd, text, len + 1) != len) if (GetWindowText(hwnd, text, len + 1) != len)
logLastError("error getting window text in uiWindowsWindowTextWidth()"); logLastError("error getting window text in uiWindowsWindowTextWidth()");