]> git.neil.brown.name Git - edlib.git/commitdiff
Always handle pane_register failure immediately.
authorNeilBrown <neil@brown.name>
Mon, 3 Jul 2023 22:38:09 +0000 (08:38 +1000)
committerNeilBrown <neil@brown.name>
Wed, 12 Jul 2023 22:17:52 +0000 (08:17 +1000)
Rather then
 p = pane_register();
 if (p)
     ....

Use

 p = pane_register();
 if (!p)
    return FAIL
 ...

Signed-off-by: NeilBrown <neil@brown.name>
14 files changed:
core-doc.c
core-editor.c
core-log.c
doc-dir.c
doc-list.c
doc-multipart.c
doc-text.c
emacs-search.c
lang-python.c
lib-aspell.c
lib-autosave.c
lib-input.c
mode-emacs.c
render-format.c

index 1f5b433d56dda32236ee1f3f0c20610a85df8a2c..c5b89cfad257e4d3574ad16309c4f5f119f6a4a3 100644 (file)
@@ -1355,9 +1355,9 @@ static struct pane *doc_attach_assign(struct pane *parent safe, struct pane *doc
 
        alloc(dd, pane);
        p = pane_register(parent, 0, &doc_handle.c, dd);
-       pane_damaged(p, DAMAGED_VIEW);
        if (!p)
                return NULL;
+       pane_damaged(p, DAMAGED_VIEW);
 
        m = point_new(doc);
        if (!m) {
index 825971d3730c20a9f38c043e2766238ff880c06d..ba87f6762106b30bb6d40acc86ca83a68fd7bb4d 100644 (file)
@@ -676,11 +676,12 @@ struct pane *editor_new(void)
        ei->cmd = ed_handle;
        ei->cmd.m = &ei->map;
        ed = pane_register_root(&ei->cmd.c, ei, sizeof(ei));
+       if (!ed)
+               return NULL;
+
+       doc_setup(ed);
+       log_setup(ed);
+       window_setup(ed);
 
-       if (ed) {
-               doc_setup(ed);
-               log_setup(ed);
-               window_setup(ed);
-       }
        return ed;
 }
index 700ef18e4688dc4df26e043925c01273d6889793..6bc34e18660469a8c2557909af28a36d7bfed11b 100644 (file)
@@ -437,6 +437,9 @@ static void log_init(struct pane *ed safe)
        INIT_LIST_HEAD(&log_doc->log);
        log_pane = doc_register(ed, &log_handle.c, log_doc);
 
+       if (!log_pane)
+               return;
+
        fname = getenv("EDLIB_LOG");
        if (!fname || !*fname)
                return;
index b58c98638fe04236d021f47c503a65786237cc94..04efd4ae7557cf62d4c60ad3045ebdf9ff413dea 100644 (file)
--- a/doc-dir.c
+++ b/doc-dir.c
@@ -198,9 +198,10 @@ DEF_CMD(dir_new)
        INIT_LIST_HEAD(&dr->ents);
        dr->fname = NULL;
        p = doc_register(ci->home, &dir_handle.c, dr);
-       if (p)
-               return comm_call(ci->comm2, "callback:doc", p);
-       return Efail;
+       if (!p)
+               return Efail;
+
+       return comm_call(ci->comm2, "callback:doc", p);
 }
 
 DEF_CMD(dir_new2)
@@ -1218,8 +1219,10 @@ DEF_CMD(dirview_clone)
        struct pane *p;
 
        p = pane_register(ci->focus, 0, &dirview_handle.c);
-       if (p)
-               pane_clone_children(ci->home, p);
+       if (!p)
+               return Efail;
+
+       pane_clone_children(ci->home, p);
        return 1;
 }
 
index 9e836bef06e9a7d266a69e7812a9a557e33862bb..cc28b35e316df6d9a62cce1e198d638d409e777b 100644 (file)
@@ -180,9 +180,10 @@ DEF_CMD(list_new)
        alloc(l, pane);
        INIT_LIST_HEAD(&l->content);
        p = doc_register(ci->home, &list_handle.c, l);
