diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-11-17 18:34:48 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-17 18:34:48 +0800 |
commit | 20ec4c776a07492c2e3b995e10b40b1cdb52bc7a (patch) | |
tree | fae077048255d77f1768a51e0276ff3daee4373e | |
parent | dc9f7b814517045b5354364655f660aae0989710 (diff) | |
download | rneovim-20ec4c776a07492c2e3b995e10b40b1cdb52bc7a.tar.gz rneovim-20ec4c776a07492c2e3b995e10b40b1cdb52bc7a.tar.bz2 rneovim-20ec4c776a07492c2e3b995e10b40b1cdb52bc7a.zip |
fix(lua): only disable vim.schedule() when closing main loop (#26090)
-rw-r--r-- | src/nvim/event/loop.c | 2 | ||||
-rw-r--r-- | src/nvim/event/loop.h | 1 | ||||
-rw-r--r-- | src/nvim/lua/executor.c | 12 |
3 files changed, 9 insertions, 6 deletions
diff --git a/src/nvim/event/loop.c b/src/nvim/event/loop.c index 3d74fe7d6d..d61666e6d4 100644 --- a/src/nvim/event/loop.c +++ b/src/nvim/event/loop.c @@ -17,6 +17,7 @@ void loop_init(Loop *loop, void *data) { uv_loop_init(&loop->uv); loop->recursive = 0; + loop->closing = false; loop->uv.data = loop; loop->children = kl_init(WatcherPtr); loop->events = multiqueue_new_parent(loop_on_put, loop); @@ -149,6 +150,7 @@ static void loop_walk_cb(uv_handle_t *handle, void *arg) bool loop_close(Loop *loop, bool wait) { bool rv = true; + loop->closing = true; uv_mutex_destroy(&loop->mutex); uv_close((uv_handle_t *)&loop->children_watcher, NULL); uv_close((uv_handle_t *)&loop->children_kill_timer, NULL); diff --git a/src/nvim/event/loop.h b/src/nvim/event/loop.h index 58216f7ec3..977ed8a1ee 100644 --- a/src/nvim/event/loop.h +++ b/src/nvim/event/loop.h @@ -40,6 +40,7 @@ typedef struct loop { uv_async_t async; uv_mutex_t mutex; int recursive; + bool closing; ///< Set to true if loop_close() has been called } Loop; #define CREATE_EVENT(multiqueue, handler, argc, ...) \ diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index aed96a539a..12304b6f11 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -366,17 +366,17 @@ static void nlua_schedule_event(void **argv) static int nlua_schedule(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL { - // If Nvim is exiting don't schedule tasks to run in the future. Any refs - // allocated here will not be cleaned up otherwise - if (exiting) { - return 0; - } - if (lua_type(lstate, 1) != LUA_TFUNCTION) { lua_pushliteral(lstate, "vim.schedule: expected function"); return lua_error(lstate); } + // If main_loop is closing don't schedule tasks to run in the future, + // otherwise any refs allocated here will not be cleaned up. + if (main_loop.closing) { + return 0; + } + LuaRef cb = nlua_ref_global(lstate, 1); multiqueue_put(main_loop.events, nlua_schedule_event, |