Added the type names back to the allocators. Implemented on GTK+ only for now.
This commit is contained in:
parent
057c6d0cfd
commit
5cf19dcc17
|
@ -21,7 +21,7 @@ void ptrArrayAppend(struct ptrArray *p, void *d)
|
|||
{
|
||||
if (p->len >= p->cap) {
|
||||
p->cap += grow;
|
||||
p->ptrs = (void **) uiRealloc(p->ptrs, p->cap * sizeof (void *));
|
||||
p->ptrs = (void **) uiRealloc(p->ptrs, p->cap * sizeof (void *), "void *[]");
|
||||
}
|
||||
p->ptrs[p->len] = d;
|
||||
p->len++;
|
||||
|
@ -33,7 +33,7 @@ void ptrArrayInsertBefore(struct ptrArray *p, uintmax_t i, void *d)
|
|||
complain("index out of range in ptrArrayInsertBefore()");
|
||||
if (p->len >= p->cap) {
|
||||
p->cap += grow;
|
||||
p->ptrs = (void **) uiRealloc(p->ptrs, p->cap * sizeof (void *));
|
||||
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 *));
|
||||
|
|
6
uipriv.h
6
uipriv.h
|
@ -3,9 +3,9 @@
|
|||
|
||||
extern uiInitOptions options;
|
||||
|
||||
extern void *uiAlloc(size_t);
|
||||
#define uiNew(T) ((T *) uiAlloc(sizeof (T)))
|
||||
extern void *uiRealloc(void *, size_t);
|
||||
extern void *uiAlloc(size_t, const char *);
|
||||
#define uiNew(T) ((T *) uiAlloc(sizeof (T), #T))
|
||||
extern void *uiRealloc(void *, size_t, const char *);
|
||||
extern void uiFree(void *);
|
||||
|
||||
extern void complain(const char *, ...);
|
||||
|
|
28
unix/alloc.c
28
unix/alloc.c
|
@ -4,6 +4,15 @@
|
|||
|
||||
static GPtrArray *allocations;
|
||||
|
||||
#define UINT8(p) ((uint8_t *) (p))
|
||||
#define PVOID(p) ((void *) (p))
|
||||
#define EXTRA (sizeof (size_t) + sizeof (const char **))
|
||||
#define DATA(p) PVOID(UINT8(p) + EXTRA)
|
||||
#define BASE(p) PVOID(UINT8(p) - EXTRA)
|
||||
#define SIZE(p) ((size_t *) (p))
|
||||
#define CCHAR(p) ((const char **) (p))
|
||||
#define TYPE(p) CCHAR(UINT8(p) + sizeof (size_t))
|
||||
|
||||
void initAlloc(void)
|
||||
{
|
||||
allocations = g_ptr_array_new();
|
||||
|
@ -11,7 +20,7 @@ void initAlloc(void)
|
|||
|
||||
static void uninitComplain(gpointer ptr, gpointer data)
|
||||
{
|
||||
fprintf(stderr, "[libui] %p\n", ptr);
|
||||
fprintf(stderr, "[libui] %p %s\n", ptr, *TYPE(ptr));
|
||||
}
|
||||
|
||||
// TODO bring back the type names for this
|
||||
|
@ -26,31 +35,26 @@ void uninitAlloc(void)
|
|||
complain("either you left something around or there's a bug in libui");
|
||||
}
|
||||
|
||||
#define UINT8(p) ((uint8_t *) (p))
|
||||
#define PVOID(p) ((void *) (p))
|
||||
#define DATA(p) PVOID(UINT8(p) + sizeof (size_t))
|
||||
#define BASE(p) PVOID(UINT8(p) - sizeof (size_t))
|
||||
#define SIZE(p) ((size_t *) (p))
|
||||
|
||||
void *uiAlloc(size_t size)
|
||||
void *uiAlloc(size_t size, const char *type)
|
||||
{
|
||||
void *out;
|
||||
|
||||
out = g_malloc0(sizeof (size_t) + size);
|
||||
out = g_malloc0(EXTRA + size);
|
||||
*SIZE(out) = size;
|
||||
*TYPE(out) = type;
|
||||
g_ptr_array_add(allocations, out);
|
||||
return DATA(out);
|
||||
}
|
||||
|
||||
void *uiRealloc(void *p, size_t new)
|
||||
void *uiRealloc(void *p, size_t new, const char *type)
|
||||
{
|
||||
void *out;
|
||||
size_t *s;
|
||||
|
||||
if (p == NULL)
|
||||
return uiAlloc(new);
|
||||
return uiAlloc(new, type);
|
||||
p = BASE(p);
|
||||
out = g_realloc(p, sizeof (size_t) + new);
|
||||
out = g_realloc(p, EXTRA + new);
|
||||
s = SIZE(out);
|
||||
if (new <= *s)
|
||||
memset(((uint8_t *) DATA(out)) + *s, 0, new - *s);
|
||||
|
|
Loading…
Reference in New Issue