Mercurial > vim
diff src/eval.c @ 14071:c1fcfafa8d1a v8.1.0053
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
commit https://github.com/vim/vim/commit/ffa9684150f5441e84d492e7184ef73587bd6c6c
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jun 12 22:05:14 2018 +0200
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
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)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 12 Jun 2018 22:15:06 +0200 |
parents | e4d5726e1678 |
children | f8280e1bfc84 |
line wrap: on
line diff
--- 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 *argvars; - varnumber_T n; - int len; - int i; + typval_T *argv, + typval_T *rettv, + int safe) /* use the sandbox */ +{ 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)