-       if (p)
-               return comm_call(ci->comm2, "callback:doc", p);
-       return Efail;
+       if (!p)
+               return Efail;
+
+       return comm_call(ci->comm2, "callback:doc", p);
 }
 
 static void list_init_map(void)
index 39eeb184d1846bafaa90069517990971a82eb485..040434782836f84f7421b94adf9e066b3e068d8b 100644 (file)
@@ -880,14 +880,14 @@ DEF_CMD(attach_mp)
        alloc(mpi, pane);
 
        h = doc_register(ci->home, &mp_handle.c, mpi);
-       if (h) {
-               mpi->doc.refcnt = mp_mark_refcnt;
-               attr_set_str(&h->attrs, "render-default", "text");
-               return comm_call(ci->comm2, "callback:doc", h);
+       if (!h) {
+               unalloc(mpi, pane);
+               return Efail;
        }
 
-       free(mpi);
-       return Efail;
+       mpi->doc.refcnt = mp_mark_refcnt;
+       attr_set_str(&h->attrs, "render-default", "text");
+       return comm_call(ci->comm2, "callback:doc", h);
 }
 
 void edlib_init(struct pane *ed safe)
index 1af2e3393b724295935f7d34660a4771e0529198..26992502e40edbcc2c1c0e627d7898de7454aae7 100644 (file)
@@ -1818,9 +1818,10 @@ DEF_CMD(text_new)
        t->as.last_change = 0;
        text_new_alloc(t, 0);
        p = doc_register(ci->home, &text_handle.c, t);
-       if (p)
-               return comm_call(ci->comm2, "callback:doc", p);
-       return Efail;
+       if (!p)
+               return Efail;
+
+       return comm_call(ci->comm2, "callback:doc", p);
 }
 
 DEF_CMD(text_new2)
index ba978469d651cc30efe0dca7ce649565ae06bce3..02dcb977e3cd4d683fba3d84844bb25d56359a27 100644 (file)
@@ -711,15 +711,17 @@ DEF_CMD(emacs_search)
        esi->backwards = ci->num & 1;
 
        p = pane_register(ci->focus, 0, &search_handle.c, esi);
-       if (p) {
-               call("doc:request:doc:replaced", p);
-               attr_set_str(&p->attrs, "status-line", " Search: case insensitive ");
-               comm_call(ci->comm2, "callback:attach", p);
-               pane_add_notify(p, esi->target, "Notify:Close");
+       if (!p)
+               return Efail;
+
+       call("doc:request:doc:replaced", p);
+       attr_set_str(&p->attrs, "status-line", " Search: case insensitive ");
+       comm_call(ci->comm2, "callback:attach", p);
+       pane_add_notify(p, esi->target, "Notify:Close");
+
+       if (ci->num & 2)
+               call("K:A-%", p);
 
-               if (ci->num & 2)
-                       call("K:A-%", p);
-       }
        return 1;
 }
 
@@ -1224,11 +1226,13 @@ DEF_CMD(emacs_search_attach_highlight)
 
        alloc(hi, pane);
        p = pane_register(ci->focus, 0, &highlight_handle.c, hi);
-       if (p) {
-               hi->view = home_call(ci->focus, "doc:add-view", p) - 1;
-               hi->replace_view = home_call(ci->focus, "doc:add-view", p) - 1;
-               comm_call(ci->comm2, "callback:attach", p);
-       }
+       if (!p)
+               return Efail;
+
+       hi->view = home_call(ci->focus, "doc:add-view", p) - 1;
+       hi->replace_view = home_call(ci->focus, "doc:add-view", p) - 1;
+       comm_call(ci->comm2, "callback:attach", p);
+
        return 1;
 }
 
index fe309fb69c9968888030adebb5af6c768a0679a0..93236f8a14c364406cf452941af8e04055bc3e6e 100644 (file)
@@ -745,8 +745,10 @@ static int Pane_init(Pane *self safe, PyObject *args, PyObject *kwds)
         */
        Py_INCREF(self);
        self->pane = pane_register(parent->pane, z, &self->cmd, self);
