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();
|
||||
}
|
||||
memset(out, 0, size);
|
||||
if (options.debugLogAllocations)
|
||||
fprintf(stderr, "%p alloc %s\n", out, type);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
@ -29,8 +27,6 @@ void *uiRealloc(void *p, size_t size, const char *type)
|
|||
abort();
|
||||
}
|
||||
// TODO zero the extra memory
|
||||
if (options.debugLogAllocations)
|
||||
fprintf(stderr, "%p realloc %p\n", p, out);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
@ -39,6 +35,4 @@ void uiFree(void *p)
|
|||
if (p == NULL)
|
||||
return;
|
||||
free(p);
|
||||
if (options.debugLogAllocations)
|
||||
fprintf(stderr, "%p free\n", p);
|
||||
}
|
||||
|
|
|
@ -13,8 +13,6 @@
|
|||
|
||||
@implementation uipButtonDelegate
|
||||
|
||||
uiLogObjCClassAllocations
|
||||
|
||||
- (IBAction)buttonClicked:(id)sender
|
||||
{
|
||||
(*(self->onClicked))(self->b, self->onClickedData);
|
||||
|
|
|
@ -13,8 +13,6 @@
|
|||
|
||||
@implementation uipCheckboxDelegate
|
||||
|
||||
uiLogObjCClassAllocations
|
||||
|
||||
- (IBAction)checkboxToggled:(id)sender
|
||||
{
|
||||
(*(self->onToggled))(self->c, self->onToggledData);
|
||||
|
|
|
@ -14,8 +14,6 @@
|
|||
|
||||
@implementation containerView
|
||||
|
||||
// TODO allocation logger
|
||||
|
||||
- (void)setContainer:(uiContainer *)cc
|
||||
{
|
||||
self->c = cc;
|
||||
|
|
|
@ -28,8 +28,6 @@ enum {
|
|||
|
||||
@implementation menuManager
|
||||
|
||||
// TODO allocation logger
|
||||
|
||||
- (id)init
|
||||
{
|
||||
self = [super init];
|
||||
|
|
|
@ -9,22 +9,6 @@
|
|||
#define toNSString(str) [NSString stringWithUTF8String:(str)]
|
||||
#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 seem to be based on Auto Layout constants, but I don't see an API that exposes these...
|
||||
#define macXMargin 20
|
||||
|
|
|
@ -12,8 +12,6 @@
|
|||
|
||||
@implementation windowDelegate
|
||||
|
||||
// TODO allocation logging
|
||||
|
||||
- (void)setuiWindow:(uiWindow *)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));
|
||||
for (i = 1; i < argc; i++)
|
||||
if (strcmp(argv[i], "leaks") == 0)
|
||||
o.debugLogAllocations = 1;
|
||||
else {
|
||||
{//TODO else {
|
||||
fprintf(stderr, "%s: unrecognized option %s\n", argv[0], argv[i]);
|
||||
return 1;
|
||||
}
|
||||
|
|
4
ui.idl
4
ui.idl
|
@ -20,10 +20,6 @@ raw "#endif";
|
|||
// TODO note that should be initialized to zero
|
||||
struct InitOptions {
|
||||
// TODO cbSize
|
||||
|
||||
// If nonzero, allocations will be logged to stderr.
|
||||
// See leaks.awk.
|
||||
field debugLogAllocations int;
|
||||
};
|
||||
|
||||
func Init(options *InitOptions) *const char;
|
||||
|
|
1
uipriv.h
1
uipriv.h
|
@ -3,6 +3,7 @@
|
|||
|
||||
extern uiInitOptions options;
|
||||
|
||||
// TODO remove the type name arguments
|
||||
extern void *uiAlloc(size_t, const char *);
|
||||
#define uiNew(T) ((T *) uiAlloc(sizeof (T), #T ))
|
||||
extern void *uiRealloc(void *, size_t, const char *);
|
||||
|
|
|
@ -7,8 +7,6 @@ void *uiAlloc(size_t size, const char *type)
|
|||
void *out;
|
||||
|
||||
out = g_malloc0(size);
|
||||
if (options.debugLogAllocations)
|
||||
fprintf(stderr, "%p alloc %s\n", out, type);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
@ -20,14 +18,10 @@ void *uiRealloc(void *p, size_t size, const char *type)
|
|||
return uiAlloc(size, type);
|
||||
// TODO fill with 0s
|
||||
out = g_realloc(p, size);
|
||||
if (options.debugLogAllocations)
|
||||
fprintf(stderr, "%p realloc %p\n", p, out);
|
||||
return out;
|
||||
}
|
||||
|
||||
void uiFree(void *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)
|
||||
{
|
||||
if (options.debugLogAllocations)
|
||||
fprintf(stderr, "%p alloc containerWidget\n", c);
|
||||
c->widgets = g_ptr_array_new();
|
||||
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_OBJECT_CLASS(containerWidget_parent_class)->finalize(obj);
|
||||
if (options.debugLogAllocations)
|
||||
fprintf(stderr, "%p free\n", obj);
|
||||
}
|
||||
|
||||
static void containerWidget_add(GtkContainer *container, GtkWidget *widget)
|
||||
|
|
|
@ -17,8 +17,6 @@ void *uiAlloc(size_t size, const char *type)
|
|||
abort();
|
||||
}
|
||||
ZeroMemory(out, size);
|
||||
if (options.debugLogAllocations)
|
||||
fprintf(stderr, "%p alloc %s\n", out, type);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
@ -34,8 +32,6 @@ void *uiRealloc(void *p, size_t size, const char *type)
|
|||
abort();
|
||||
}
|
||||
// TODO zero the extra memory
|
||||
if (options.debugLogAllocations)
|
||||
fprintf(stderr, "%p realloc %p\n", p, out);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
@ -44,6 +40,4 @@ void uiFree(void *p)
|
|||
if (p == NULL)
|
||||
return;
|
||||
free(p);
|
||||
if (options.debugLogAllocations)
|
||||
fprintf(stderr, "%p free\n", p);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue