commit 5ca6cf55f9c772f5c691b08dc49581f27f88e8f9
parent c9b0fe1f41ebaa6815a69ac614a5b2d1bab6f720
Author: glacambre <code@lacamb.re>
Date: Sat, 11 Feb 2023 13:51:33 +0100
fix(helpers): restore channel id after a call to WITH_SCRIPT_CONTEXT
In https://github.com/neovim/neovim/pull/22214, init_default_autocmds
has been turned into a lua function call to nvim_create_augroup and
nvim_create_autocmd.
This introduced a strange regression: a test in vim_spec.lua started
failing with its last_set_chan value switching from 0 to
-9223372036854775808.
It turns out that -9223372036854775808 is the value of LUA_INTERNAL_CALL
and would be inherited as last_set_chan by options set from the command
line due to the WITH_SCRIPT_CONTEXT macro not restoring the channel id
(WITH_SCRIPT_CONTEXT is used by nvim_create_augroup).
Diffstat:
1 file changed, 2 insertions(+), 0 deletions(-)
diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h
@@ -175,11 +175,13 @@ typedef struct {
#define WITH_SCRIPT_CONTEXT(channel_id, code) \
do { \
const sctx_T save_current_sctx = current_sctx; \
+ const uint64_t save_channel_id = current_channel_id; \
current_sctx.sc_sid = \
(channel_id) == LUA_INTERNAL_CALL ? SID_LUA : SID_API_CLIENT; \
current_sctx.sc_lnum = 0; \
current_channel_id = channel_id; \
code; \
+ current_channel_id = save_channel_id; \
current_sctx = save_current_sctx; \
} while (0);