Added lifetime logging and implemented most of it on the Unix backend.

This commit is contained in:
Pietro Gagliardi 2015-04-18 01:11:34 -04:00
parent 5bd6140d46
commit 786ef2cbe4
9 changed files with 42 additions and 0 deletions

2
test.c
View File

@ -196,6 +196,8 @@ int main(int argc, char *argv[])
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
if (strcmp(argv[i], "leaks") == 0) if (strcmp(argv[i], "leaks") == 0)
o.debugLogAllocations = 1; o.debugLogAllocations = 1;
else if (strcmp(argv[i], "lifetime") == 0)
o.debugLogLifetimes = 1;
else { 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;

3
ui.idl
View File

@ -20,6 +20,9 @@ struct InitOptions {
// If nonzero, allocations will be logged to stderr. // If nonzero, allocations will be logged to stderr.
// See leaks.awk. // See leaks.awk.
field debugLogAllocations int; field debugLogAllocations int;
// If nonzero, OS control creation/destruction will be logged to stderr.
field debugLogLifetimes int;
}; };
// TODO const char // TODO const char

View File

@ -25,6 +25,8 @@ static void onDestroy(GtkWidget *widget, gpointer data)
{ {
struct button *b = (struct button *) data; struct button *b = (struct button *) data;
if (options.debugLogLifetimes)
fprintf(stderr, "GtkWidget::destroy button %p\n", b);
uiFree(b); uiFree(b);
} }
@ -55,6 +57,8 @@ uiButton *uiNewButton(const char *text)
struct button *b; struct button *b;
b = uiNew(struct button); b = uiNew(struct button);
if (options.debugLogLifetimes)
fprintf(stderr, "uiNewButton() %p %s\n", b, text);
uiUnixNewControl(uiControl(b), GTK_TYPE_BUTTON, uiUnixNewControl(uiControl(b), GTK_TYPE_BUTTON,
FALSE, FALSE, FALSE, FALSE,

View File

@ -28,6 +28,8 @@ static void onDestroy(GtkWidget *widget, gpointer data)
{ {
struct checkbox *c = (struct checkbox *) data; struct checkbox *c = (struct checkbox *) data;
if (options.debugLogLifetimes)
fprintf(stderr, "GtkWidget::destroy checkbox %p\n", c);
uiFree(c); uiFree(c);
} }
@ -79,6 +81,8 @@ uiCheckbox *uiNewCheckbox(const char *text)
struct checkbox *c; struct checkbox *c;
c = uiNew(struct checkbox); c = uiNew(struct checkbox);
if (options.debugLogLifetimes)
fprintf(stderr, "uiNewCheckbox() %p %s\n", c, text);
uiUnixNewControl(uiControl(c), GTK_TYPE_CHECK_BUTTON, uiUnixNewControl(uiControl(c), GTK_TYPE_CHECK_BUTTON,
FALSE, FALSE, FALSE, FALSE,

View File

@ -11,6 +11,8 @@ static void onDestroy(GtkWidget *widget, gpointer data)
{ {
struct entry *e = (struct entry *) data; struct entry *e = (struct entry *) data;
if (options.debugLogLifetimes)
fprintf(stderr, "GtkWidget::destroy entry %p\n", e);
uiFree(e); uiFree(e);
} }
@ -33,6 +35,8 @@ uiEntry *uiNewEntry(void)
struct entry *e; struct entry *e;
e = uiNew(struct entry); e = uiNew(struct entry);
if (options.debugLogLifetimes)
fprintf(stderr, "uiNewEntry() %p\n", e);
uiUnixNewControl(uiControl(e), GTK_TYPE_ENTRY, uiUnixNewControl(uiControl(e), GTK_TYPE_ENTRY,
FALSE, FALSE, FALSE, FALSE,

View File

@ -11,6 +11,8 @@ static void onDestroy(GtkWidget *widget, gpointer data)
{ {
struct label *l = (struct label *) data; struct label *l = (struct label *) data;
if (options.debugLogLifetimes)
fprintf(stderr, "GtkWidget::destroy label %p\n", l);
uiFree(l); uiFree(l);
} }
@ -34,6 +36,8 @@ uiLabel *uiNewLabel(const char *text)
struct label *l; struct label *l;
l = uiNew(struct label); l = uiNew(struct label);
if (options.debugLogLifetimes)
fprintf(stderr, "uiNewLabel() %p %s\n", l, text);
uiUnixNewControl(uiControl(l), GTK_TYPE_LABEL, uiUnixNewControl(uiControl(l), GTK_TYPE_LABEL,
FALSE, FALSE, FALSE, FALSE,

View File

@ -18,6 +18,8 @@ static void singleDestroy(uiControl *c)
{ {
singleWidget *s = (singleWidget *) (c->Internal); singleWidget *s = (singleWidget *) (c->Internal);
if (options.debugLogLifetimes)
fprintf(stderr, "uiControlDestroy() singleWidget %p %p\n", c, s);
gtk_widget_destroy(s->immediate); gtk_widget_destroy(s->immediate);
} }
@ -161,6 +163,8 @@ static void onDestroy(GtkWidget *widget, gpointer data)
{ {
singleWidget *s = (singleWidget *) data; singleWidget *s = (singleWidget *) data;
if (options.debugLogLifetimes)
fprintf(stderr, "GtkWidget::destroy singleWidget %p\n", s);
uiFree(s); uiFree(s);
} }
@ -170,6 +174,8 @@ void uiUnixNewControl(uiControl *c, GType type, gboolean inScrolledWindow, gbool
va_list ap; va_list ap;
s = uiNew(singleWidget); s = uiNew(singleWidget);
if (options.debugLogLifetimes)
fprintf(stderr, "uiUnixNewControl() %p %p\n", c, s);
va_start(ap, firstProperty); va_start(ap, firstProperty);
s->widget = GTK_WIDGET(g_object_new_valist(type, firstProperty, ap)); s->widget = GTK_WIDGET(g_object_new_valist(type, firstProperty, ap));

View File

@ -31,6 +31,8 @@ static void uipParent_init(uipParent *p)
{ {
if (options.debugLogAllocations) if (options.debugLogAllocations)
fprintf(stderr, "%p alloc uipParent\n", p); fprintf(stderr, "%p alloc uipParent\n", p);
if (options.debugLogLifetimes)
fprintf(stderr, "uipParent_init() %p\n", p);
p->children = g_ptr_array_new(); p->children = g_ptr_array_new();
gtk_widget_set_has_window(GTK_WIDGET(p), FALSE); gtk_widget_set_has_window(GTK_WIDGET(p), FALSE);
} }
@ -41,6 +43,8 @@ static void uipParent_dispose(GObject *obj)
{ {
uipParent *p = uipParent(obj); uipParent *p = uipParent(obj);
if (options.debugLogLifetimes)
fprintf(stderr, "uipParent_dispose() %p\n", p);
if (p->children != NULL) { if (p->children != NULL) {
g_ptr_array_unref(p->children); g_ptr_array_unref(p->children);
p->children = NULL; p->children = NULL;
@ -54,6 +58,8 @@ static void uipParent_dispose(GObject *obj)
static void uipParent_finalize(GObject *obj) static void uipParent_finalize(GObject *obj)
{ {
if (options.debugLogLifetimes)
fprintf(stderr, "uipParent_finalize() %p\n", obj);
G_OBJECT_CLASS(uipParent_parent_class)->finalize(obj); G_OBJECT_CLASS(uipParent_parent_class)->finalize(obj);
if (options.debugLogAllocations) if (options.debugLogAllocations)
fprintf(stderr, "%p free\n", obj); fprintf(stderr, "%p free\n", obj);
@ -137,6 +143,8 @@ static void parentDestroy(uiParent *pp)
{ {
uipParent *p = uipParent(pp->Internal); uipParent *p = uipParent(pp->Internal);
if (options.debugLogLifetimes)
fprintf(stderr, "uiParentDestroy() %p %p\n", pp, p);
gtk_widget_destroy(GTK_WIDGET(p)); gtk_widget_destroy(GTK_WIDGET(p));
} }
@ -181,6 +189,8 @@ uiParent *uiNewParent(uintptr_t osParent)
p = uiNew(uiParent); p = uiNew(uiParent);
p->Internal = g_object_new(uipParentType, NULL); p->Internal = g_object_new(uipParentType, NULL);
if (options.debugLogLifetimes)
fprintf(stderr, "uiNewParent() %p %p\n", p, p->Internal);
p->Destroy = parentDestroy; p->Destroy = parentDestroy;
p->Handle = parentHandle; p->Handle = parentHandle;
p->SetMainControl = parentSetMainControl; p->SetMainControl = parentSetMainControl;

View File

@ -15,6 +15,8 @@ static void onDestroy(GtkWidget *widget, gpointer data)
{ {
struct tab *t = (struct tab *) data; struct tab *t = (struct tab *) data;
if (options.debugLogLifetimes)
fprintf(stderr, "GtkWidget::destroy tab %p\n", t);
uiFree(t->pages); uiFree(t->pages);
uiFree(t); uiFree(t);
} }
@ -64,6 +66,9 @@ uiTab *uiNewTab(void)
struct tab *t; struct tab *t;
t = uiNew(struct tab); t = uiNew(struct tab);
// TODO log page lifetimes too
if (options.debugLogLifetimes)
fprintf(stderr, "uiNewTab() %p\n", t);
uiUnixNewControl(uiControl(t), GTK_TYPE_NOTEBOOK, uiUnixNewControl(uiControl(t), GTK_TYPE_NOTEBOOK,
FALSE, FALSE, FALSE, FALSE,