aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval.c
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2019-08-30 07:42:57 +0200
committerGitHub <noreply@github.com>2019-08-30 07:42:57 +0200
commit56e570f8af263aeefe2b6dc121c4a88c347a6e9c (patch)
tree1d6840820ff7a9ef9b6bc5f31705c7025eae5b30 /src/nvim/eval.c
parent7732976918d34d34d8fdb9c9829032cb43062740 (diff)
parent97c1775646b87e7127a93daa13aab3d09e8e4b88 (diff)
downloadrneovim-56e570f8af263aeefe2b6dc121c4a88c347a6e9c.tar.gz
rneovim-56e570f8af263aeefe2b6dc121c4a88c347a6e9c.tar.bz2
rneovim-56e570f8af263aeefe2b6dc121c4a88c347a6e9c.zip
Merge #10886 from janlazo/vim-8.1.1938
vim-patch:8.1.{233,1938}
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r--src/nvim/eval.c49
1 files changed, 17 insertions, 32 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index d883b53ed2..12c53fa804 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -1307,27 +1307,17 @@ int call_vim_function(
const char_u *func,
int argc,
typval_T *argv,
- typval_T *rettv,
- bool safe // use the sandbox
+ typval_T *rettv
)
+ FUNC_ATTR_NONNULL_ALL
{
int doesrange;
- void *save_funccalp = NULL;
int ret;
- if (safe) {
- save_funccalp = save_funccal();
- ++sandbox;
- }
-
rettv->v_type = VAR_UNKNOWN; // tv_clear() uses this.
ret = call_func(func, (int)STRLEN(func), rettv, argc, argv, NULL,
curwin->w_cursor.lnum, curwin->w_cursor.lnum,
&doesrange, true, NULL, NULL);
- if (safe) {
- --sandbox;
- restore_funccal(save_funccalp);
- }
if (ret == FAIL) {
tv_clear(rettv);
@@ -1340,16 +1330,16 @@ int call_vim_function(
/// @param[in] func Function name.
/// @param[in] argc Number of arguments.
/// @param[in] argv Array with typval_T arguments.
-/// @param[in] safe Use with sandbox.
///
/// @return -1 when calling function fails, result of function otherwise.
-varnumber_T call_func_retnr(char_u *func, int argc,
- typval_T *argv, int safe)
+varnumber_T call_func_retnr(const char_u *func, int argc,
+ typval_T *argv)
+ FUNC_ATTR_NONNULL_ALL
{
typval_T rettv;
varnumber_T retval;
- if (call_vim_function(func, argc, argv, &rettv, safe) == FAIL) {
+ if (call_vim_function(func, argc, argv, &rettv) == FAIL) {
return -1;
}
retval = tv_get_number_chk(&rettv, NULL);
@@ -1361,18 +1351,16 @@ varnumber_T call_func_retnr(char_u *func, int argc,
/// @param[in] func Function name.
/// @param[in] argc Number of arguments.
/// @param[in] argv Array with typval_T arguments.
-/// @param[in] safe Use the sandbox.
///
/// @return [allocated] NULL when calling function fails, allocated string
/// otherwise.
char *call_func_retstr(const char *const func, int argc,
- typval_T *argv,
- bool safe)
- FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_MALLOC
+ typval_T *argv)
+ FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_MALLOC
{
typval_T rettv;
// All arguments are passed as strings, no conversion to number.
- if (call_vim_function((const char_u *)func, argc, argv, &rettv, safe)
+ if (call_vim_function((const char_u *)func, argc, argv, &rettv)
== FAIL) {
return NULL;
}
@@ -1386,17 +1374,16 @@ char *call_func_retstr(const char *const func, int argc,
/// @param[in] func Function name.
/// @param[in] argc Number of arguments.
/// @param[in] argv Array with typval_T arguments.
-/// @param[in] safe Use the sandbox.
///
/// @return [allocated] NULL when calling function fails or return tv is not a
/// List, allocated List otherwise.
-void *call_func_retlist(char_u *func, int argc, typval_T *argv,
- bool safe)
+void *call_func_retlist(const char_u *func, int argc, typval_T *argv)
+ FUNC_ATTR_NONNULL_ALL
{
typval_T rettv;
// All arguments are passed as strings, no conversion to number.
- if (call_vim_function(func, argc, argv, &rettv, safe) == FAIL) {
+ if (call_vim_function(func, argc, argv, &rettv) == FAIL) {
return NULL;
}
@@ -6437,6 +6424,10 @@ call_func(
typval_T argv[MAX_FUNC_ARGS + 1]; // used when "partial" is not NULL
int argv_clear = 0;
+ // Initialize rettv so that it is safe for caller to invoke clear_tv(rettv)
+ // even when call_func() returns FAIL.
+ rettv->v_type = VAR_UNKNOWN;
+
// Make a copy of the name, if it comes from a funcref variable it could
// be changed or deleted in the called function.
name = vim_strnsave(funcname, len);
@@ -6465,13 +6456,7 @@ call_func(
}
}
-
- // Execute the function if executing and no errors were detected.
- if (!evaluate) {
- // Not evaluating, which means the return value is unknown. This
- // matters for giving error messages.
- rettv->v_type = VAR_UNKNOWN;
- } else if (error == ERROR_NONE) {
+ if (error == ERROR_NONE && evaluate) {
char_u *rfname = fname;
/* Ignore "g:" before a function name. */