aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/vimscript.c
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2023-03-22 10:09:28 +0000
committerGitHub <noreply@github.com>2023-03-22 10:09:28 +0000
commit3285cd6eccd9b7f33cc32f992c2607c3fc4ca13f (patch)
tree4357dab570945b69f7ee3c4406c45c1153222049 /src/nvim/api/vimscript.c
parentc45b5e2c5b0f02742099ebccc44462fe4203e99c (diff)
downloadrneovim-3285cd6eccd9b7f33cc32f992c2607c3fc4ca13f.tar.gz
rneovim-3285cd6eccd9b7f33cc32f992c2607c3fc4ca13f.tar.bz2
rneovim-3285cd6eccd9b7f33cc32f992c2607c3fc4ca13f.zip
refactor: do more in TRY_WRAP
Diffstat (limited to 'src/nvim/api/vimscript.c')
-rw-r--r--src/nvim/api/vimscript.c97
1 files changed, 51 insertions, 46 deletions
diff --git a/src/nvim/api/vimscript.c b/src/nvim/api/vimscript.c
index af1b23b712..32dcbdec3f 100644
--- a/src/nvim/api/vimscript.c
+++ b/src/nvim/api/vimscript.c
@@ -137,35 +137,37 @@ Object nvim_eval(String expr, Error *err)
static int recursive = 0; // recursion depth
Object rv = OBJECT_INIT;
- TRY_WRAP({
- // Initialize `force_abort` and `suppress_errthrow` at the top level.
- if (!recursive) {
- force_abort = false;
- suppress_errthrow = false;
- did_throw = false;
- // `did_emsg` is set by emsg(), which cancels execution.
- did_emsg = false;
- }
- recursive++;
- try_start();
+ // Initialize `force_abort` and `suppress_errthrow` at the top level.
+ if (!recursive) {
+ force_abort = false;
+ suppress_errthrow = false;
+ did_throw = false;
+ // `did_emsg` is set by emsg(), which cancels execution.
+ did_emsg = false;
+ }
- typval_T rettv;
- int ok = eval0(expr.data, &rettv, NULL, true);
+ recursive++;
- if (!try_end(err)) {
- if (ok == FAIL) {
- // Should never happen, try_end() should get the error. #8371
- api_set_error(err, kErrorTypeException,
- "Failed to evaluate expression: '%.*s'", 256, expr.data);
- } else {
- rv = vim_to_object(&rettv);
- }
- }
+ typval_T rettv;
+ int ok;
- tv_clear(&rettv);
- recursive--;
+ TRY_WRAP(err, {
+ ok = eval0(expr.data, &rettv, NULL, true);
});
+ if (!ERROR_SET(err)) {
+ if (ok == FAIL) {
+ // Should never happen, try_end() (in TRY_WRAP) should get the error. #8371
+ api_set_error(err, kErrorTypeException,
+ "Failed to evaluate expression: '%.*s'", 256, expr.data);
+ } else {
+ rv = vim_to_object(&rettv);
+ }
+ }
+
+ tv_clear(&rettv);
+ recursive--;
+
return rv;
}
@@ -196,34 +198,37 @@ static Object _call_function(String fn, Array args, dict_T *self, Error *err)
}
}
- TRY_WRAP({
- // Initialize `force_abort` and `suppress_errthrow` at the top level.
- if (!recursive) {
- force_abort = false;
- suppress_errthrow = false;
- did_throw = false;
- // `did_emsg` is set by emsg(), which cancels execution.
- did_emsg = false;
- }
- recursive++;
- try_start();
- typval_T rettv;
- funcexe_T funcexe = FUNCEXE_INIT;
- funcexe.fe_firstline = curwin->w_cursor.lnum;
- funcexe.fe_lastline = curwin->w_cursor.lnum;
- funcexe.fe_evaluate = true;
- funcexe.fe_selfdict = self;
+ // Initialize `force_abort` and `suppress_errthrow` at the top level.
+ if (!recursive) {
+ force_abort = false;
+ suppress_errthrow = false;
+ did_throw = false;
+ // `did_emsg` is set by emsg(), which cancels execution.
+ did_emsg = false;
+ }
+ recursive++;
+
+ typval_T rettv;
+ funcexe_T funcexe = FUNCEXE_INIT;
+ funcexe.fe_firstline = curwin->w_cursor.lnum;
+ funcexe.fe_lastline = curwin->w_cursor.lnum;
+ funcexe.fe_evaluate = true;
+ funcexe.fe_selfdict = self;
+
+ TRY_WRAP(err, {
// call_func() retval is deceptive, ignore it. Instead we set `msg_list`
// (see above) to capture abort-causing non-exception errors.
(void)call_func(fn.data, (int)fn.size, &rettv, (int)args.size,
vim_args, &funcexe);
- if (!try_end(err)) {
- rv = vim_to_object(&rettv);
- }
- tv_clear(&rettv);
- recursive--;
});
+ if (!ERROR_SET(err)) {
+ rv = vim_to_object(&rettv);
+ }
+
+ tv_clear(&rettv);
+ recursive--;
+
free_vim_args:
while (i > 0) {
tv_clear(&vim_args[--i]);