Decided to remove allocation logging. Leak checking can be done with dedicated tools.
This commit is contained in:
parent
dc9cdcc7bb
commit
c8695e4ca2
|
@ -12,8 +12,6 @@ void *uiAlloc(size_t size, const char *type)
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
memset(out, 0, size);
|
memset(out, 0, size);
|
||||||
if (options.debugLogAllocations)
|
|
||||||
fprintf(stderr, "%p alloc %s\n", out, type);
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,8 +27,6 @@ void *uiRealloc(void *p, size_t size, const char *type)
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
// TODO zero the extra memory
|
// TODO zero the extra memory
|
||||||
if (options.debugLogAllocations)
|
|
||||||
fprintf(stderr, "%p realloc %p\n", p, out);
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +35,4 @@ void uiFree(void *p)
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return;
|
return;
|
||||||
free(p);
|
free(p);
|
||||||
if (options.debugLogAllocations)
|
|
||||||
fprintf(stderr, "%p free\n", p);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,6 @@
|
||||||
|
|
||||||
@implementation uipButtonDelegate
|
@implementation uipButtonDelegate
|
||||||
|
|
||||||
uiLogObjCClassAllocations
|
|
||||||
|
|
||||||
- (IBAction)buttonClicked:(id)sender
|
- (IBAction)buttonClicked:(id)sender
|
||||||
{
|
{
|
||||||
(*(self->onClicked))(self->b, self->onClickedData);
|
(*(self->onClicked))(self->b, self->onClickedData);
|
||||||
|
|
|
@ -13,8 +13,6 @@
|
||||||
|
|
||||||
@implementation uipCheckboxDelegate
|
@implementation uipCheckboxDelegate
|
||||||
|
|
||||||
uiLogObjCClassAllocations
|
|
||||||
|
|
||||||
- (IBAction)checkboxToggled:(id)sender
|
- (IBAction)checkboxToggled:(id)sender
|
||||||
{
|
{
|
||||||
(*(self->onToggled))(self->c, self->onToggledData);
|
(*(self->onToggled))(self->c, self->onToggledData);
|
||||||
|
|
|
@ -14,8 +14,6 @@
|
||||||
|
|
||||||
@implementation containerView
|
@implementation containerView
|
||||||
|
|
||||||
// TODO allocation logger
|
|
||||||
|
|
||||||
- (void)setContainer:(uiContainer *)cc
|
- (void)setContainer:(uiContainer *)cc
|
||||||
{
|
{
|
||||||
self->c = cc;
|
self->c = cc;
|
||||||
|
|
|
@ -28,8 +28,6 @@ enum {
|
||||||
|
|
||||||
@implementation menuManager
|
@implementation menuManager
|
||||||
|
|
||||||
// TODO allocation logger
|
|
||||||
|
|
||||||
- (id)init
|
- (id)init
|
||||||
{
|
{
|
||||||
self = [super init];
|
self = [super init];
|
||||||
|
|
|
@ -9,22 +9,6 @@
|
||||||
#define toNSString(str) [NSString stringWithUTF8String:(str)]
|
#define toNSString(str) [NSString stringWithUTF8String:(str)]
|
||||||
#define fromNSString(str) [(str) UTF8String]
|
#define fromNSString(str) [(str) UTF8String]
|
||||||
|
|
||||||
#define uiLogObjCClassAllocations \
|
|
||||||
+ (id)alloc \
|
|
||||||
{ \
|
|
||||||
id thing; \
|
|
||||||
thing = [super alloc]; \
|
|
||||||
if (options.debugLogAllocations) \
|
|
||||||
fprintf(stderr, "%p alloc %s\n", thing, [[self className] UTF8String]); \
|
|
||||||
return thing; \
|
|
||||||
} \
|
|
||||||
- (void)dealloc \
|
|
||||||
{ \
|
|
||||||
[super dealloc]; \
|
|
||||||
if (options.debugLogAllocations) \
|
|
||||||
fprintf(stderr, "%p free\n", self); \
|
|
||||||
}
|
|
||||||
|
|
||||||
// These are based on measurements from Interface Builder.
|
// These are based on measurements from Interface Builder.
|
||||||
// These seem to be based on Auto Layout constants, but I don't see an API that exposes these...
|
// These seem to be based on Auto Layout constants, but I don't see an API that exposes these...
|
||||||
#define macXMargin 20
|
#define macXMargin 20
|
||||||
|
|
|
@ -12,8 +12,6 @@
|
||||||
|
|
||||||
@implementation windowDelegate
|
@implementation windowDelegate
|
||||||
|
|
||||||
// TODO allocation logging
|
|
||||||
|
|
||||||
- (void)setuiWindow:(uiWindow *)ww
|
- (void)setuiWindow:(uiWindow *)ww
|
||||||
{
|
{
|
||||||
self->w = ww;
|
self->w = ww;
|
||||||
|
|
56
leaks.awk
56
leaks.awk
|
@ -1,56 +0,0 @@
|
||||||
# 7 april 2015
|
|
||||||
|
|
||||||
$2 == "alloc" {
|
|
||||||
if ($1 in A) {
|
|
||||||
problem($1 " already allocated (" A[$1] "); allocated at " NR)
|
|
||||||
next
|
|
||||||
}
|
|
||||||
A[$1] = type()
|
|
||||||
next
|
|
||||||
}
|
|
||||||
|
|
||||||
$2 == "realloc" {
|
|
||||||
if (!($1 in A)) {
|
|
||||||
problem($1 " not yet allocated; reallocated at " NR)
|
|
||||||
next
|
|
||||||
}
|
|
||||||
if ($3 in A) {
|
|
||||||
problem($3 " already allocated (" A[$3] "); reallocated at " NR)
|
|
||||||
next
|
|
||||||
}
|
|
||||||
t = A[$1]
|
|
||||||
delete A[$1]
|
|
||||||
A[$3] = t
|
|
||||||
next
|
|
||||||
}
|
|
||||||
|
|
||||||
$2 == "free" {
|
|
||||||
if (!($1 in A)) {
|
|
||||||
problem($1 " not yet allocated; freed at " NR)
|
|
||||||
next
|
|
||||||
}
|
|
||||||
delete A[$1]
|
|
||||||
next
|
|
||||||
}
|
|
||||||
|
|
||||||
{ problem("unrecognized line " $0 " at " NR) }
|
|
||||||
|
|
||||||
END {
|
|
||||||
for (i in A)
|
|
||||||
problem("leaked " A[i] " at " i)
|
|
||||||
close("/dev/stderr")
|
|
||||||
if (hasProblems)
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
function problem(s) {
|
|
||||||
print s > "/dev/stderr"
|
|
||||||
hasProblems = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
function type( s, i) {
|
|
||||||
s = $3
|
|
||||||
for (i = 4; i <= NF; i++)
|
|
||||||
s = s " " $i
|
|
||||||
return s
|
|
||||||
}
|
|
|
@ -27,9 +27,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
memset(&o, 0, sizeof (uiInitOptions));
|
memset(&o, 0, sizeof (uiInitOptions));
|
||||||
for (i = 1; i < argc; i++)
|
for (i = 1; i < argc; i++)
|
||||||
if (strcmp(argv[i], "leaks") == 0)
|
{//TODO else {
|
||||||
o.debugLogAllocations = 1;
|
|
||||||
else {
|
|
||||||
fprintf(stderr, "%s: unrecognized option %s\n", argv[0], argv[i]);
|
fprintf(stderr, "%s: unrecognized option %s\n", argv[0], argv[i]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
4
ui.idl
4
ui.idl
|
@ -20,10 +20,6 @@ raw "#endif";
|
||||||
// TODO note that should be initialized to zero
|
// TODO note that should be initialized to zero
|
||||||
struct InitOptions {
|
struct InitOptions {
|
||||||
// TODO cbSize
|
// TODO cbSize
|
||||||
|
|
||||||
// If nonzero, allocations will be logged to stderr.
|
|
||||||
// See leaks.awk.
|
|
||||||
field debugLogAllocations int;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
func Init(options *InitOptions) *const char;
|
func Init(options *InitOptions) *const char;
|
||||||
|
|
1
uipriv.h
1
uipriv.h
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
extern uiInitOptions options;
|
extern uiInitOptions options;
|
||||||
|
|
||||||
|
// TODO remove the type name arguments
|
||||||
extern void *uiAlloc(size_t, const char *);
|
extern void *uiAlloc(size_t, const char *);
|
||||||
#define uiNew(T) ((T *) uiAlloc(sizeof (T), #T ))
|
#define uiNew(T) ((T *) uiAlloc(sizeof (T), #T ))
|
||||||
extern void *uiRealloc(void *, size_t, const char *);
|
extern void *uiRealloc(void *, size_t, const char *);
|
||||||
|
|
|
@ -7,8 +7,6 @@ void *uiAlloc(size_t size, const char *type)
|
||||||
void *out;
|
void *out;
|
||||||
|
|
||||||
out = g_malloc0(size);
|
out = g_malloc0(size);
|
||||||
if (options.debugLogAllocations)
|
|
||||||
fprintf(stderr, "%p alloc %s\n", out, type);
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,14 +18,10 @@ void *uiRealloc(void *p, size_t size, const char *type)
|
||||||
return uiAlloc(size, type);
|
return uiAlloc(size, type);
|
||||||
// TODO fill with 0s
|
// TODO fill with 0s
|
||||||
out = g_realloc(p, size);
|
out = g_realloc(p, size);
|
||||||
if (options.debugLogAllocations)
|
|
||||||
fprintf(stderr, "%p realloc %p\n", p, out);
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiFree(void *p)
|
void uiFree(void *p)
|
||||||
{
|
{
|
||||||
g_free(p);
|
g_free(p);
|
||||||
if (options.debugLogAllocations)
|
|
||||||
fprintf(stderr, "%p free\n", p);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,6 @@ G_DEFINE_TYPE(containerWidget, containerWidget, GTK_TYPE_CONTAINER)
|
||||||
|
|
||||||
static void containerWidget_init(containerWidget *c)
|
static void containerWidget_init(containerWidget *c)
|
||||||
{
|
{
|
||||||
if (options.debugLogAllocations)
|
|
||||||
fprintf(stderr, "%p alloc containerWidget\n", c);
|
|
||||||
c->widgets = g_ptr_array_new();
|
c->widgets = g_ptr_array_new();
|
||||||
gtk_widget_set_has_window(GTK_WIDGET(c), FALSE);
|
gtk_widget_set_has_window(GTK_WIDGET(c), FALSE);
|
||||||
}
|
}
|
||||||
|
@ -44,8 +42,6 @@ static void containerWidget_finalize(GObject *obj)
|
||||||
|
|
||||||
g_ptr_array_unref(c->widgets);
|
g_ptr_array_unref(c->widgets);
|
||||||
G_OBJECT_CLASS(containerWidget_parent_class)->finalize(obj);
|
G_OBJECT_CLASS(containerWidget_parent_class)->finalize(obj);
|
||||||
if (options.debugLogAllocations)
|
|
||||||
fprintf(stderr, "%p free\n", obj);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void containerWidget_add(GtkContainer *container, GtkWidget *widget)
|
static void containerWidget_add(GtkContainer *container, GtkWidget *widget)
|
||||||
|
|
|
@ -17,8 +17,6 @@ void *uiAlloc(size_t size, const char *type)
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
ZeroMemory(out, size);
|
ZeroMemory(out, size);
|
||||||
if (options.debugLogAllocations)
|
|
||||||
fprintf(stderr, "%p alloc %s\n", out, type);
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,8 +32,6 @@ void *uiRealloc(void *p, size_t size, const char *type)
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
// TODO zero the extra memory
|
// TODO zero the extra memory
|
||||||
if (options.debugLogAllocations)
|
|
||||||
fprintf(stderr, "%p realloc %p\n", p, out);
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +40,4 @@ void uiFree(void *p)
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return;
|
return;
|
||||||
free(p);
|
free(p);
|
||||||
if (options.debugLogAllocations)
|
|
||||||
fprintf(stderr, "%p free\n", p);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue