To: vim_dev@googlegroups.com Subject: Patch 8.2.0121 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.0121 Problem: filter() and map() on blob don't work. Solution: Correct the code. (closes #5483) Files: src/list.c, src/testdir/test_blob.vim *** ../vim-8.2.0120/src/list.c 2019-12-04 21:42:30.000000000 +0100 --- src/list.c 2020-01-15 20:48:27.529594561 +0100 *************** *** 1689,1694 **** --- 1689,1695 ---- { int i; typval_T tv; + varnumber_T val; // set_vim_var_nr() doesn't set the type set_vim_var_type(VV_KEY, VAR_NUMBER); *************** *** 1696,1702 **** for (i = 0; i < b->bv_ga.ga_len; i++) { tv.v_type = VAR_NUMBER; ! tv.vval.v_number = blob_get(b, i); set_vim_var_nr(VV_KEY, idx); if (filter_map_one(&tv, expr, map, &rem) == FAIL || did_emsg) break; --- 1697,1704 ---- for (i = 0; i < b->bv_ga.ga_len; i++) { tv.v_type = VAR_NUMBER; ! val = blob_get(b, i); ! tv.vval.v_number = val; set_vim_var_nr(VV_KEY, idx); if (filter_map_one(&tv, expr, map, &rem) == FAIL || did_emsg) break; *************** *** 1705,1721 **** emsg(_(e_invalblob)); break; } ! tv.v_type = VAR_NUMBER; ! blob_set(b, i, tv.vval.v_number); ! if (!map && rem) { char_u *p = (char_u *)argvars[0].vval.v_blob->bv_ga.ga_data; ! mch_memmove(p + idx, p + i + 1, (size_t)b->bv_ga.ga_len - i - 1); --b->bv_ga.ga_len; --i; } } } else // argvars[0].v_type == VAR_LIST --- 1707,1727 ---- emsg(_(e_invalblob)); break; } ! if (map) ! { ! if (tv.vval.v_number != val) ! blob_set(b, i, tv.vval.v_number); ! } ! else if (rem) { char_u *p = (char_u *)argvars[0].vval.v_blob->bv_ga.ga_data; ! mch_memmove(p + i, p + i + 1, (size_t)b->bv_ga.ga_len - i - 1); --b->bv_ga.ga_len; --i; } + ++idx; } } else // argvars[0].v_type == VAR_LIST *** ../vim-8.2.0120/src/testdir/test_blob.vim 2019-08-31 20:45:47.000000000 +0200 --- src/testdir/test_blob.vim 2020-01-15 20:44:09.954620101 +0100 *************** *** 260,277 **** " filter() item in blob func Test_blob_filter() ! let b = 0zDEADBEEF ! call filter(b, 'v:val != 0xEF') ! call assert_equal(0zDEADBE, b) 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_fails("call map(b, '[9]')", 'E978:') endfunc func Test_blob_index() --- 260,281 ---- " filter() item in blob func Test_blob_filter() ! 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() ! 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(0z00, '[9]')", 'E978:') endfunc func Test_blob_index() *** ../vim-8.2.0120/src/version.c 2020-01-15 20:36:52.140437085 +0100 --- src/version.c 2020-01-15 20:44:01.786654250 +0100 *************** *** 744,745 **** --- 744,747 ---- { /* Add new patch number below this line */ + /**/ + 121, /**/ -- Wi n0t trei a h0liday in Sweden thi yer? "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///