summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2015-04-07 19:04:09 -0400
committerPietro Gagliardi <[email protected]>2015-04-07 19:04:09 -0400
commit7b1dfbf1d6de954efdb5d9d9d4df61a98935ddd4 (patch)
tree98b82ee5987a646a409bb0efd510366cb5182ef0
parent03d94db0fd80f1d293dbf727b6e9a2466546c2c3 (diff)
Unified the allocators across all platforms so that everyone uses uiAlloc() and friends.
-rw-r--r--new/alloc_unix.c18
-rw-r--r--new/button_unix.c2
-rw-r--r--new/init_unix.c6
-rw-r--r--new/newcontrol_unix.c2
-rw-r--r--new/uipriv.h6
-rw-r--r--new/uipriv_darwin.h7
-rw-r--r--new/uipriv_windows.h7
-rw-r--r--new/window_unix.c4
8 files changed, 31 insertions, 21 deletions
diff --git a/new/alloc_unix.c b/new/alloc_unix.c
new file mode 100644
index 0000000..f956bb2
--- /dev/null
+++ b/new/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/new/button_unix.c b/new/button_unix.c
index 2d341cc..9c6fa2b 100644
--- a/new/button_unix.c
+++ b/new/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/new/init_unix.c b/new/init_unix.c
index 48d4366..67954c0 100644
--- a/new/init_unix.c
+++ b/new/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/new/newcontrol_unix.c b/new/newcontrol_unix.c
index 0523bd3..3123685 100644
--- a/new/newcontrol_unix.c
+++ b/new/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/new/uipriv.h b/new/uipriv.h
index 02aa72b..4b150dd 100644
--- a/new/uipriv.h
+++ b/new/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/new/uipriv_darwin.h b/new/uipriv_darwin.h
index 3c9c731..dd3467a 100644
--- a/new/uipriv_darwin.h
+++ b/new/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/new/uipriv_windows.h b/new/uipriv_windows.h
index f41528a..f12a6b6 100644
--- a/new/uipriv_windows.h
+++ b/new/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/new/window_unix.c b/new/window_unix.c
index ecc520c..acdede7 100644
--- a/new/window_unix.c
+++ b/new/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)