aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/lua/stdlib.c
diff options
context:
space:
mode:
authorluukvbaal <luukvbaal@gmail.com>2024-12-17 13:12:22 +0100
committerGitHub <noreply@github.com>2024-12-17 04:12:22 -0800
commit6bf2a6fc5bb395b67c88cb26d332f882a106c7ab (patch)
tree44259c3b4df40c5af3a4bacec308945f93365d6e /src/nvim/lua/stdlib.c
parentb03e790cddd19b57fa91f4fbfcc30c28f3c173bf (diff)
downloadrneovim-6bf2a6fc5bb395b67c88cb26d332f882a106c7ab.tar.gz
rneovim-6bf2a6fc5bb395b67c88cb26d332f882a106c7ab.tar.bz2
rneovim-6bf2a6fc5bb395b67c88cb26d332f882a106c7ab.zip
refactor(api): always use TRY_WRAP #31600
Problem: Two separate try/end wrappers, that only marginally differ by restoring a few variables. Wrappers that don't restore previous state are dangerous to use in "api-fast" functions. Solution: Remove wrappers that don't restore the previous state. Always use TRY_WRAP.
Diffstat (limited to 'src/nvim/lua/stdlib.c')
-rw-r--r--src/nvim/lua/stdlib.c48
1 files changed, 21 insertions, 27 deletions
diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c
index 5ebff3a809..4de25f4265 100644
--- a/src/nvim/lua/stdlib.c
+++ b/src/nvim/lua/stdlib.c
@@ -623,38 +623,32 @@ static int nlua_with(lua_State *L)
cmdmod.cmod_flags = flags;
apply_cmdmod(&cmdmod);
- if (buf || win) {
- try_start();
- }
-
- aco_save_T aco;
- win_execute_T win_execute_args;
Error err = ERROR_INIT;
+ TRY_WRAP(&err, {
+ aco_save_T aco;
+ win_execute_T win_execute_args;
- if (win) {
- tabpage_T *tabpage = win_find_tabpage(win);
- if (!win_execute_before(&win_execute_args, win, tabpage)) {
- goto end;
+ if (win) {
+ tabpage_T *tabpage = win_find_tabpage(win);
+ if (!win_execute_before(&win_execute_args, win, tabpage)) {
+ goto end;
+ }
+ } else if (buf) {
+ aucmd_prepbuf(&aco, buf);
}
- } else if (buf) {
- aucmd_prepbuf(&aco, buf);
- }
- int s = lua_gettop(L);
- lua_pushvalue(L, 2);
- status = lua_pcall(L, 0, LUA_MULTRET, 0);
- rets = lua_gettop(L) - s;
+ int s = lua_gettop(L);
+ lua_pushvalue(L, 2);
+ status = lua_pcall(L, 0, LUA_MULTRET, 0);
+ rets = lua_gettop(L) - s;
- if (win) {
- win_execute_after(&win_execute_args);
- } else if (buf) {
- aucmd_restbuf(&aco);
- }
-
-end:
- if (buf || win) {
- try_end(&err);
- }
+ if (win) {
+ win_execute_after(&win_execute_args);
+ } else if (buf) {
+ aucmd_restbuf(&aco);
+ }
+ end:;
+ });
undo_cmdmod(&cmdmod);
cmdmod = save_cmdmod;