diff --git a/test.c b/test.c index d5e09362..38bd4c01 100644 --- a/test.c +++ b/test.c @@ -196,6 +196,8 @@ int main(int argc, char *argv[]) for (i = 1; i < argc; i++) if (strcmp(argv[i], "leaks") == 0) o.debugLogAllocations = 1; + else if (strcmp(argv[i], "lifetime") == 0) + o.debugLogLifetimes = 1; else { fprintf(stderr, "%s: unrecognized option %s\n", argv[0], argv[i]); return 1; diff --git a/ui.idl b/ui.idl index b776531f..21b13421 100644 --- a/ui.idl +++ b/ui.idl @@ -20,6 +20,9 @@ struct InitOptions { // If nonzero, allocations will be logged to stderr. // See leaks.awk. field debugLogAllocations int; + + // If nonzero, OS control creation/destruction will be logged to stderr. + field debugLogLifetimes int; }; // TODO const char diff --git a/unix/button.c b/unix/button.c index 4e25da94..ec2f8fdd 100644 --- a/unix/button.c +++ b/unix/button.c @@ -25,6 +25,8 @@ static void onDestroy(GtkWidget *widget, gpointer data) { struct button *b = (struct button *) data; + if (options.debugLogLifetimes) + fprintf(stderr, "GtkWidget::destroy button %p\n", b); uiFree(b); } @@ -55,6 +57,8 @@ uiButton *uiNewButton(const char *text) struct button *b; b = uiNew(struct button); + if (options.debugLogLifetimes) + fprintf(stderr, "uiNewButton() %p %s\n", b, text); uiUnixNewControl(uiControl(b), GTK_TYPE_BUTTON, FALSE, FALSE, diff --git a/unix/checkbox.c b/unix/checkbox.c index 31918dc7..22ea702c 100644 --- a/unix/checkbox.c +++ b/unix/checkbox.c @@ -28,6 +28,8 @@ static void onDestroy(GtkWidget *widget, gpointer data) { struct checkbox *c = (struct checkbox *) data; + if (options.debugLogLifetimes) + fprintf(stderr, "GtkWidget::destroy checkbox %p\n", c); uiFree(c); } @@ -79,6 +81,8 @@ uiCheckbox *uiNewCheckbox(const char *text) struct checkbox *c; c = uiNew(struct checkbox); + if (options.debugLogLifetimes) + fprintf(stderr, "uiNewCheckbox() %p %s\n", c, text); uiUnixNewControl(uiControl(c), GTK_TYPE_CHECK_BUTTON, FALSE, FALSE, diff --git a/unix/entry.c b/unix/entry.c index 55f75a5c..c2306984 100644 --- a/unix/entry.c +++ b/unix/entry.c @@ -11,6 +11,8 @@ static void onDestroy(GtkWidget *widget, gpointer data) { struct entry *e = (struct entry *) data; + if (options.debugLogLifetimes) + fprintf(stderr, "GtkWidget::destroy entry %p\n", e); uiFree(e); } @@ -33,6 +35,8 @@ uiEntry *uiNewEntry(void) struct entry *e; e = uiNew(struct entry); + if (options.debugLogLifetimes) + fprintf(stderr, "uiNewEntry() %p\n", e); uiUnixNewControl(uiControl(e), GTK_TYPE_ENTRY, FALSE, FALSE, diff --git a/unix/label.c b/unix/label.c index e1dc03f4..052fca2d 100644 --- a/unix/label.c +++ b/unix/label.c @@ -11,6 +11,8 @@ static void onDestroy(GtkWidget *widget, gpointer data) { struct label *l = (struct label *) data; + if (options.debugLogLifetimes) + fprintf(stderr, "GtkWidget::destroy label %p\n", l); uiFree(l); } @@ -34,6 +36,8 @@ uiLabel *uiNewLabel(const char *text) struct label *l; l = uiNew(struct label); + if (options.debugLogLifetimes) + fprintf(stderr, "uiNewLabel() %p %s\n", l, text); uiUnixNewControl(uiControl(l), GTK_TYPE_LABEL, FALSE, FALSE, diff --git a/unix/newcontrol.c b/unix/newcontrol.c index d23e1903..56c685b1 100644 --- a/unix/newcontrol.c +++ b/unix/newcontrol.c @@ -18,6 +18,8 @@ static void singleDestroy(uiControl *c) { singleWidget *s = (singleWidget *) (c->Internal); + if (options.debugLogLifetimes) + fprintf(stderr, "uiControlDestroy() singleWidget %p %p\n", c, s); gtk_widget_destroy(s->immediate); } @@ -161,6 +163,8 @@ static void onDestroy(GtkWidget *widget, gpointer data) { singleWidget *s = (singleWidget *) data; + if (options.debugLogLifetimes) + fprintf(stderr, "GtkWidget::destroy singleWidget %p\n", s); uiFree(s); } @@ -170,6 +174,8 @@ void uiUnixNewControl(uiControl *c, GType type, gboolean inScrolledWindow, gbool va_list ap; s = uiNew(singleWidget); + if (options.debugLogLifetimes) + fprintf(stderr, "uiUnixNewControl() %p %p\n", c, s); va_start(ap, firstProperty); s->widget = GTK_WIDGET(g_object_new_valist(type, firstProperty, ap)); diff --git a/unix/parent.c b/unix/parent.c index 5ae6812f..f7966f58 100644 --- a/unix/parent.c +++ b/unix/parent.c @@ -31,6 +31,8 @@ static void uipParent_init(uipParent *p) { if (options.debugLogAllocations) fprintf(stderr, "%p alloc uipParent\n", p); + if (options.debugLogLifetimes) + fprintf(stderr, "uipParent_init() %p\n", p); p->children = g_ptr_array_new(); gtk_widget_set_has_window(GTK_WIDGET(p), FALSE); } @@ -41,6 +43,8 @@ static void uipParent_dispose(GObject *obj) { uipParent *p = uipParent(obj); + if (options.debugLogLifetimes) + fprintf(stderr, "uipParent_dispose() %p\n", p); if (p->children != NULL) { g_ptr_array_unref(p->children); p->children = NULL; @@ -54,6 +58,8 @@ static void uipParent_dispose(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); if (options.debugLogAllocations) fprintf(stderr, "%p free\n", obj); @@ -137,6 +143,8 @@ static void parentDestroy(uiParent *pp) { uipParent *p = uipParent(pp->Internal); + if (options.debugLogLifetimes) + fprintf(stderr, "uiParentDestroy() %p %p\n", pp, p); gtk_widget_destroy(GTK_WIDGET(p)); } @@ -181,6 +189,8 @@ uiParent *uiNewParent(uintptr_t osParent) p = uiNew(uiParent); p->Internal = g_object_new(uipParentType, NULL); + if (options.debugLogLifetimes) + fprintf(stderr, "uiNewParent() %p %p\n", p, p->Internal); p->Destroy = parentDestroy; p->Handle = parentHandle; p->SetMainControl = parentSetMainControl; diff --git a/unix/tab.c b/unix/tab.c index ba7bfa37..af38f665 100644 --- a/unix/tab.c +++ b/unix/tab.c @@ -15,6 +15,8 @@ static void onDestroy(GtkWidget *widget, gpointer data) { struct tab *t = (struct tab *) data; + if (options.debugLogLifetimes) + fprintf(stderr, "GtkWidget::destroy tab %p\n", t); uiFree(t->pages); uiFree(t); } @@ -64,6 +66,9 @@ uiTab *uiNewTab(void) struct tab *t; t = uiNew(struct tab); + // TODO log page lifetimes too + if (options.debugLogLifetimes) + fprintf(stderr, "uiNewTab() %p\n", t); uiUnixNewControl(uiControl(t), GTK_TYPE_NOTEBOOK, FALSE, FALSE,