aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSean Dewar <seandewar@users.noreply.github.com>2021-08-01 18:27:41 +0100
committerSean Dewar <seandewar@users.noreply.github.com>2021-09-16 00:14:46 +0100
commite88961943b85434ceebff6a31089c635ac39cd66 (patch)
tree715ec2acac329e04e5b1a265c63e2e0a960c4341 /src
parent3d6bb8b3fbe21d8a7a4ba975682eb9a4e5170859 (diff)
downloadrneovim-e88961943b85434ceebff6a31089c635ac39cd66.tar.gz
rneovim-e88961943b85434ceebff6a31089c635ac39cd66.tar.bz2
rneovim-e88961943b85434ceebff6a31089c635ac39cd66.zip
fix(eval): partially port v8.2.3284
These were issues that I found while porting that I fixed upstream. :^) Very little of the patch can be exactly ported as we're a bit behind on dependant patches (we also can't use the exact :for emsg, as we don't support iterating over Strings yet), so just translate the fixes as best as we can for now. Include latest relevant doc changes from: - v8.1.0815 - v8.2.2658
Diffstat (limited to 'src')
-rw-r--r--src/nvim/eval.c2
-rw-r--r--src/nvim/eval/funcs.c21
-rw-r--r--src/nvim/testdir/test_blob.vim12
-rw-r--r--src/nvim/testdir/test_eval_stuff.vim8
4 files changed, 33 insertions, 10 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 8777ae1281..5607de3cc1 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -2614,7 +2614,7 @@ void *eval_for_line(const char_u *arg, bool *errp, char_u **nextcmdp, int skip)
}
tv_clear(&tv);
} else {
- EMSG(_(e_listreq));
+ EMSG(_(e_listblobreq));
tv_clear(&tv);
}
}
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
index 660c069e7f..ec13aa7fbd 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -4984,12 +4984,16 @@ static void f_insert(typval_T *argvars, typval_T *rettv, FunPtr fptr)
bool error = false;
if (argvars[0].v_type == VAR_BLOB) {
- if (argvars[0].vval.v_blob == NULL) {
+ blob_T *const b = argvars[0].vval.v_blob;
+
+ if (b == NULL
+ || var_check_lock(b->bv_lock, N_("insert() argument"),
+ TV_TRANSLATE)) {
return;
}
long before = 0;
- const int len = tv_blob_len(argvars[0].vval.v_blob);
+ const int len = tv_blob_len(b);
if (argvars[2].v_type != VAR_UNKNOWN) {
before = (long)tv_get_number_chk(&argvars[2], &error);
@@ -5010,11 +5014,11 @@ static void f_insert(typval_T *argvars, typval_T *rettv, FunPtr fptr)
return;
}
- ga_grow(&argvars[0].vval.v_blob->bv_ga, 1);
- char_u *const p = (char_u *)argvars[0].vval.v_blob->bv_ga.ga_data;
+ ga_grow(&b->bv_ga, 1);
+ char_u *const p = (char_u *)b->bv_ga.ga_data;
memmove(p + before + 1, p + before, (size_t)len - before);
*(p + before) = val;
- argvars[0].vval.v_blob->bv_ga.ga_len++;
+ b->bv_ga.ga_len++;
tv_copy(&argvars[0], rettv);
} else if (argvars[0].v_type != VAR_LIST) {
@@ -7312,11 +7316,16 @@ static void f_remove(typval_T *argvars, typval_T *rettv, FunPtr fptr)
}
}
} else if (argvars[0].v_type == VAR_BLOB) {
+ blob_T *const b = argvars[0].vval.v_blob;
+
+ if (b != NULL && var_check_lock(b->bv_lock, arg_errmsg, TV_TRANSLATE)) {
+ return;
+ }
+
bool error = false;
idx = (long)tv_get_number_chk(&argvars[1], &error);
if (!error) {
- blob_T *const b = argvars[0].vval.v_blob;
const int len = tv_blob_len(b);
if (idx < 0) {
diff --git a/src/nvim/testdir/test_blob.vim b/src/nvim/testdir/test_blob.vim
index b21fd936ad..20758b0c0a 100644
--- a/src/nvim/testdir/test_blob.vim
+++ b/src/nvim/testdir/test_blob.vim
@@ -251,6 +251,12 @@ func Test_blob_func_remove()
call assert_fails("call remove(1, 0)", 'E896:')
call assert_fails("call remove(b, b)", 'E974:')
call assert_fails("call remove(v:_null_blob, 1, 2)", 'E979:')
+
+ " Translated from v8.2.3284
+ let b = 0zDEADBEEF
+ lockvar b
+ call assert_fails('call remove(b, 0)', 'E741:')
+ unlockvar b
endfunc
func Test_blob_read_write()
@@ -308,6 +314,12 @@ func Test_blob_insert()
call assert_fails('call insert(b, 257)', 'E475:')
call assert_fails('call insert(b, 0, [9])', 'E745:')
call assert_equal(0, insert(v:_null_blob, 0x33))
+
+ " Translated from v8.2.3284
+ let b = 0zDEADBEEF
+ lockvar b
+ call assert_fails('call insert(b, 3)', 'E741:')
+ unlockvar b
endfunc
func Test_blob_reverse()
diff --git a/src/nvim/testdir/test_eval_stuff.vim b/src/nvim/testdir/test_eval_stuff.vim
index 084c856ba0..98e098387e 100644
--- a/src/nvim/testdir/test_eval_stuff.vim
+++ b/src/nvim/testdir/test_eval_stuff.vim
@@ -23,9 +23,11 @@ func Test_E963()
endfunc
func Test_for_invalid()
- call assert_fails("for x in 99", 'E714:')
- call assert_fails("for x in function('winnr')", 'E714:')
- call assert_fails("for x in {'a': 9}", 'E714:')
+ " Vim gives incorrect emsg here until v8.2.3284, but the exact emsg from that
+ " patch cannot be used until v8.2.2658 is ported (for loop over Strings)
+ call assert_fails("for x in 99", 'E897:')
+ call assert_fails("for x in function('winnr')", 'E897:')
+ call assert_fails("for x in {'a': 9}", 'E897:')
if 0
/1/5/2/s/\n