diff --git a/lifetimes.go b/lifetimes.go deleted file mode 100644 index 8affb905..00000000 --- a/lifetimes.go +++ /dev/null @@ -1,150 +0,0 @@ -// 18 april 2015 -package main - -import ( - "fmt" - "os" - "bufio" - "strings" - "strconv" -) - -func toaddr(s string) uintptr { - // TODO verify this call - n, err := strconv.ParseUint(s, 0, 0) - if err != nil { - panic(err) - } - return uintptr(n) -} - -var failed = false - -func report(format string, args ...interface{}) { - fmt.Fprintf(os.Stderr, format, args...) - failed = true -} - -type Object struct { - Type string - Detail string - Refs int - CanDestroy bool -} - -var objs = make(map[uintptr]*Object) -var singles = make(map[uintptr]*Object) - -var newControls = map[string]string{ - "uiNewButton()": "button", - "uiNewCheckbox()": "checkbox", - "uiNewEntry()": "entry", - "uiNewLabel()": "label", - "uiNewTab()": "tab", -} - -func newControl(parts []string) { - ty := newControls[parts[0]] - addr := toaddr(parts[1]) - detail := strings.Join(parts[2:], " ") - o := &Object{ - Type: ty, - Detail: detail, - Refs: 1, - } - if oo := objs[addr]; oo != nil { - report("duplicate object %s %q, %s %q at 0x%X\n", - oo.Type, oo.Detail, - o.Type, o.Detail, - addr) - } - if oo := singles[addr]; oo != nil { - report("single %s %q and objecct %s %q coexist at 0x%X\n", - oo.Type, oo.Detail, - o.Type, o.Detail, - addr) - } - objs[addr] = o -} - -func newSingle(parts []string) { - addrObj := toaddr(parts[1]) - addrSingle := toaddr(parts[2]) - o := objs[addrObj] - if o == nil { - report("single without object at 0x%X\n", addrObj) - } - o.Refs++ - if oo := singles[addrSingle]; oo != nil { - report("duplicate singles %s %q, %s %q at 0x%X\n", - oo.Type, oo.Detail, - o.Type, o.Detail, - addrSingle) - } - singles[addrSingle] = o -} - -func canDestroy(parts []string) { - addrObj := toaddr(parts[1]) - addrSingle := toaddr(parts[2]) - o := objs[addrObj] - if o == nil { - report("destroy object without object at 0x%X\n", addrObj) - } - if singles[addrSingle] != o { - report("inconsistency: single 0x%X has different object\n", addrSingle) - } - o.CanDestroy = true -} - -func destroy(parts []string) { - var o *Object - var what string - - ty := parts[1] - addr := toaddr(parts[2]) - if ty == "single" { - o = singles[addr] - delete(singles, addr) - what = "single" - } else { - o = objs[addr] - delete(objs, addr) - what = "object" - } - if o == nil { - report("missing %s %p in destroy()\n", what, addr) - return - } - if !o.CanDestroy { - report("can't destroy %s %p yet\n", what, addr) - } - o.Refs-- - if o.Refs < 0 { - report("not enough references to %p in destroy()\n", addr) - } -} - -func main() { - b := bufio.NewScanner(os.Stdin) - for b.Scan() { - s := b.Text() - parts := strings.Split(s, " ") - name := parts[0] - switch { - case newControls[name] != "": - newControl(parts) - case name == "newSingle": - newSingle(parts) - case name == "uiControlDestroy()": - canDestroy(parts) - case name == "OSdestroy": - destroy(parts) - default: - panic("unknown line " + name) - } - } - if err := b.Err(); err != nil { - panic(err) - } -} diff --git a/test.c b/test.c index 08d77ceb..d5e09362 100644 --- a/test.c +++ b/test.c @@ -196,8 +196,6 @@ 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], "lifetimes") == 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 21b13421..b776531f 100644 --- a/ui.idl +++ b/ui.idl @@ -20,9 +20,6 @@ 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 d4c0b92e..4e25da94 100644 --- a/unix/button.c +++ b/unix/button.c @@ -25,8 +25,6 @@ static void onDestroy(GtkWidget *widget, gpointer data) { struct button *b = (struct button *) data; - if (options.debugLogLifetimes) - fprintf(stderr, "OSdestroy button %p\n", b); uiFree(b); } @@ -57,8 +55,6 @@ 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 f7580e6f..31918dc7 100644 --- a/unix/checkbox.c +++ b/unix/checkbox.c @@ -28,8 +28,6 @@ static void onDestroy(GtkWidget *widget, gpointer data) { struct checkbox *c = (struct checkbox *) data; - if (options.debugLogLifetimes) - fprintf(stderr, "OSdestroy checkbox %p\n", c); uiFree(c); } @@ -81,8 +79,6 @@ 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 665083a6..55f75a5c 100644 --- a/unix/entry.c +++ b/unix/entry.c @@ -11,8 +11,6 @@ static void onDestroy(GtkWidget *widget, gpointer data) { struct entry *e = (struct entry *) data; - if (options.debugLogLifetimes) - fprintf(stderr, "OSdestroy entry %p\n", e); uiFree(e); } @@ -35,8 +33,6 @@ 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 45ef07bb..e1dc03f4 100644 --- a/unix/label.c +++ b/unix/label.c @@ -11,8 +11,6 @@ static void onDestroy(GtkWidget *widget, gpointer data) { struct label *l = (struct label *) data; - if (options.debugLogLifetimes) - fprintf(stderr, "OSdestroy label %p\n", l); uiFree(l); } @@ -36,8 +34,6 @@ 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 a2e55743..d23e1903 100644 --- a/unix/newcontrol.c +++ b/unix/newcontrol.c @@ -18,8 +18,6 @@ static void singleDestroy(uiControl *c) { singleWidget *s = (singleWidget *) (c->Internal); - if (options.debugLogLifetimes) - fprintf(stderr, "uiControlDestroy() %p %p\n", c, s); gtk_widget_destroy(s->immediate); } @@ -163,8 +161,6 @@ static void onDestroy(GtkWidget *widget, gpointer data) { singleWidget *s = (singleWidget *) data; - if (options.debugLogLifetimes) - fprintf(stderr, "OSdestroy single %p\n", s); uiFree(s); } @@ -174,8 +170,6 @@ void uiUnixNewControl(uiControl *c, GType type, gboolean inScrolledWindow, gbool va_list ap; s = uiNew(singleWidget); - if (options.debugLogLifetimes) - fprintf(stderr, "newSingle %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 5d696f1c..5ae6812f 100644 --- a/unix/parent.c +++ b/unix/parent.c @@ -31,8 +31,6 @@ static void uipParent_init(uipParent *p) { if (options.debugLogAllocations) fprintf(stderr, "%p alloc uipParent\n", p); - if (options.debugLogLifetimes) -;//TODO fprintf(stderr, "uipParent_init() %p\n", p); p->children = g_ptr_array_new(); gtk_widget_set_has_window(GTK_WIDGET(p), FALSE); } @@ -43,8 +41,6 @@ static void uipParent_dispose(GObject *obj) { uipParent *p = uipParent(obj); - if (options.debugLogLifetimes) -;//TODO fprintf(stderr, "uipParent_dispose() %p\n", p); if (p->children != NULL) { g_ptr_array_unref(p->children); p->children = NULL; @@ -58,8 +54,6 @@ static void uipParent_dispose(GObject *obj) static void uipParent_finalize(GObject *obj) { - if (options.debugLogLifetimes) -;//TODO fprintf(stderr, "uipParent_finalize() %p\n", obj); G_OBJECT_CLASS(uipParent_parent_class)->finalize(obj); if (options.debugLogAllocations) fprintf(stderr, "%p free\n", obj); @@ -143,8 +137,6 @@ static void parentDestroy(uiParent *pp) { uipParent *p = uipParent(pp->Internal); - if (options.debugLogLifetimes) -;//TODO fprintf(stderr, "uiParentDestroy() %p %p\n", pp, p); gtk_widget_destroy(GTK_WIDGET(p)); } @@ -189,8 +181,6 @@ uiParent *uiNewParent(uintptr_t osParent) p = uiNew(uiParent); p->Internal = g_object_new(uipParentType, NULL); - if (options.debugLogLifetimes) -;//TODO 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 a2666275..ba7bfa37 100644 --- a/unix/tab.c +++ b/unix/tab.c @@ -15,8 +15,6 @@ static void onDestroy(GtkWidget *widget, gpointer data) { struct tab *t = (struct tab *) data; - if (options.debugLogLifetimes) - fprintf(stderr, "OSdestroy tab %p\n", t); uiFree(t->pages); uiFree(t); } @@ -66,9 +64,6 @@ 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,