From 9d2b637aa2710e2ed5c2219f66d2506e69fad1b6 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 5 May 2016 21:51:14 -0400 Subject: [PATCH] FINALLY got rid of ptrArray. Woo! --- common/GNUfiles.mk | 1 - common/ptrarray.c | 49 ---------------------------------------------- common/uipriv.h | 13 ------------ 3 files changed, 63 deletions(-) delete mode 100644 common/ptrarray.c diff --git a/common/GNUfiles.mk b/common/GNUfiles.mk index da66fb97..14416f4e 100644 --- a/common/GNUfiles.mk +++ b/common/GNUfiles.mk @@ -4,7 +4,6 @@ CFILES += \ common/areaevents.c \ common/control.c \ common/matrix.c \ - common/ptrarray.c \ common/shouldquit.c HFILES += \ diff --git a/common/ptrarray.c b/common/ptrarray.c deleted file mode 100644 index ac6dd165..00000000 --- a/common/ptrarray.c +++ /dev/null @@ -1,49 +0,0 @@ -// 5 may 2015 -#include -#include "../ui.h" -#include "uipriv.h" - -struct ptrArray *newPtrArray(void) -{ - return uiNew(struct ptrArray); -} - -void ptrArrayDestroy(struct ptrArray *p) -{ - if (p->len != 0) - complain("attempt to destroy ptrarray %p while it still has pointers inside", p); - if (p->ptrs != NULL) // array was created but nothing was ever put inside - uiFree(p->ptrs); - uiFree(p); -} - -#define grow 32 - -void ptrArrayAppend(struct ptrArray *p, void *d) -{ - ptrArrayInsertAt(p, p->len, d); -} - -void ptrArrayInsertAt(struct ptrArray *p, uintmax_t i, void *d) -{ - if (i > p->len) - complain("index out of range in ptrArrayInsertAt()"); - if (p->len >= p->cap) { - p->cap += grow; - p->ptrs = (void **) uiRealloc(p->ptrs, p->cap * sizeof (void *), "void *[]"); - } - // thanks to ValleyBell - memmove(&(p->ptrs[i + 1]), &(p->ptrs[i]), (p->len - i) * sizeof (void *)); - p->ptrs[i] = d; - p->len++; -} - -void ptrArrayDelete(struct ptrArray *p, uintmax_t i) -{ - if (i >= p->len) - complain("index out of range in ptrArrayRemove()"); - // thanks to ValleyBell - memmove(&(p->ptrs[i]), &(p->ptrs[i + 1]), (p->len - i - 1) * sizeof (void *)); - p->ptrs[p->len - 1] = NULL; - p->len--; -} diff --git a/common/uipriv.h b/common/uipriv.h index bb6e8b38..c8b6b6f0 100644 --- a/common/uipriv.h +++ b/common/uipriv.h @@ -19,19 +19,6 @@ extern void complain(const char *, ...); // control.c extern uiControl *newControl(size_t size, uint32_t OSsig, uint32_t typesig, const char *typenamestr); -// ptrarray.c -struct ptrArray { - void **ptrs; - uintmax_t len; - uintmax_t cap; -}; -struct ptrArray *newPtrArray(void); -void ptrArrayDestroy(struct ptrArray *); -void ptrArrayAppend(struct ptrArray *, void *); -void ptrArrayInsertAt(struct ptrArray *, uintmax_t, void *); -void ptrArrayDelete(struct ptrArray *, uintmax_t); -#define ptrArrayIndex(p, T, i) ((T) ((p)->ptrs[(i)])) - // shouldquit.c extern int shouldQuit(void);