From ad4ea182c4aed4f58cb422c042317c81eebe49ff Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Fri, 8 Sep 2023 17:29:12 +1000 Subject: [PATCH] libevent: switch to embedded data pattern. 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 --- core-pane.c | 7 +++++-- lib-libevent.c | 19 ++++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/core-pane.c b/core-pane.c index c39848e2..15cb2110 100644 --- a/core-pane.c +++ b/core-pane.c @@ -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; diff --git a/lib-libevent.c b/lib-libevent.c index 610376e7..6268f721 100644 --- a/lib-libevent.c +++ b/lib-libevent.c @@ -19,12 +19,10 @@ #include #include #include +#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); } -- 2.39.5