Unified the allocators across all platforms so that everyone uses uiAlloc() and friends.

This commit is contained in:
Pietro Gagliardi 2015-04-07 19:04:09 -04:00
parent 03d94db0fd
commit 7b1dfbf1d6
8 changed files with 31 additions and 21 deletions

18
new/alloc_unix.c Normal file
View File

@ -0,0 +1,18 @@
// 7 april 2015
#include "uipriv_unix.h"
void *uiAlloc(size_t size)
{
return g_malloc0(size);
}
void *uiRealloc(void *p, size_t size)
{
// TODO fill with 0s
return g_realloc(p, size);
}
void uiFree(void *p)
{
g_free(p);
}

View File

@ -26,7 +26,7 @@ uiControl *uiNewButton(const char *text)
GParameter props[1];
GtkWidget *widget;
b = g_new0(struct button, 1);
b = uiNew(struct button);
props[0].name = "label";
g_value_init(&(props[0].value), G_TYPE_STRING);

View File

@ -9,10 +9,10 @@ uiInitError *uiInit(uiInitOptions *o)
{
uiInitError *err;
err = g_new0(uiInitError, 1);
err = uiNew(uiInitError);
if (gtk_init_with_args(NULL, NULL, NULL, NULL, NULL, &(err->err)) == FALSE)
return err;
g_free(err);
uiFree(err);
return NULL;
}
@ -24,5 +24,5 @@ const char *uiInitErrorMessage(uiInitError *err)
void uiInitErrorFree(uiInitError *err)
{
g_error_free(err->err);
g_free(err);
uiFree(err);
}

View File

@ -64,7 +64,7 @@ uiControl *uiUnixNewControl(GType type, guint nConstructParams, GParameter *cons
{
uiSingleWidgetControl *c;
c = g_new0(uiSingleWidgetControl, 1);
c = uiNew(uiSingleWidgetControl);
c->widget = GTK_WIDGET(g_object_newv(type, nConstructParams, constructParams));
c->immediate = c->widget;

View File

@ -18,3 +18,9 @@ struct uiControl {
void (*containerShow)(uiControl *);
void (*containerHide)(uiControl *);
};
extern void *uiAlloc(size_t);
// TODO use this in existing files
#define uiNew(T) ((T *) uiAlloc(sizeof (T)))
extern void *uiRealloc(void *, size_t);
extern void uiFree(void *);

View File

@ -11,13 +11,6 @@
struct uiSizing {
};
// alloc_darwin.m
extern void *uiAlloc(size_t);
// TODO use this in existing files
#define uiNew(T) ((T *) uiAlloc(sizeof (T)))
extern void *uiRealloc(void *, size_t);
extern void uiFree(void *);
// util_darwin.m
extern void setStandardControlFont(NSControl *);

View File

@ -42,13 +42,6 @@ struct uiSizing {
LONG internalLeading;
};
// alloc_windows.c
extern void *uiAlloc(size_t);
// TODO use this in existing files
#define uiNew(T) ((T *) uiAlloc(sizeof (T)))
extern void *uiRealloc(void *, size_t);
extern void uiFree(void *);
// debug_windows.c
extern HRESULT logLastError(const char *);
extern HRESULT logHRESULT(const char *, HRESULT);

View File

@ -12,7 +12,7 @@ uiWindow *uiNewWindow(char *title, int width, int height)
{
uiWindow *w;
w = g_new0(uiWindow, 1);
w = uiNew(uiWindow);
w->widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(w->widget), title);
gtk_window_resize(GTK_WINDOW(w->widget), width, height);
@ -24,7 +24,7 @@ uiWindow *uiNewWindow(char *title, int width, int height)
void uiWindowDestroy(uiWindow *w)
{
gtk_widget_destroy(w->widget);
g_free(w);
uiFree(w);
}
uintptr_t uiWindowHandle(uiWindow *w)