diff --git a/alloc_unix.c b/alloc_unix.c new file mode 100644 index 00000000..f956bb2e --- /dev/null +++ b/alloc_unix.c @@ -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); +} diff --git a/button_unix.c b/button_unix.c index 2d341cc3..9c6fa2b9 100644 --- a/button_unix.c +++ b/button_unix.c @@ -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); diff --git a/init_unix.c b/init_unix.c index 48d4366a..67954c0c 100644 --- a/init_unix.c +++ b/init_unix.c @@ -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); } diff --git a/newcontrol_unix.c b/newcontrol_unix.c index 0523bd3b..3123685c 100644 --- a/newcontrol_unix.c +++ b/newcontrol_unix.c @@ -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; diff --git a/uipriv.h b/uipriv.h index 02aa72b3..4b150ddf 100644 --- a/uipriv.h +++ b/uipriv.h @@ -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 *); diff --git a/uipriv_darwin.h b/uipriv_darwin.h index 3c9c7316..dd3467ad 100644 --- a/uipriv_darwin.h +++ b/uipriv_darwin.h @@ -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 *); diff --git a/uipriv_windows.h b/uipriv_windows.h index f41528a8..f12a6b67 100644 --- a/uipriv_windows.h +++ b/uipriv_windows.h @@ -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); diff --git a/window_unix.c b/window_unix.c index ecc520c6..acdede75 100644 --- a/window_unix.c +++ b/window_unix.c @@ -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)