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) {
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;

View File

@ -2,7 +2,7 @@
#import <stdio.h>
#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);

View File

@ -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 *, ...);

View File

@ -2,7 +2,7 @@
#include <stdio.h>
#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;

View File

@ -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;

View File

@ -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);

View File

@ -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++;

View File

@ -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);

View File

@ -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()");

View File

@ -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()");