-       if (self->pane)
-               pane_get(self->pane);
+       if (!self->pane)
+               return -1;
+
+       pane_get(self->pane);
        return 0;
 }
 
index 2be4e3dbcf2bb57f73b40b07875f986b05e412b6..8fb4f4b0d97855f8a632fb819f0e561476098f8f 100644 (file)
@@ -57,13 +57,15 @@ DEF_CMD(aspell_attach_helper)
        alloc(as, pane);
        as->speller = safe_cast to_aspell_speller(ret);
        p = pane_register(ci->focus, 0, &aspell_handle.c, as);
-       if (p) {
-               call("doc:request:aspell:check", p);
-               call("doc:request:aspell:suggest", p);
-               call("doc:request:aspell:set-dict", p);
-               call("doc:request:aspell:add-word", p);
-               call("doc:request:aspell:save", p);
-       }
+       if (!p)
+               return Efail;
+
+       call("doc:request:aspell:check", p);
+       call("doc:request:aspell:suggest", p);
+       call("doc:request:aspell:set-dict", p);
+       call("doc:request:aspell:add-word", p);
+       call("doc:request:aspell:save", p);
+
        return 1;
 }
 
index eaef0a9e0f6fb5b4e1f164bffc726b4590ee2652..c02a97890bead9a524c8a969b10bb0af015477a3 100644 (file)
@@ -236,13 +236,14 @@ DEF_CMD(ask_autosave)
                p2 = NULL;
        if (p2)
                p2 = pane_register(p2, 0, &autosave_handle.c);
-       if (p2) {
-               attr_set_str(&p2->attrs, "orig_name", f);
-               attr_set_str(&p2->attrs, "autosave_name", a);
-               attr_set_str(&p2->attrs, "autosave_type", autosave_type);
-               if (doc)
-                       pane_add_notify(p2, doc, "doc:replaced");
-       }
+       if (!p2)
+               return Efail;
+
+       attr_set_str(&p2->attrs, "orig_name", f);
+       attr_set_str(&p2->attrs, "autosave_name", a);
+       attr_set_str(&p2->attrs, "autosave_type", autosave_type);
+       if (doc)
+               pane_add_notify(p2, doc, "doc:replaced");
 
        return 1;
 }
index 3ccbce3dd0d3c0e21b1806c4a58d81c535b8a1f6..f7707cf199fe5857b091f93b6a5cd87e62dbca1b 100644 (file)
@@ -482,9 +482,10 @@ DEF_CMD(input_attach)
        im->num2 = 0;
 
        p = pane_register(ci->focus, 0, &input_handle.c, im);
-       if (p)
-               return comm_call(ci->comm2, "callback:attach", p);
-       return Efail;
+       if (!p)
+               return Efail;
+
+       return comm_call(ci->comm2, "callback:attach", p);
 }
 
 void edlib_init(struct pane *ed safe)
index 65575eda0e63ba4a3ee02984f4049720ca8fb2d5..cac83d70ab5529fa7ed60df2d1299a06c5e7435b 100644 (file)
@@ -1800,7 +1800,9 @@ DEF_CMD(emacs_shell)
                             0, NULL, "popup:close");
                if (p)
                        p = pane_register(p, 0, &find_handle.c, "shellcmd");
-               if (p && ci->comm2)
+               if (!p)
+                       return Efail;
+               if (ci->comm2)
                        comm_call(ci->comm2, "cb", p);
                return 1;
        }
index c2028af97041e142133097ebb53ad8fafce1cd0f..2fde945c2cbf441193cdf1eb4365e200ae3a4680 100644 (file)
@@ -986,7 +986,9 @@ static struct pane *do_render_format_attach(struct pane *parent safe)
 
                alloc(rf, pane);
                p = pane_register(parent, 0, &render_format2_handle.c, rf);
-               if (p && !pane_attr_get(parent, "format:no-linecount")) {
+               if (!p)
+                       return p;
+               if (!pane_attr_get(parent, "format:no-linecount")) {
                        struct pane *p2 = call_ret(pane, "attach-line-count", p);
                        if (p2)
                                p = p2;