aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-08-17 17:36:30 +0800
committerGitHub <noreply@github.com>2023-08-17 17:36:30 +0800
commit4292575dfc3ecd02874fc291769c8b496bf94abf (patch)
tree08cc7e0d3d47b7c5bb0e2f220021d5d44563e398
parentfb78c1983c267f622c1983a999f5fb8bdfc85c73 (diff)
parent8ac9abd4fad5837c2cc7a858827efb2e53b852be (diff)
downloadrneovim-4292575dfc3ecd02874fc291769c8b496bf94abf.tar.gz
rneovim-4292575dfc3ecd02874fc291769c8b496bf94abf.tar.bz2
rneovim-4292575dfc3ecd02874fc291769c8b496bf94abf.zip
Merge pull request #24752 from zeertzjq/vim-9.0.0548
vim-patch:9.0.{0359,0548,1416}
-rw-r--r--src/nvim/eval.c26
-rw-r--r--src/nvim/eval/funcs.c71
-rw-r--r--test/old/testdir/test_filter_map.vim15
-rw-r--r--test/old/testdir/test_listdict.vim19
4 files changed, 76 insertions, 55 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 589bee6f84..9baf3209a2 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -5040,7 +5040,6 @@ static void filter_map_dict(dict_T *d, filtermap_T filtermap, const char *func_n
return;
}
- const VarLockStatus prev_lock = d->dv_lock;
dict_T *d_ret = NULL;
if (filtermap == FILTERMAP_MAPNEW) {
@@ -5050,7 +5049,8 @@ static void filter_map_dict(dict_T *d, filtermap_T filtermap, const char *func_n
vimvars[VV_KEY].vv_type = VAR_STRING;
- if (filtermap != FILTERMAP_FILTER && d->dv_lock == VAR_UNLOCKED) {
+ const VarLockStatus prev_lock = d->dv_lock;
+ if (d->dv_lock == VAR_UNLOCKED) {
d->dv_lock = VAR_LOCKED;
}
hash_lock(&d->dv_hashtab);
@@ -5060,7 +5060,6 @@ static void filter_map_dict(dict_T *d, filtermap_T filtermap, const char *func_n
|| var_check_ro(di->di_flags, arg_errmsg, TV_TRANSLATE))) {
break;
}
-
vimvars[VV_KEY].vv_str = xstrdup(di->di_key);
typval_T newtv;
bool rem;
@@ -5097,14 +5096,16 @@ static void filter_map_dict(dict_T *d, filtermap_T filtermap, const char *func_n
/// Implementation of map() and filter() for a Blob.
static void filter_map_blob(blob_T *blob_arg, filtermap_T filtermap, typval_T *expr,
- typval_T *rettv)
+ const char *arg_errmsg, typval_T *rettv)
{
if (filtermap == FILTERMAP_MAPNEW) {
rettv->v_type = VAR_BLOB;
rettv->vval.v_blob = NULL;
}
- blob_T *b;
- if ((b = blob_arg) == NULL) {
+ blob_T *b = blob_arg;
+ if (b == NULL
+ || (filtermap == FILTERMAP_FILTER
+ && value_check_lock(b->bv_lock, arg_errmsg, TV_TRANSLATE))) {
return;
}
@@ -5117,6 +5118,11 @@ static void filter_map_blob(blob_T *blob_arg, filtermap_T filtermap, typval_T *e
vimvars[VV_KEY].vv_type = VAR_NUMBER;
+ const VarLockStatus prev_lock = b->bv_lock;
+ if (b->bv_lock == 0) {
+ b->bv_lock = VAR_LOCKED;
+ }
+
for (int i = 0, idx = 0; i < b->bv_ga.ga_len; i++) {
const varnumber_T val = tv_blob_get(b, i);
typval_T tv = {
@@ -5148,6 +5154,8 @@ static void filter_map_blob(blob_T *blob_arg, filtermap_T filtermap, typval_T *e
}
idx++;
}
+
+ b->bv_lock = prev_lock;
}
/// Implementation of map() and filter() for a String.
@@ -5215,7 +5223,6 @@ static void filter_map_list(list_T *l, filtermap_T filtermap, const char *func_n
return;
}
- const VarLockStatus prev_lock = tv_list_locked(l);
list_T *l_ret = NULL;
if (filtermap == FILTERMAP_MAPNEW) {
@@ -5225,7 +5232,8 @@ static void filter_map_list(list_T *l, filtermap_T filtermap, const char *func_n
vimvars[VV_KEY].vv_type = VAR_NUMBER;
- if (filtermap != FILTERMAP_FILTER && tv_list_locked(l) == VAR_UNLOCKED) {
+ const VarLockStatus prev_lock = tv_list_locked(l);
+ if (tv_list_locked(l) == VAR_UNLOCKED) {
tv_list_set_lock(l, VAR_LOCKED);
}
@@ -5311,7 +5319,7 @@ static void filter_map(typval_T *argvars, typval_T *rettv, filtermap_T filtermap
filter_map_dict(argvars[0].vval.v_dict, filtermap, func_name,
arg_errmsg, expr, rettv);
} else if (argvars[0].v_type == VAR_BLOB) {
- filter_map_blob(argvars[0].vval.v_blob, filtermap, expr, rettv);
+ filter_map_blob(argvars[0].vval.v_blob, filtermap, expr, arg_errmsg, rettv);
} else if (argvars[0].v_type == VAR_STRING) {
filter_map_string(tv_get_string(&argvars[0]), filtermap, expr, rettv);
} else {
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
index d5d9726397..044dabb058 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -154,8 +154,6 @@ static const char e_string_list_or_blob_required[]
= N_("E1098: String, List or Blob required");
static const char e_missing_function_argument[]
= N_("E1132: Missing function argument");
-static const char e_string_expected_for_argument_nr[]
- = N_("E1253: String expected for argument %d");
/// Dummy va_list for passing to vim_snprintf
///
@@ -1187,18 +1185,16 @@ static void f_debugbreak(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
/// "deepcopy()" function
static void f_deepcopy(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
{
- int noref = 0;
+ if (tv_check_for_opt_bool_arg(argvars, 1) == FAIL) {
+ return;
+ }
+ varnumber_T noref = 0;
if (argvars[1].v_type != VAR_UNKNOWN) {
- noref = (int)tv_get_bool_chk(&argvars[1], NULL);
- }
- if (noref < 0 || noref > 1) {
- semsg(_(e_using_number_as_bool_nr), noref);
- } else {
- var_item_copy(NULL, &argvars[0], rettv, true, (noref == 0
- ? get_copyID()
- : 0));
+ noref = tv_get_bool_chk(&argvars[1], NULL);
}
+
+ var_item_copy(NULL, &argvars[0], rettv, true, (noref == 0 ? get_copyID() : 0));
}
/// "delete()" function
@@ -6171,9 +6167,10 @@ static void f_reverse(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
}
}
-/// reduce() on a List
-static void reduce_list(typval_T *argvars, const char *func_name, funcexe_T *funcexe,
- typval_T *rettv)
+/// Implementation of reduce() for list "argvars[0]", using the function "expr"
+/// starting with the optional initial value argvars[2] and return the result in
+/// "rettv".
+static void reduce_list(typval_T *argvars, typval_T *expr, typval_T *rettv)
{
list_T *const l = argvars[0].vval.v_list;
const int called_emsg_start = called_emsg;
@@ -6207,7 +6204,9 @@ static void reduce_list(typval_T *argvars, const char *func_name, funcexe_T *fun
argv[0] = *rettv;
argv[1] = *TV_LIST_ITEM_TV(li);
rettv->v_type = VAR_UNKNOWN;
- const int r = call_func(func_name, -1, rettv, 2, argv, funcexe);
+
+ const int r = eval_expr_typval(expr, argv, 2, rettv);
+
tv_clear(&argv[0]);
if (r == FAIL || called_emsg != called_emsg_start) {
break;
@@ -6216,9 +6215,10 @@ static void reduce_list(typval_T *argvars, const char *func_name, funcexe_T *fun
tv_list_set_lock(l, prev_locked);
}
-/// reduce() on a String
-static void reduce_string(typval_T *argvars, const char *func_name, funcexe_T *funcexe,
- typval_T *rettv)
+/// Implementation of reduce() for String "argvars[0]" using the function "expr"
+/// starting with the optional initial value "argvars[2]" and return the result
+/// in "rettv".
+static void reduce_string(typval_T *argvars, typval_T *expr, typval_T *rettv)
{
const char *p = tv_get_string(&argvars[0]);
int len;
@@ -6236,8 +6236,7 @@ static void reduce_string(typval_T *argvars, const char *func_name, funcexe_T *f
.vval.v_string = xstrnsave(p, (size_t)len),
};
p += len;
- } else if (argvars[2].v_type != VAR_STRING) {
- semsg(_(e_string_expected_for_argument_nr), 3);
+ } else if (tv_check_for_string_arg(argvars, 2) == FAIL) {
return;
} else {
tv_copy(&argvars[2], rettv);
@@ -6252,7 +6251,9 @@ static void reduce_string(typval_T *argvars, const char *func_name, funcexe_T *f
.v_lock = VAR_UNLOCKED,
.vval.v_string = xstrnsave(p, (size_t)len),
};
- const int r = call_func(func_name, -1, rettv, 2, argv, funcexe);
+
+ const int r = eval_expr_typval(expr, argv, 2, rettv);
+
tv_clear(&argv[0]);
tv_clear(&argv[1]);
if (r == FAIL || called_emsg != called_emsg_start) {
@@ -6261,9 +6262,10 @@ static void reduce_string(typval_T *argvars, const char *func_name, funcexe_T *f
}
}
-/// reduce() on a Blob
-static void reduce_blob(typval_T *argvars, const char *func_name, funcexe_T *funcexe,
- typval_T *rettv)
+/// Implementaion of reduce() for Blob "argvars[0]" using the function "expr"
+/// starting with the optional initial value "argvars[2]" and return the result
+/// in "rettv".
+static void reduce_blob(typval_T *argvars, typval_T *expr, typval_T *rettv)
{
const blob_T *const b = argvars[0].vval.v_blob;
const int called_emsg_start = called_emsg;
@@ -6281,8 +6283,7 @@ static void reduce_blob(typval_T *argvars, const char *func_name, funcexe_T *fun
.vval.v_number = tv_blob_get(b, 0),
};
i = 1;
- } else if (argvars[2].v_type != VAR_NUMBER) {
- emsg(_(e_number_exp));
+ } else if (tv_check_for_number_arg(argvars, 2) == FAIL) {
return;
} else {
initial = argvars[2];
@@ -6298,7 +6299,9 @@ static void reduce_blob(typval_T *argvars, const char *func_name, funcexe_T *fun
.v_lock = VAR_UNLOCKED,
.vval.v_number = tv_blob_get(b, i),
};
- const int r = call_func(func_name, -1, rettv, 2, argv, funcexe);
+
+ const int r = eval_expr_typval(expr, argv, 2, rettv);
+
if (r == FAIL || called_emsg != called_emsg_start) {
return;
}
@@ -6318,12 +6321,10 @@ static void f_reduce(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
}
const char *func_name;
- partial_T *partial = NULL;
if (argvars[1].v_type == VAR_FUNC) {
func_name = argvars[1].vval.v_string;
} else if (argvars[1].v_type == VAR_PARTIAL) {
- partial = argvars[1].vval.v_partial;
- func_name = partial_name(partial);
+ func_name = partial_name(argvars[1].vval.v_partial);
} else {
func_name = tv_get_string(&argvars[1]);
}
@@ -6332,16 +6333,12 @@ static void f_reduce(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
return;
}
- funcexe_T funcexe = FUNCEXE_INIT;
- funcexe.fe_evaluate = true;
- funcexe.fe_partial = partial;
-
if (argvars[0].v_type == VAR_LIST) {
- reduce_list(argvars, func_name, &funcexe, rettv);
+ reduce_list(argvars, &argvars[1], rettv);
} else if (argvars[0].v_type == VAR_STRING) {
- reduce_string(argvars, func_name, &funcexe, rettv);
+ reduce_string(argvars, &argvars[1], rettv);
} else {
- reduce_blob(argvars, func_name, &funcexe, rettv);
+ reduce_blob(argvars, &argvars[1], rettv);
}
}
diff --git a/test/old/testdir/test_filter_map.vim b/test/old/testdir/test_filter_map.vim
index 3040b7b0d0..7658797759 100644
--- a/test/old/testdir/test_filter_map.vim
+++ b/test/old/testdir/test_filter_map.vim
@@ -109,6 +109,21 @@ func Test_map_and_modify()
let d = #{a: 1, b: 2, c: 3}
call assert_fails('call map(d, "remove(d, v:key)[0]")', 'E741:')
call assert_fails('echo map(d, {k,v -> remove(d, k)})', 'E741:')
+
+ let b = 0z1234
+ call assert_fails('call filter(b, "remove(b, 0)")', 'E741:')
+endfunc
+
+func Test_filter_and_modify()
+ let l = [0]
+ " cannot change the list halfway a map()
+ call assert_fails('call filter(l, "remove(l, 0)")', 'E741:')
+
+ let d = #{a: 0, b: 0, c: 0}
+ call assert_fails('call filter(d, "remove(d, v:key)")', 'E741:')
+
+ let b = 0z1234
+ call assert_fails('call filter(b, "remove(b, 0)")', 'E741:')
endfunc
func Test_mapnew_dict()
diff --git a/test/old/testdir/test_listdict.vim b/test/old/testdir/test_listdict.vim
index f2b4747ff2..abb7f88a7b 100644
--- a/test/old/testdir/test_listdict.vim
+++ b/test/old/testdir/test_listdict.vim
@@ -526,7 +526,7 @@ func Test_dict_deepcopy()
END
call CheckLegacyAndVim9Success(lines)
- call assert_fails("call deepcopy([1, 2], 2)", 'E1023:')
+ call assert_fails("call deepcopy([1, 2], 2)", 'E1212:')
endfunc
" Locked variables
@@ -952,25 +952,26 @@ func Test_reduce()
call assert_fails("call reduce([], { acc, val -> acc + val })", 'E998: Reduce of an empty List with no initial value')
call assert_fails("call reduce(0z, { acc, val -> acc + val })", 'E998: Reduce of an empty Blob with no initial value')
+ call assert_fails("call reduce(v:_null_blob, { acc, val -> acc + val })", 'E998: Reduce of an empty Blob with no initial value')
call assert_fails("call reduce('', { acc, val -> acc + val })", 'E998: Reduce of an empty String with no initial value')
call assert_fails("call reduce(v:_null_string, { acc, val -> acc + val })", 'E998: Reduce of an empty String with no initial value')
call assert_fails("call reduce({}, { acc, val -> acc + val }, 1)", 'E1098:')
call assert_fails("call reduce(0, { acc, val -> acc + val }, 1)", 'E1098:')
- call assert_fails("call reduce([1, 2], 'Xdoes_not_exist')", 'E117:')
- call assert_fails("echo reduce(0z01, { acc, val -> 2 * acc + val }, '')", 'E39:')
+ call assert_fails("call reduce([1, 2], 'Xdoes_not_exist')", 'E121:')
+ call assert_fails("echo reduce(0z01, { acc, val -> 2 * acc + val }, '')", 'E1210:')
" call assert_fails("vim9 reduce(0, (acc, val) => (acc .. val), '')", 'E1252:')
" call assert_fails("vim9 reduce({}, (acc, val) => (acc .. val), '')", 'E1252:')
" call assert_fails("vim9 reduce(0.1, (acc, val) => (acc .. val), '')", 'E1252:')
" call assert_fails("vim9 reduce(function('tr'), (acc, val) => (acc .. val), '')", 'E1252:')
- call assert_fails("call reduce('', { acc, val -> acc + val }, 1)", 'E1253:')
- call assert_fails("call reduce('', { acc, val -> acc + val }, {})", 'E1253:')
- call assert_fails("call reduce('', { acc, val -> acc + val }, 0.1)", 'E1253:')
- call assert_fails("call reduce('', { acc, val -> acc + val }, function('tr'))", 'E1253:')
+ call assert_fails("call reduce('', { acc, val -> acc + val }, 1)", 'E1174:')
+ call assert_fails("call reduce('', { acc, val -> acc + val }, {})", 'E1174:')
+ call assert_fails("call reduce('', { acc, val -> acc + val }, 0.1)", 'E1174:')
+ call assert_fails("call reduce('', { acc, val -> acc + val }, function('tr'))", 'E1174:')
call assert_fails("call reduce('abc', { a, v -> a10}, '')", 'E121:')
- call assert_fails("call reduce(0z01, { a, v -> a10}, 1)", 'E121:')
- call assert_fails("call reduce([1], { a, v -> a10}, '')", 'E121:')
+ call assert_fails("call reduce(0z0102, { a, v -> a10}, 1)", 'E121:')
+ call assert_fails("call reduce([1, 2], { a, v -> a10}, '')", 'E121:')
let g:lut = [1, 2, 3, 4]
func EvilRemove()