]> git.neil.brown.name Git - edlib.git/commitdiff
libevent: switch to embedded data pattern.
authorNeilBrown <neil@brown.name>
Fri, 8 Sep 2023 07:29:12 +0000 (17:29 +1000)
committerNeilBrown <neil@brown.name>
Fri, 8 Sep 2023 07:29:12 +0000 (17:29 +1000)
Note that previously pane_register was being called with a NULL parent,
though this was hidden from smatch.
This meant that pane_damaged() skipped this event:idle registration.
Fixing that resulted in extreme recursion.  That wasn't really
needed for libevent, so break it.

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

index c39848e27c5a5af90b4e061e35b0355fad324fce..15cb21104e85069d3cd78e09e9a214230c625d30 100644 (file)
@@ -177,8 +177,11 @@ static struct pane *_do_pane_register(struct pane *parent, short z,
                        p->damaged |= DAMAGED_NOINIT;
                        pane_close(p);
                        p = NULL;
-               } else
-                       /* Need to set size of child */
+               } else if (parent && parent != pane_root(parent))
+                       /* Need to set size of child, but not
+                        * if parent is root and that make libevent
+                        * fail to load.
+                        */
                        pane_damaged(parent, DAMAGED_SIZE);
        }
        return p;
index 610376e73e19950107dd9ab22ba6e6fce87ca245..6268f7219f34a467301a616d034b5dbe5d9c2625 100644 (file)
 #include <unistd.h>
 #include <event.h>
 #include <string.h>
+#define PANE_DATA_TYPE struct event_info
 #include "core.h"
 #include "misc.h"
 
-static struct map *libevent_map;
-DEF_LOOKUP_CMD(libevent_handle, libevent_map);
-
 enum {
        EV_LIST,        /* Events handled by libevent */
        POLL_LIST,      /* Events to poll before calling event_base_loop */
@@ -43,6 +41,10 @@ struct event_info {
        struct command read, write, signal, timer, poll, on_idle,
                run, deactivate, free, refresh, noblock;
 };
+#include "core-pane.h"
+
+static struct map *libevent_map;
+DEF_LOOKUP_CMD(libevent_handle, libevent_map);
 
 struct evt {
        struct event *l;
@@ -452,7 +454,11 @@ DEF_CMD(libevent_activate)
        struct pane *p;
        int i;
 
-       alloc(ei, pane);
+       p = pane_register(pane_root(ci->home), 0, &libevent_handle.c);
+       if (!p)
+               return Efail;
+       ei = p->data;
+       ei->home = p;
        for (i = 0; i < NR_LISTS; i++)
                INIT_LIST_HEAD(&ei->event_list[i]);
        ei->read = libevent_read;
@@ -466,10 +472,6 @@ DEF_CMD(libevent_activate)
        ei->free = libevent_free;
        ei->refresh = libevent_refresh;
        ei->noblock = libevent_noblock;
-       p = pane_register(ei->home, 0, &libevent_handle.c, ei);
-       if (!p)
-               return Efail;
-       ei->home = p;
 
        /* These are defaults, so make them sort late */
        call_comm("global-set-command", ci->focus, &ei->read,
@@ -508,5 +510,4 @@ void edlib_init(struct pane *ed safe)
                return;
        libevent_map = key_alloc();
        key_add(libevent_map, "Notify:Close", &libevent_notify);
-       key_add(libevent_map, "Free", &edlib_do_free);
 }