diff --git a/new/box.c b/new/box.c index 0f6f10c8..49e08404 100644 --- a/new/box.c +++ b/new/box.c @@ -38,7 +38,7 @@ static void boxDestroy(uiControl *c) uiControlSetHasParent(b->controls[i].c, 0); uiControlSetOSContainer(b->controls[i].c, NULL); uiControlDestroy(b->controls[i].c); - { + } uiFree(b->controls); uiFree(b); } @@ -64,7 +64,7 @@ static void boxSetOSContainer(uiControl *c, uiOSContainer *osContainer) oldcontainer = b->osContainer; b->osContainer = osContainer; for (i = 0; i < b->len; i++) - uiControlSetParent(b->controls[i].c, b->osContainer); + uiControlSetOSContainer(b->controls[i].c, b->osContainer); if (oldcontainer != NULL) uiOSContainerUpdate(oldcontainer); if (b->osContainer != NULL) @@ -325,7 +325,7 @@ static void boxAppend(uiBox *ss, uiControl *c, int stretchy) b->cap += boxCapGrow; b->controls = (boxControl *) uiRealloc(b->controls, b->cap * sizeof (boxControl), "boxControl[]"); } - uiControlSethasParent(c, 1); + uiControlSetHasParent(c, 1); b->controls[b->len].c = c; b->controls[b->len].stretchy = stretchy; b->len++; // must be here for OS container updates to work diff --git a/new/test/main.c b/new/test/main.c index 27e712e5..692d9866 100644 --- a/new/test/main.c +++ b/new/test/main.c @@ -1,6 +1,12 @@ // 22 april 2015 #include "test.h" +void die(const char *fmt, ...) +{ + // TODO + abort(); +} + int main(void) { printf("hello, world %p\n", uiMain); diff --git a/new/test/spaced.c b/new/test/spaced.c index 920d7bb5..0e9ed781 100644 --- a/new/test/spaced.c +++ b/new/test/spaced.c @@ -10,13 +10,13 @@ static struct thing *things = NULL; static uintmax_t len = 0; static uintmax_t cap = 0; -#define incr 32 +#define grow 32 static void *append(void *thing, int type) { if (len >= cap) { cap += grow; - things = (struct thing *) realloc(uiBoxes, cap * sizeof (struct thing)); + things = (struct thing *) realloc(things, cap * sizeof (struct thing)); if (things == NULL) die("reallocating things array in test/spaced.c append()"); } @@ -38,7 +38,7 @@ void setSpaced(int spaced) for (i = 0; i < len; i++) { p = things[i].ptr; - switch (things[i],type) { + switch (things[i].type) { case window: uiWindowSetMargined(uiWindow(p), spaced); break; diff --git a/new/test/test.h b/new/test/test.h index 7377679e..c65e1476 100644 --- a/new/test/test.h +++ b/new/test/test.h @@ -1,8 +1,13 @@ // 22 april 2015 +#include #include #include +#include #include "../ui.h" +// main.c +extern void die(const char *, ...); + // spaced.c extern void setSpaced(int); extern uiBox *newHorizontalBox(void); diff --git a/new/unix/GNUmakeinc.mk b/new/unix/GNUmakeinc.mk index 1371d0dd..ecbee66a 100644 --- a/new/unix/GNUmakeinc.mk +++ b/new/unix/GNUmakeinc.mk @@ -1,7 +1,9 @@ # 22 april 2015 osCFILES = \ - unix/main.c + unix/alloc.c \ + unix/main.c \ + unix/util.c osHFILES = \ unix/uipriv_unix.h diff --git a/new/unix/alloc.c b/new/unix/alloc.c new file mode 100644 index 00000000..33482b25 --- /dev/null +++ b/new/unix/alloc.c @@ -0,0 +1,33 @@ +// 7 april 2015 +#include +#include "uipriv_unix.h" + +void *uiAlloc(size_t size, const char *type) +{ + void *out; + + out = g_malloc0(size); + if (options.debugLogAllocations) + fprintf(stderr, "%p alloc %s\n", out, type); + return out; +} + +void *uiRealloc(void *p, size_t size, const char *type) +{ + void *out; + + if (p == NULL) + return uiAlloc(size, type); + // TODO fill with 0s + out = g_realloc(p, size); + if (options.debugLogAllocations) + fprintf(stderr, "%p realloc %p\n", p, out); + return out; +} + +void uiFree(void *p) +{ + g_free(p); + if (options.debugLogAllocations) + fprintf(stderr, "%p free\n", p); +} diff --git a/new/unix/util.c b/new/unix/util.c new file mode 100644 index 00000000..f02f4380 --- /dev/null +++ b/new/unix/util.c @@ -0,0 +1,13 @@ +// 18 april 2015 +#include "uipriv_unix.h" + +void complain(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + // there's no g_errorv() in glib 2.32, so do it manually instead + g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, fmt, ap); + va_end(ap); + abort(); // just in case +}