]> git.neil.brown.name Git - edlib.git/commitdiff
Introduce Close:Notify
authorNeilBrown <neil@brown.name>
Sat, 9 Sep 2023 00:07:16 +0000 (10:07 +1000)
committerNeilBrown <neil@brown.name>
Sat, 9 Sep 2023 00:07:16 +0000 (10:07 +1000)
Close:Notify is like Notify:Close, but can be called even after the home
pane has DAMAGED_CLOSED.  Functions that respond to this must be careful
to not trust anything that "Close" might have freed.

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

index f11ac966f38876a2f7089cb132f917be91de2b22..645d2825f831f2d21d5ace450dc3157489a90b73 100644 (file)
@@ -731,7 +731,10 @@ DEF_CMD(doc_addview)
        if (d->views /* FIXME always true */) {
                points_attach(d, ret);
                d->views[ret].owner = ci->focus;
-               pane_add_notify(ci->home, ci->focus, "Notify:Close");
+               /* Use Close:Notify because we need this even
+                * when the pane is closing
+                */
+               pane_add_notify(ci->home, ci->focus, "Close:Notify");
        }
        return 1 + ret;
 }
@@ -1330,7 +1333,7 @@ static void init_doc_cmds(void)
 
        key_add(doc_default_cmd, "doc:add-view", &doc_addview);
        key_add(doc_default_cmd, "doc:del-view", &doc_delview);
-       key_add(doc_default_cmd, "Notify:Close", &doc_view_close);
+       key_add(doc_default_cmd, "Close:Notify", &doc_view_close);
        key_add(doc_default_cmd, "doc:vmark-get", &doc_vmarkget);
        key_add(doc_default_cmd, "doc:vmark-prev", &doc_vmarkprev);
        key_add(doc_default_cmd, "doc:vmark-new", &doc_vmarknew);
index 8026b88d515b1b2724ae9ec126eabc6388c148e0..1ba2bf1480f43669fa6a8364be6c12f0445c1912 100644 (file)
@@ -485,6 +485,11 @@ static void pane_notify_close(struct pane *p safe)
                list_del_init(&n->notifier_link);
                if (strcmp(n->notification, "Notify:Close") == 0)
                        pane_call(n->notifiee, n->notification, p);
+               /* Close:Notify can be delivered even to DAMAGED_CLOSED
+                * panes
+                */
+               if (strcmp(n->notification, "Close:Notify") == 0)
+                       pane_call(n->notifiee, n->notification, p);
                free(n->notification);
                free(n);
        }
index ca24b0d90beda3cc66d7ced6a44b28775bdab965..6bdaead030e427da1881a0606daccc4518f03c7d 100644 (file)
@@ -132,10 +132,12 @@ static inline int do_call_val(enum target_type type, struct pane *home,
                if (home)
                        ci.home = home;
                if ((home->damaged & DAMAGED_CLOSED) &&
-                   strncmp(ci.key, "Close", 5) != 0 &&
-                   strcmp(ci.key, "Notify:Close") != 0)
+                   ci.key[0] != 'C' && /* Compile will often optimise
+                                        * the strncmp away
+                                        */
+                   strncmp(ci.key, "Close", 5) != 0)
                        /* This pane cannot accept anything but
-                        * "Close" or "Close:mark" or "Notify:Close"
+                        * "Close" or "Close:mark" or "Close:Notify"
                         */
                        return Efail;
                ci.comm = home->handle;