Started working on a pointer array implementation. This also means we'll need the C standard library for memcpy()/memmove(), so drop the DisableThreadLibraryCalls() TODO.
This commit is contained in:
parent
657cbe2013
commit
bc2e6d134b
|
@ -0,0 +1,58 @@
|
||||||
|
// 5 may 2015
|
||||||
|
#include <string.h>
|
||||||
|
#include "ui.h"
|
||||||
|
#include "uipriv.h"
|
||||||
|
|
||||||
|
// TODO see if we can use memmove()
|
||||||
|
|
||||||
|
struct ptrArray newPtrArray(void)
|
||||||
|
{
|
||||||
|
return uiNew(struct ptrArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ptrArrayDestroy(struct ptrArray *p)
|
||||||
|
{
|
||||||
|
// TODO check iif len is nonzero
|
||||||
|
uiFree(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define grow 32
|
||||||
|
|
||||||
|
void ptrArrayAppend(struct ptrArray *p, void *d)
|
||||||
|
{
|
||||||
|
p->len++;
|
||||||
|
if (p->len >= p->cap) {
|
||||||
|
p->cap += grow;
|
||||||
|
p->ptrs = (void **) uiRealloc(p->ptrs, p->cap * sizeof (void *));
|
||||||
|
}
|
||||||
|
p->ptrs[p->len - 1] = d;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ptrArrayInsertBefore(struct ptrArray *p, uintmax_t i, void *d)
|
||||||
|
{
|
||||||
|
uintmax_t j;
|
||||||
|
|
||||||
|
if (i >= p->len)
|
||||||
|
complain("index out of range in ptrArrayInsertBefore()");
|
||||||
|
// TODO does this need to be here
|
||||||
|
p->len++;
|
||||||
|
if (p->len >= p->cap) {
|
||||||
|
p->cap += grow;
|
||||||
|
p->ptrs = (void **) uiRealloc(p->ptrs, p->cap * sizeof (void *));
|
||||||
|
}
|
||||||
|
for (j = p->len - 1; j >= i; j--)
|
||||||
|
p->ptrs[j + 1] = p->ptrs[j];
|
||||||
|
p->ptrs[i] = d;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ptrArrayDelete(struct ptrArray *p, uintmax_t i)
|
||||||
|
{
|
||||||
|
uintmax_t j;
|
||||||
|
|
||||||
|
if (i >= p->len)
|
||||||
|
complain("index out of range in ptrArrayRemove()");
|
||||||
|
for (j = i; j < p->len - 1; j++)
|
||||||
|
p->ptrs[j] = p->ptrs[j + 1];
|
||||||
|
p->ptrs[j] = NULL;
|
||||||
|
p->len--;
|
||||||
|
}
|
12
uipriv.h
12
uipriv.h
|
@ -14,3 +14,15 @@ extern uiContainer *newBin(void);
|
||||||
extern void binSetMainControl(uiContainer *, uiControl *);
|
extern void binSetMainControl(uiContainer *, uiControl *);
|
||||||
extern void binSetMargins(uiContainer *, intmax_t, intmax_t, intmax_t, intmax_t);
|
extern void binSetMargins(uiContainer *, intmax_t, intmax_t, intmax_t, intmax_t);
|
||||||
extern void binSetParent(uiContainer *, uintptr_t);
|
extern void binSetParent(uiContainer *, uintptr_t);
|
||||||
|
|
||||||
|
// array.c
|
||||||
|
struct ptrArray {
|
||||||
|
void **ptrs;
|
||||||
|
uintmax_t len;
|
||||||
|
uintmax_t cap;
|
||||||
|
};
|
||||||
|
struct ptrArray *newPtrArray(void);
|
||||||
|
void ptrArrayDestroy(sstruct ptrArray *);
|
||||||
|
void ptrArrayAppend(struct ptrArray *, void *);
|
||||||
|
void ptrArrayInsertBefore(struct ptrArray *, uintmax_t, void *);
|
||||||
|
void ptrArrayDelete(struct ptrArray *, uintmax_t);
|
||||||
|
|
|
@ -110,7 +110,6 @@ void uiFreeInitError(const char *err)
|
||||||
uiFree((void *) err);
|
uiFree((void *) err);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO consider DisableThreadLibraryCalls() (will require removing ALL C runtime calls); if we do so we will need to adjust the below signature
|
|
||||||
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
||||||
{
|
{
|
||||||
if (fdwReason == DLL_PROCESS_ATTACH)
|
if (fdwReason == DLL_PROCESS_ATTACH)
|
||||||
|
|
Loading…
Reference in New Issue