aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Dewar <seandewar@users.noreply.github.com>2020-11-25 18:56:30 +0000
committerSean Dewar <seandewar@users.noreply.github.com>2021-09-15 22:57:53 +0100
commitef76238548ba758cb15b5316710b356b59334a41 (patch)
tree3a82b001d10e010303b52dc4bfd448b392a2baa7
parent726b25528863ecd25f62f488b41bc984b842458c (diff)
downloadrneovim-ef76238548ba758cb15b5316710b356b59334a41.tar.gz
rneovim-ef76238548ba758cb15b5316710b356b59334a41.tar.bz2
rneovim-ef76238548ba758cb15b5316710b356b59334a41.zip
vim-patch:8.2.0121: filter() and map() on blob don't work
Problem: filter() and map() on blob don't work. Solution: Correct the code. (closes vim/vim#5483) https://github.com/vim/vim/commit/49c57ce50019b667e5005ce1cfb8cdc2e48bf868
-rw-r--r--src/nvim/eval.c14
-rw-r--r--src/nvim/testdir/test_blob.vim18
2 files changed, 20 insertions, 12 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 9d03a94d71..ba9cb11ed5 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -6449,7 +6449,8 @@ void filter_map(typval_T *argvars, typval_T *rettv, int map)
for (int i = 0; i < b->bv_ga.ga_len; i++) {
typval_T tv;
tv.v_type = VAR_NUMBER;
- tv.vval.v_number = tv_blob_get(b, i);
+ const varnumber_T val = tv_blob_get(b, i);
+ tv.vval.v_number = val;
vimvars[VV_KEY].vv_nr = idx;
if (filter_map_one(&tv, expr, map, &rem) == FAIL || did_emsg) {
break;
@@ -6458,14 +6459,17 @@ void filter_map(typval_T *argvars, typval_T *rettv, int map)
EMSG(_(e_invalblob));
return;
}
- tv.v_type = VAR_NUMBER;
- tv_blob_set(b, i, tv.vval.v_number);
- if (!map && rem) {
+ if (map) {
+ if (tv.vval.v_number != val) {
+ tv_blob_set(b, i, tv.vval.v_number);
+ }
+ } else if (rem) {
char_u *const p = (char_u *)argvars[0].vval.v_blob->bv_ga.ga_data;
- memmove(p + idx, p + i + 1, (size_t)b->bv_ga.ga_len - i - 1);
+ memmove(p + i, p + i + 1, (size_t)b->bv_ga.ga_len - i - 1);
b->bv_ga.ga_len--;
i--;
}
+ idx++;
}
} else {
assert(argvars[0].v_type == VAR_LIST);
diff --git a/src/nvim/testdir/test_blob.vim b/src/nvim/testdir/test_blob.vim
index 575c757837..a74dd538e5 100644
--- a/src/nvim/testdir/test_blob.vim
+++ b/src/nvim/testdir/test_blob.vim
@@ -260,18 +260,22 @@ endfunc
" filter() item in blob
func Test_blob_filter()
- let b = 0zDEADBEEF
- call filter(b, 'v:val != 0xEF')
- call assert_equal(0zDEADBE, b)
+ call assert_equal(0z, filter(0zDEADBEEF, '0'))
+ call assert_equal(0zADBEEF, filter(0zDEADBEEF, 'v:val != 0xDE'))
+ call assert_equal(0zDEADEF, filter(0zDEADBEEF, 'v:val != 0xBE'))
+ call assert_equal(0zDEADBE, filter(0zDEADBEEF, 'v:val != 0xEF'))
+ call assert_equal(0zDEADBEEF, filter(0zDEADBEEF, '1'))
+ call assert_equal(0z01030103, filter(0z010203010203, 'v:val != 0x02'))
+ call assert_equal(0zADEF, filter(0zDEADBEEF, 'v:key % 2'))
endfunc
" map() item in blob
func Test_blob_map()
- let b = 0zDEADBEEF
- call map(b, 'v:val + 1')
- call assert_equal(0zDFAEBFF0, b)
+ call assert_equal(0zDFAEBFF0, map(0zDEADBEEF, 'v:val + 1'))
+ call assert_equal(0z00010203, map(0zDEADBEEF, 'v:key'))
+ call assert_equal(0zDEAEC0F2, map(0zDEADBEEF, 'v:key + v:val'))
- call assert_fails("call map(b, '[9]')", 'E978:')
+ call assert_fails("call map(0z00, '[9]')", 'E978:')
endfunc
func Test_blob_index()