diff options
author | Bram Moolenaar <Bram@vim.org> | 2018-06-12 22:05:14 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2018-06-12 22:05:14 +0200 |
commit | ffa9684150f5441e84d492e7184ef73587bd6c6c (patch) | |
tree | e73aa4b5e0d37ef4d113fcb07f9e1efa5c01d133 /src/eval.c | |
parent | 83f4cbd973731872b633d6ba0caf850fb708d70c (diff) |
patch 8.1.0053: first argument of 'completefunc' has inconsistent typev8.1.0053
Problem: The first argument given to 'completefunc' can be Number or
String, depending on the value.
Solution: Avoid guessing the type of an argument, use typval_T in the
callers of call_vim_function(). (Ozaki Kiichi, closes #2993)
Diffstat (limited to 'src/eval.c')
-rw-r--r-- | src/eval.c | 78 |
1 files changed, 18 insertions, 60 deletions
diff --git a/src/eval.c b/src/eval.c index 2ba9e82a80..26aa0e34e7 100644 --- a/src/eval.c +++ b/src/eval.c @@ -1011,63 +1011,22 @@ eval_expr(char_u *arg, char_u **nextcmd) /* * Call some Vim script function and return the result in "*rettv". - * Uses argv[argc] for the function arguments. Only Number and String - * arguments are currently supported. + * Uses argv[0] to argv[argc - 1] for the function arguments. argv[argc] + * should have type VAR_UNKNOWN. * Returns OK or FAIL. */ int call_vim_function( char_u *func, int argc, - char_u **argv, - int safe, /* use the sandbox */ - int str_arg_only, /* all arguments are strings */ - typval_T *rettv) + typval_T *argv, + typval_T *rettv, + int safe) /* use the sandbox */ { - typval_T *argvars; - varnumber_T n; - int len; - int i; int doesrange; void *save_funccalp = NULL; int ret; - argvars = (typval_T *)alloc((unsigned)((argc + 1) * sizeof(typval_T))); - if (argvars == NULL) - return FAIL; - - for (i = 0; i < argc; i++) - { - /* Pass a NULL or empty argument as an empty string */ - if (argv[i] == NULL || *argv[i] == NUL) - { - argvars[i].v_type = VAR_STRING; - argvars[i].vval.v_string = (char_u *)""; - continue; - } - - if (str_arg_only) - len = 0; - else - { - /* Recognize a number argument, the others must be strings. A dash - * is a string too. */ - vim_str2nr(argv[i], NULL, &len, STR2NR_ALL, &n, NULL, 0); - if (len == 1 && *argv[i] == '-') - len = 0; - } - if (len != 0 && len == (int)STRLEN(argv[i])) - { - argvars[i].v_type = VAR_NUMBER; - argvars[i].vval.v_number = n; - } - else - { - argvars[i].v_type = VAR_STRING; - argvars[i].vval.v_string = argv[i]; - } - } - if (safe) { save_funccalp = save_funccal(); @@ -1075,7 +1034,7 @@ call_vim_function( } rettv->v_type = VAR_UNKNOWN; /* clear_tv() uses this */ - ret = call_func(func, (int)STRLEN(func), rettv, argc, argvars, NULL, + 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) @@ -1083,7 +1042,6 @@ call_vim_function( --sandbox; restore_funccal(save_funccalp); } - vim_free(argvars); if (ret == FAIL) clear_tv(rettv); @@ -1094,20 +1052,20 @@ call_vim_function( /* * Call Vim script function "func" and return the result as a number. * Returns -1 when calling the function fails. - * Uses argv[argc] for the function arguments. + * Uses argv[0] to argv[argc - 1] for the function arguments. argv[argc] should + * have type VAR_UNKNOWN. */ varnumber_T call_func_retnr( char_u *func, int argc, - char_u **argv, + typval_T *argv, int safe) /* use the sandbox */ { typval_T rettv; varnumber_T retval; - /* All arguments are passed as strings, no conversion to number. */ - if (call_vim_function(func, argc, argv, safe, TRUE, &rettv) == FAIL) + if (call_vim_function(func, argc, argv, &rettv, safe) == FAIL) return -1; retval = get_tv_number_chk(&rettv, NULL); @@ -1122,20 +1080,20 @@ call_func_retnr( /* * Call Vim script function "func" and return the result as a string. * Returns NULL when calling the function fails. - * Uses argv[argc] for the function arguments. + * Uses argv[0] to argv[argc - 1] for the function arguments. argv[argc] should + * have type VAR_UNKNOWN. */ void * call_func_retstr( char_u *func, int argc, - char_u **argv, + typval_T *argv, int safe) /* use the sandbox */ { typval_T rettv; char_u *retval; - /* All arguments are passed as strings, no conversion to number. */ - if (call_vim_function(func, argc, argv, safe, TRUE, &rettv) == FAIL) + if (call_vim_function(func, argc, argv, &rettv, safe) == FAIL) return NULL; retval = vim_strsave(get_tv_string(&rettv)); @@ -1146,20 +1104,20 @@ call_func_retstr( /* * Call Vim script function "func" and return the result as a List. - * Uses argv[argc] for the function arguments. + * Uses argv[0] to argv[argc - 1] for the function arguments. argv[argc] should + * have type VAR_UNKNOWN. * Returns NULL when there is something wrong. */ void * call_func_retlist( char_u *func, int argc, - char_u **argv, + typval_T *argv, int safe) /* use the sandbox */ { typval_T rettv; - /* All arguments are passed as strings, no conversion to number. */ - if (call_vim_function(func, argc, argv, safe, TRUE, &rettv) == FAIL) + if (call_vim_function(func, argc, argv, &rettv, safe) == FAIL) return NULL; if (rettv.v_type != VAR_LIST) |