From 94c317647845b92d675548a481f664a6a1808426 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 11 Aug 2022 15:44:55 +0800 Subject: refactor: use CLEAR_FIELD and CLEAR_POINTER macros (#19709) vim-patch:8.2.0559: clearing a struct is verbose Problem: Clearing a struct is verbose. Solution: Define and use CLEAR_FIELD() and CLEAR_POINTER(). https://github.com/vim/vim/commit/a80faa8930ed5a554beeb2727762538873135e83 --- src/nvim/lua/executor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/lua/executor.c') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 661dbfc4c2..c7b654482c 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -447,7 +447,7 @@ static nlua_ref_state_t *nlua_new_ref_state(lua_State *lstate, bool is_thread) FUNC_ATTR_NONNULL_ALL { nlua_ref_state_t *ref_state = lua_newuserdata(lstate, sizeof(*ref_state)); - memset(ref_state, 0, sizeof(*ref_state)); + CLEAR_POINTER(ref_state); ref_state->nil_ref = LUA_NOREF; ref_state->empty_dict_ref = LUA_NOREF; if (!is_thread) { -- cgit From 342d18b91ec176c5e3aa6d32d439d01e6ac88ee6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 12 Aug 2022 21:16:28 +0800 Subject: refactor: remove some unused includes (#19740) Mostly avoids including eval.h, ex_cmds2.h and ex_docmd.h in other headers. --- src/nvim/lua/executor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/lua/executor.c') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index c7b654482c..2ce564c011 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -15,12 +15,12 @@ #include "nvim/buffer_defs.h" #include "nvim/change.h" #include "nvim/cursor.h" +#include "nvim/eval.h" #include "nvim/eval/funcs.h" #include "nvim/eval/typval.h" #include "nvim/eval/userfunc.h" #include "nvim/event/loop.h" #include "nvim/event/time.h" -#include "nvim/ex_cmds2.h" #include "nvim/ex_getln.h" #include "nvim/extmark.h" #include "nvim/func_attr.h" -- cgit From f52c236c5b432629f0e074c3511e7e9d481197b1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 13 Aug 2022 13:48:11 +0800 Subject: vim-patch:8.2.0056: execution stack is incomplete and inefficient Problem: Execution stack is incomplete and inefficient. Solution: Introduce a proper execution stack and use it instead of sourcing_name/sourcing_lnum. Create a string only when used. https://github.com/vim/vim/commit/1a47ae32cdc19b0fd5a82e19fe5fddf45db1a506 Omit test_debugger.vim: superseded by later patches. Omit check_map_keycodes(): N/A. Omit kword_test.c: N/A (converted to a unit test). --- src/nvim/lua/executor.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/lua/executor.c') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 2ce564c011..342b3f6c67 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1313,6 +1313,7 @@ static void nlua_typval_exec(const char *lcmd, size_t lcmd_len, const char *name int nlua_source_using_linegetter(LineGetter fgetline, void *cookie, char *name) { +#if 0 // TODO: const linenr_T save_sourcing_lnum = sourcing_lnum; const sctx_T save_current_sctx = current_sctx; current_sctx.sc_sid = SID_STR; @@ -1336,6 +1337,7 @@ int nlua_source_using_linegetter(LineGetter fgetline, void *cookie, char *name) ga_clear_strings(&ga); xfree(code); return OK; +#endif } /// Call a LuaCallable given some typvals -- cgit From ded2925b406f55223f6093544bc3a38534c1e72e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 13 Aug 2022 16:07:05 +0800 Subject: refactor: change remaining sourcing_name/sourcing_lnum to exestack Co-Authored-By: VVKot --- src/nvim/lua/executor.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/nvim/lua/executor.c') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 342b3f6c67..2e5b411fad 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -37,6 +37,7 @@ #include "nvim/msgpack_rpc/channel.h" #include "nvim/os/os.h" #include "nvim/profile.h" +#include "nvim/runtime.h" #include "nvim/screen.h" #include "nvim/undo.h" #include "nvim/usercmd.h" @@ -1313,13 +1314,11 @@ static void nlua_typval_exec(const char *lcmd, size_t lcmd_len, const char *name int nlua_source_using_linegetter(LineGetter fgetline, void *cookie, char *name) { -#if 0 // TODO: - const linenr_T save_sourcing_lnum = sourcing_lnum; const sctx_T save_current_sctx = current_sctx; current_sctx.sc_sid = SID_STR; current_sctx.sc_seq = 0; current_sctx.sc_lnum = 0; - sourcing_lnum = 0; + estack_push(ETYPE_SCRIPT, NULL, 0); garray_T ga; char_u *line = NULL; @@ -1332,12 +1331,11 @@ int nlua_source_using_linegetter(LineGetter fgetline, void *cookie, char *name) size_t len = strlen(code); nlua_typval_exec(code, len, name, NULL, 0, false, NULL); - sourcing_lnum = save_sourcing_lnum; + estack_pop(); current_sctx = save_current_sctx; ga_clear_strings(&ga); xfree(code); return OK; -#endif } /// Call a LuaCallable given some typvals -- cgit From 9ab9eb1220113d247dd1eb089cb6576a135b8699 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 15 Aug 2022 08:28:20 +0800 Subject: fix(source): make changing 'shellslash' change expand() result --- src/nvim/lua/executor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/lua/executor.c') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 2e5b411fad..a86f23db8e 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1906,7 +1906,7 @@ void nlua_set_sctx(sctx_T *current) break; } char *source_path = fix_fname(info->source + 1); - get_current_script_id((char_u *)source_path, current); + get_current_script_id(&source_path, current); xfree(source_path); current->sc_lnum = info->currentline; current->sc_seq = -1; -- cgit From d1464d16d6897144b29c22f8113aad9b7210e14c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 15 Aug 2022 13:40:01 +0800 Subject: fix(source): fix expand('') no longer works for Lua --- src/nvim/lua/executor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/lua/executor.c') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index a86f23db8e..7cfd666f3e 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1318,7 +1318,7 @@ int nlua_source_using_linegetter(LineGetter fgetline, void *cookie, char *name) current_sctx.sc_sid = SID_STR; current_sctx.sc_seq = 0; current_sctx.sc_lnum = 0; - estack_push(ETYPE_SCRIPT, NULL, 0); + estack_push(ETYPE_SCRIPT, name, 0); garray_T ga; char_u *line = NULL; -- cgit From 51063a90df4cc8af4e1111dd50194ae487e8097e Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 16 Aug 2022 12:27:07 +0100 Subject: vim-patch:8.1.2057: the screen.c file is much too big Problem: The screen.c file is much too big. Solution: Split it in three parts. (Yegappan Lakshmanan, closes vim/vim#4943) https://github.com/vim/vim/commit/7528d1f6b5422750eb778dfb550cfd0b0e540964 This is an approximation vim-patch 8.1.2057. Applying the patch directly isn't feasible since our version of screen.c has diverged too much, however we still introduce drawscreen.c and drawline.c: - screen.c is now a much smaller file used for low level screen functions - drawline.c contains everything needed for win_line() - drawscreen.c contains everything needed for update_screen() Co-authored-by: zeertzjq --- src/nvim/lua/executor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/lua/executor.c') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 7cfd666f3e..5d97f90bb1 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -15,6 +15,7 @@ #include "nvim/buffer_defs.h" #include "nvim/change.h" #include "nvim/cursor.h" +#include "nvim/drawscreen.h" #include "nvim/eval.h" #include "nvim/eval/funcs.h" #include "nvim/eval/typval.h" @@ -38,7 +39,6 @@ #include "nvim/os/os.h" #include "nvim/profile.h" #include "nvim/runtime.h" -#include "nvim/screen.h" #include "nvim/undo.h" #include "nvim/usercmd.h" #include "nvim/version.h" -- cgit From 0d0a336c5348c653376766d90a86f187167ae5c5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 21 Aug 2022 06:33:24 +0800 Subject: vim-patch:8.1.1886: command line expansion code is spread out (#19861) Problem: Command line expansion code is spread out. Solution: Move the code to cmdexpand.c. (Yegappan Lakshmanan, closes vim/vim#4831) https://github.com/vim/vim/commit/66b51420e0c8d49bcf6786b792c938d6099e3393 --- src/nvim/lua/executor.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/lua/executor.c') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 5d97f90bb1..38c19ed456 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -22,6 +22,7 @@ #include "nvim/eval/userfunc.h" #include "nvim/event/loop.h" #include "nvim/event/time.h" +#include "nvim/ex_cmds.h" #include "nvim/ex_getln.h" #include "nvim/extmark.h" #include "nvim/func_attr.h" -- cgit From dde90f0ca4e394667afe39c18f4a4dabdd8a6666 Mon Sep 17 00:00:00 2001 From: Javier Lopez Date: Sun, 21 Aug 2022 08:19:29 -0500 Subject: fix(api/command): fargs behavior when no arguments are passed (#19862) Problem: A command defined with `nargs="?"` returns `fargs={""}` to a Lua callback when executed with no arguments, which is inconsistent with how`nargs="*"` behaves. Solution: Pass `fargs={}` for no argument with `nargs="?"` as well. --- src/nvim/lua/executor.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/nvim/lua/executor.c') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 38c19ed456..d1d1480696 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1940,8 +1940,13 @@ int nlua_do_ucmd(ucmd_T *cmd, exarg_T *eap, bool preview) // Split args by unescaped whitespace || (nargs dependent) if (cmd->uc_argt & EX_NOSPC) { - // Commands where nargs = 1 or "?" fargs is the same as args - lua_rawseti(lstate, -2, 1); + if ((cmd->uc_argt & EX_NEEDARG) || STRLEN(eap->arg)) { + // For commands where nargs is 1 or "?" and argument is passed, fargs = { args } + lua_rawseti(lstate, -2, 1); + } else { + // if nargs = "?" and no argument is passed, fargs = {} + lua_pop(lstate, 1); // Pop the reference of opts.args + } } else if (eap->args == NULL) { // For commands with more than one possible argument, split if argument list isn't available. lua_pop(lstate, 1); // Pop the reference of opts.args -- cgit From 6cc6e11929ad76a2dc5204aed95cb9ed1dafde23 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 23 Aug 2022 22:00:19 +0800 Subject: vim-patch:9.0.0206: redraw flags are not named specifically (#19913) Problem: Redraw flags are not named specifically. Solution: Prefix "UPD_" to the flags, for UPDate_screen(). https://github.com/vim/vim/commit/a4d158b3c839e96ed98ff87c7b7124ff4518c4ff --- src/nvim/lua/executor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/lua/executor.c') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index d1d1480696..bc8d5a3577 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1578,7 +1578,7 @@ void ex_luado(exarg_T *const eap) } lua_pop(lstate, 1); check_cursor(); - update_screen(NOT_VALID); + update_screen(UPD_NOT_VALID); } /// Run lua file -- cgit From bcf5ee328e228d5a536b4de2069a79234f9f3e9e Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 23 Aug 2022 10:36:46 +0200 Subject: refactor(arena): use a shared block freelist This is both simpler in client code and more effective (always reuse block hottest in cache) --- src/nvim/lua/executor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/lua/executor.c') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index d1d1480696..8316ab3bd1 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1093,7 +1093,7 @@ static int nlua_rpc(lua_State *lstate, bool request) Object result = rpc_send_call(chan_id, name, args, &res_mem, &err); if (!ERROR_SET(&err)) { nlua_push_Object(lstate, result, false); - arena_mem_free(res_mem, NULL); + arena_mem_free(res_mem); } } else { if (!rpc_send_event(chan_id, name, args)) { -- cgit From 26ebf67c39d3776095706fafe34eea2e37013579 Mon Sep 17 00:00:00 2001 From: Thomas Vigouroux Date: Wed, 24 Aug 2022 16:22:50 +0200 Subject: test(treesitter): make internal lang test pending when necessary --- src/nvim/lua/executor.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/lua/executor.c') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 8cd0e9937b..38bc187f4f 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1662,6 +1662,9 @@ static void nlua_add_treesitter(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL lua_pushcfunction(lstate, tslua_has_language); lua_setfield(lstate, -2, "_ts_has_language"); + lua_pushcfunction(lstate, tslua_remove_lang); + lua_setfield(lstate, -2, "_ts_remove_language"); + lua_pushcfunction(lstate, tslua_inspect_lang); lua_setfield(lstate, -2, "_ts_inspect_language"); -- cgit From 40855b0143a864739a6037921e15699445dcf8a7 Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Sun, 31 Jul 2022 16:20:57 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/lua/executor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/lua/executor.c') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 38bc187f4f..39585ac182 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -990,7 +990,7 @@ int nlua_in_fast_event(lua_State *lstate) static bool viml_func_is_fast(const char *name) { - const EvalFuncDef *const fdef = find_internal_func((const char *)name); + const EvalFuncDef *const fdef = find_internal_func(name); if (fdef) { return fdef->fast; } -- cgit From 813476bf7291dfaf9fc0ef77c9f53a07258a3801 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Tue, 30 Aug 2022 23:13:52 +0100 Subject: fix(exceptions): restore `did_throw` (#20000) `!did_throw` doesn't exactly imply `!current_exception`, as `did_throw = false` is sometimes used to defer exception handling for later (without forgetting the exception). E.g: uncaught exception handling in `do_cmdline()` may be deferred to a different call (e.g: when `try_level > 0`). In #7881, `current_exception = NULL` in `do_cmdline()` is used as an analogue of `did_throw = false`, but also causes the pending exception to be lost, which also leaks as `discard_exception()` wasn't used. It may be possible to fix this by saving/restoring `current_exception`, but handling all of `did_throw`'s edge cases seems messier. Maybe not worth diverging over. This fix also uncovers a `man_spec.lua` bug on Windows: exceptions are thrown due to Windows missing `man`, but they're lost; skip these tests if `man` isn't executable. --- src/nvim/lua/executor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/lua/executor.c') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 39585ac182..42aa13cfc1 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1027,7 +1027,7 @@ int nlua_call(lua_State *lstate) // TODO(bfredl): this should be simplified in error handling refactor force_abort = false; suppress_errthrow = false; - current_exception = NULL; + did_throw = false; did_emsg = false; try_start(); -- cgit