Somewhat implemented uninitAlloc() on OS X.
This commit is contained in:
parent
33f41d6c37
commit
c079e43784
|
@ -2,8 +2,11 @@
|
||||||
#import <stdlib.h>
|
#import <stdlib.h>
|
||||||
#import "uipriv_darwin.h"
|
#import "uipriv_darwin.h"
|
||||||
|
|
||||||
|
NSMutableArray *allocations;
|
||||||
|
|
||||||
void initAlloc(void)
|
void initAlloc(void)
|
||||||
{
|
{
|
||||||
|
allocations = [NSMutableArray new];
|
||||||
}
|
}
|
||||||
|
|
||||||
#define UINT8(p) ((uint8_t *) (p))
|
#define UINT8(p) ((uint8_t *) (p))
|
||||||
|
@ -17,6 +20,20 @@ void initAlloc(void)
|
||||||
|
|
||||||
void uninitAlloc(void)
|
void uninitAlloc(void)
|
||||||
{
|
{
|
||||||
|
if ([allocations count] == 0) {
|
||||||
|
[allocations release];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fprintf(stderr, "[libui] leaked allocations:\n");
|
||||||
|
[allocations enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
||||||
|
NSValue *v;
|
||||||
|
void *ptr;
|
||||||
|
|
||||||
|
v = (NSValue *) obj;
|
||||||
|
ptr = [v pointerValue];
|
||||||
|
fprintf(stderr, "[libui] %p %s\n", ptr, *TYPE(ptr));
|
||||||
|
}];
|
||||||
|
complain("either you left something around or there's a bug in libui");
|
||||||
}
|
}
|
||||||
|
|
||||||
void *uiAlloc(size_t size, const char *type)
|
void *uiAlloc(size_t size, const char *type)
|
||||||
|
@ -31,6 +48,7 @@ void *uiAlloc(size_t size, const char *type)
|
||||||
memset(DATA(out), 0, size);
|
memset(DATA(out), 0, size);
|
||||||
*SIZE(out) = size;
|
*SIZE(out) = size;
|
||||||
*TYPE(out) = type;
|
*TYPE(out) = type;
|
||||||
|
[allocations addObject:[NSValue valueWithPointer:out]];
|
||||||
return DATA(out);
|
return DATA(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +69,8 @@ void *uiRealloc(void *p, size_t new, const char *type)
|
||||||
if (new <= *s)
|
if (new <= *s)
|
||||||
memset(((uint8_t *) DATA(out)) + *s, 0, new - *s);
|
memset(((uint8_t *) DATA(out)) + *s, 0, new - *s);
|
||||||
*s = new;
|
*s = new;
|
||||||
|
[allocations removeObject:[NSValue valueWithPointer:p]];
|
||||||
|
[allocations addObject:[NSValue valueWithPointer:out]];
|
||||||
return DATA(out);
|
return DATA(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,4 +79,5 @@ void uiFree(void *p)
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
complain("attempt to uiFree(NULL); there's a bug somewhere");
|
complain("attempt to uiFree(NULL); there's a bug somewhere");
|
||||||
free(BASE(p));
|
free(BASE(p));
|
||||||
|
[allocations removeObject:[NSValue valueWithPointer:p]];
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ void uiUninit(void)
|
||||||
{
|
{
|
||||||
// TODO free menus
|
// TODO free menus
|
||||||
// TODO free application delegate
|
// TODO free application delegate
|
||||||
// TODO uninit alloc
|
uninitAlloc();
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiFreeInitError(const char *err)
|
void uiFreeInitError(const char *err)
|
||||||
|
|
|
@ -49,3 +49,4 @@ extern uiWindow *windowFromNSWindow(NSWindow *);
|
||||||
|
|
||||||
// alloc.m
|
// alloc.m
|
||||||
extern void initAlloc(void);
|
extern void initAlloc(void);
|
||||||
|
extern void uninitAlloc(void);
|
||||||
|
|
Loading…
Reference in New Issue