]> git.neil.brown.name Git - edlib.git/commitdiff
doc_close_views mustn't close newly added views.
authorNeilBrown <neil@brown.name>
Sun, 22 Nov 2015 05:08:20 +0000 (16:08 +1100)
committerNeilBrown <neil@brown.name>
Sun, 22 Nov 2015 05:08:20 +0000 (16:08 +1100)
It is possible for a view to be added while others
are deleted.  This happens when a view loses it's doc
and adds another and only finds the one it lost.

So use a mark/sweep still approach to only delete pre-existing views.

Signed-off-by: NeilBrown <neil@brown.name>
core-doc.c
core.h

index 49eaa1cc6222c1afb1e3bfb29235a96c1877e8c1..98a382482575fe718fd9d507c5e5ae842e3451a1 100644 (file)
@@ -48,11 +48,13 @@ int doc_add_view(struct doc *d, struct command *c)
                        tlist_del(&d->views[i].head);
                        g[i].notify = d->views[i].notify;
                        g[i].space = d->views[i].space;
+                       g[i].marked = d->views[i].marked;
                }
                for (; i < d->nviews; i++) {
                        INIT_TLIST_HEAD(&g[i].head, GRP_HEAD);
                        g[i].notify = NULL;
                        g[i].space = 0;
+                       g[i].marked = 0;
                }
                free(d->views);
                d->views = g;
@@ -62,6 +64,7 @@ int doc_add_view(struct doc *d, struct command *c)
        points_attach(d, ret);
        d->views[ret].space = 0;
        d->views[ret].notify = c;
+       d->views[ret].marked = 0;
        return ret;
 }
 
@@ -99,10 +102,18 @@ static void doc_close_views(struct doc *d)
        struct cmd_info ci;
        int i;
 
+       for (i = 0; i < d->nviews; i++)
+               if (d->views[i].notify)
+                       d->views[i].marked = 1;
+               else
+                       d->views[i].marked = 0;
        ci.key = "Release";
        for (i = 0; i < d->nviews; i++) {
                struct point pt, *ptp = &pt;
                struct command *c;
+               if (!d->views[i].marked)
+                       /* Don't delete newly added views */
+                       continue;
                if (d->views[i].notify == NULL)
                        continue;
                ci.pointp = &ptp;
diff --git a/core.h b/core.h
index 8702827482249410d41b38f099d7c271e4cee11a..7620a88e32163ad1042682e4fa1abab26a748b39 100644 (file)
--- a/core.h
+++ b/core.h
@@ -69,7 +69,8 @@ struct doc {
        struct docview {
                struct tlist_head head;
                struct command    *notify;
-               int             space;  /* extra space to allocate after a mark */
+               short           space;  /* extra space to allocate after a mark */
+               short           marked; /* being deleted */
        } *views;
        struct attrset          *attrs;
        int                     nviews;