Mercurial > vim
comparison 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 |
comparison
equal
deleted
inserted
replaced
14070:e5b1d05b7b77 | 14071:c1fcfafa8d1a |
---|---|
1009 } | 1009 } |
1010 | 1010 |
1011 | 1011 |
1012 /* | 1012 /* |
1013 * Call some Vim script function and return the result in "*rettv". | 1013 * Call some Vim script function and return the result in "*rettv". |
1014 * Uses argv[argc] for the function arguments. Only Number and String | 1014 * Uses argv[0] to argv[argc - 1] for the function arguments. argv[argc] |
1015 * arguments are currently supported. | 1015 * should have type VAR_UNKNOWN. |
1016 * Returns OK or FAIL. | 1016 * Returns OK or FAIL. |
1017 */ | 1017 */ |
1018 int | 1018 int |
1019 call_vim_function( | 1019 call_vim_function( |
1020 char_u *func, | 1020 char_u *func, |
1021 int argc, | 1021 int argc, |
1022 char_u **argv, | 1022 typval_T *argv, |
1023 int safe, /* use the sandbox */ | 1023 typval_T *rettv, |
1024 int str_arg_only, /* all arguments are strings */ | 1024 int safe) /* use the sandbox */ |
1025 typval_T *rettv) | 1025 { |
1026 { | |
1027 typval_T *argvars; | |
1028 varnumber_T n; | |
1029 int len; | |
1030 int i; | |
1031 int doesrange; | 1026 int doesrange; |
1032 void *save_funccalp = NULL; | 1027 void *save_funccalp = NULL; |
1033 int ret; | 1028 int ret; |
1034 | 1029 |
1035 argvars = (typval_T *)alloc((unsigned)((argc + 1) * sizeof(typval_T))); | |
1036 if (argvars == NULL) | |
1037 return FAIL; | |
1038 | |
1039 for (i = 0; i < argc; i++) | |
1040 { | |
1041 /* Pass a NULL or empty argument as an empty string */ | |
1042 if (argv[i] == NULL || *argv[i] == NUL) | |
1043 { | |
1044 argvars[i].v_type = VAR_STRING; | |
1045 argvars[i].vval.v_string = (char_u *)""; | |
1046 continue; | |
1047 } | |
1048 | |
1049 if (str_arg_only) | |
1050 len = 0; | |
1051 else | |
1052 { | |
1053 /* Recognize a number argument, the others must be strings. A dash | |
1054 * is a string too. */ | |
1055 vim_str2nr(argv[i], NULL, &len, STR2NR_ALL, &n, NULL, 0); | |
1056 if (len == 1 && *argv[i] == '-') | |
1057 len = 0; | |
1058 } | |
1059 if (len != 0 && len == (int)STRLEN(argv[i])) | |
1060 { | |
1061 argvars[i].v_type = VAR_NUMBER; | |
1062 argvars[i].vval.v_number = n; | |
1063 } | |
1064 else | |
1065 { | |
1066 argvars[i].v_type = VAR_STRING; | |
1067 argvars[i].vval.v_string = argv[i]; | |
1068 } | |
1069 } | |
1070 | |
1071 if (safe) | 1030 if (safe) |
1072 { | 1031 { |
1073 save_funccalp = save_funccal(); | 1032 save_funccalp = save_funccal(); |
1074 ++sandbox; | 1033 ++sandbox; |
1075 } | 1034 } |
1076 | 1035 |
1077 rettv->v_type = VAR_UNKNOWN; /* clear_tv() uses this */ | 1036 rettv->v_type = VAR_UNKNOWN; /* clear_tv() uses this */ |
1078 ret = call_func(func, (int)STRLEN(func), rettv, argc, argvars, NULL, | 1037 ret = call_func(func, (int)STRLEN(func), rettv, argc, argv, NULL, |
1079 curwin->w_cursor.lnum, curwin->w_cursor.lnum, | 1038 curwin->w_cursor.lnum, curwin->w_cursor.lnum, |
1080 &doesrange, TRUE, NULL, NULL); | 1039 &doesrange, TRUE, NULL, NULL); |
1081 if (safe) | 1040 if (safe) |
1082 { | 1041 { |
1083 --sandbox; | 1042 --sandbox; |
1084 restore_funccal(save_funccalp); | 1043 restore_funccal(save_funccalp); |
1085 } | 1044 } |
1086 vim_free(argvars); | |
1087 | 1045 |
1088 if (ret == FAIL) | 1046 if (ret == FAIL) |
1089 clear_tv(rettv); | 1047 clear_tv(rettv); |
1090 | 1048 |
1091 return ret; | 1049 return ret; |
1092 } | 1050 } |
1093 | 1051 |
1094 /* | 1052 /* |
1095 * Call Vim script function "func" and return the result as a number. | 1053 * Call Vim script function "func" and return the result as a number. |
1096 * Returns -1 when calling the function fails. | 1054 * Returns -1 when calling the function fails. |
1097 * Uses argv[argc] for the function arguments. | 1055 * Uses argv[0] to argv[argc - 1] for the function arguments. argv[argc] should |
1056 * have type VAR_UNKNOWN. | |
1098 */ | 1057 */ |
1099 varnumber_T | 1058 varnumber_T |
1100 call_func_retnr( | 1059 call_func_retnr( |
1101 char_u *func, | 1060 char_u *func, |
1102 int argc, | 1061 int argc, |
1103 char_u **argv, | 1062 typval_T *argv, |
1104 int safe) /* use the sandbox */ | 1063 int safe) /* use the sandbox */ |
1105 { | 1064 { |
1106 typval_T rettv; | 1065 typval_T rettv; |
1107 varnumber_T retval; | 1066 varnumber_T retval; |
1108 | 1067 |
1109 /* All arguments are passed as strings, no conversion to number. */ | 1068 if (call_vim_function(func, argc, argv, &rettv, safe) == FAIL) |
1110 if (call_vim_function(func, argc, argv, safe, TRUE, &rettv) == FAIL) | |
1111 return -1; | 1069 return -1; |
1112 | 1070 |
1113 retval = get_tv_number_chk(&rettv, NULL); | 1071 retval = get_tv_number_chk(&rettv, NULL); |
1114 clear_tv(&rettv); | 1072 clear_tv(&rettv); |
1115 return retval; | 1073 return retval; |
1120 | 1078 |
1121 # if (defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL)) || defined(PROTO) | 1079 # if (defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL)) || defined(PROTO) |
1122 /* | 1080 /* |
1123 * Call Vim script function "func" and return the result as a string. | 1081 * Call Vim script function "func" and return the result as a string. |
1124 * Returns NULL when calling the function fails. | 1082 * Returns NULL when calling the function fails. |
1125 * Uses argv[argc] for the function arguments. | 1083 * Uses argv[0] to argv[argc - 1] for the function arguments. argv[argc] should |
1084 * have type VAR_UNKNOWN. | |
1126 */ | 1085 */ |
1127 void * | 1086 void * |
1128 call_func_retstr( | 1087 call_func_retstr( |
1129 char_u *func, | 1088 char_u *func, |
1130 int argc, | 1089 int argc, |
1131 char_u **argv, | 1090 typval_T *argv, |
1132 int safe) /* use the sandbox */ | 1091 int safe) /* use the sandbox */ |
1133 { | 1092 { |
1134 typval_T rettv; | 1093 typval_T rettv; |
1135 char_u *retval; | 1094 char_u *retval; |
1136 | 1095 |
1137 /* All arguments are passed as strings, no conversion to number. */ | 1096 if (call_vim_function(func, argc, argv, &rettv, safe) == FAIL) |
1138 if (call_vim_function(func, argc, argv, safe, TRUE, &rettv) == FAIL) | |
1139 return NULL; | 1097 return NULL; |
1140 | 1098 |
1141 retval = vim_strsave(get_tv_string(&rettv)); | 1099 retval = vim_strsave(get_tv_string(&rettv)); |
1142 clear_tv(&rettv); | 1100 clear_tv(&rettv); |
1143 return retval; | 1101 return retval; |
1144 } | 1102 } |
1145 # endif | 1103 # endif |
1146 | 1104 |
1147 /* | 1105 /* |
1148 * Call Vim script function "func" and return the result as a List. | 1106 * Call Vim script function "func" and return the result as a List. |
1149 * Uses argv[argc] for the function arguments. | 1107 * Uses argv[0] to argv[argc - 1] for the function arguments. argv[argc] should |
1108 * have type VAR_UNKNOWN. | |
1150 * Returns NULL when there is something wrong. | 1109 * Returns NULL when there is something wrong. |
1151 */ | 1110 */ |
1152 void * | 1111 void * |
1153 call_func_retlist( | 1112 call_func_retlist( |
1154 char_u *func, | 1113 char_u *func, |
1155 int argc, | 1114 int argc, |
1156 char_u **argv, | 1115 typval_T *argv, |
1157 int safe) /* use the sandbox */ | 1116 int safe) /* use the sandbox */ |
1158 { | 1117 { |
1159 typval_T rettv; | 1118 typval_T rettv; |
1160 | 1119 |
1161 /* All arguments are passed as strings, no conversion to number. */ | 1120 if (call_vim_function(func, argc, argv, &rettv, safe) == FAIL) |
1162 if (call_vim_function(func, argc, argv, safe, TRUE, &rettv) == FAIL) | |
1163 return NULL; | 1121 return NULL; |
1164 | 1122 |
1165 if (rettv.v_type != VAR_LIST) | 1123 if (rettv.v_type != VAR_LIST) |
1166 { | 1124 { |
1167 clear_tv(&rettv); | 1125 clear_tv(&rettv); |