To: vim_dev@googlegroups.com Subject: Patch 8.2.2777 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2777 Problem: Vim9: blob operations not tested in all ways. Solution: Run tests with CheckLegacyAndVim9Success(). Make blob assign with index work. Files: src/vim9compile.c, src/vim9execute.c, src/errors.h, src/blob.c, src/proto/blob.pro, src/testdir/test_blob.vim, src/testdir/test_vim9_disassemble.vim *** ../vim-8.2.2776/src/vim9compile.c 2021-04-17 17:59:15.819846298 +0200 --- src/vim9compile.c 2021-04-17 20:34:01.215930951 +0200 *************** *** 6209,6222 **** } if (dest_type == VAR_DICT && may_generate_2STRING(-1, cctx) == FAIL) return FAIL; ! if (dest_type == VAR_LIST) { ! if (range ! && need_type(((type_T **)stack->ga_data)[stack->ga_len - 2], ! &t_number, -1, 0, cctx, FALSE, FALSE) == FAIL) return FAIL; ! if (need_type(((type_T **)stack->ga_data)[stack->ga_len - 1], ! &t_number, -1, 0, cctx, FALSE, FALSE) == FAIL) return FAIL; } } --- 6209,6229 ---- } if (dest_type == VAR_DICT && may_generate_2STRING(-1, cctx) == FAIL) return FAIL; ! if (dest_type == VAR_LIST || dest_type == VAR_BLOB) { ! type_T *type; ! ! if (range) ! { ! type = ((type_T **)stack->ga_data)[stack->ga_len - 2]; ! if (need_type(type, &t_number, ! -1, 0, cctx, FALSE, FALSE) == FAIL) return FAIL; ! } ! type = ((type_T **)stack->ga_data)[stack->ga_len - 1]; ! if ((dest_type != VAR_BLOB || type != &t_special) ! && need_type(type, &t_number, ! -1, 0, cctx, FALSE, FALSE) == FAIL) return FAIL; } } *** ../vim-8.2.2776/src/vim9execute.c 2021-04-17 17:59:15.819846298 +0200 --- src/vim9execute.c 2021-04-17 20:20:52.028268397 +0200 *************** *** 2221,2227 **** } else if (status == OK && dest_type == VAR_BLOB) { ! // TODO } else { --- 2221,2255 ---- } else if (status == OK && dest_type == VAR_BLOB) { ! long lidx = (long)tv_idx->vval.v_number; ! blob_T *blob = tv_dest->vval.v_blob; ! varnumber_T nr; ! int error = FALSE; ! int len; ! ! if (blob == NULL) ! { ! emsg(_(e_blob_not_set)); ! goto on_error; ! } ! len = blob_len(blob); ! if (lidx < 0 && len + lidx >= 0) ! // negative index is relative to the end ! lidx = len + lidx; ! ! // Can add one byte at the end. ! if (lidx < 0 || lidx > len) ! { ! semsg(_(e_blobidx), lidx); ! goto on_error; ! } ! if (value_check_lock(blob->bv_lock, ! (char_u *)"blob", FALSE)) ! goto on_error; ! nr = tv_get_number_chk(tv, &error); ! if (error) ! goto on_error; ! blob_set_append(blob, lidx, nr); } else { *************** *** 4415,4433 **** break; case ISN_STOREINDEX: ! switch (iptr->isn_arg.vartype) ! { ! case VAR_LIST: ! smsg("%4d STORELIST", current); ! break; ! case VAR_DICT: ! smsg("%4d STOREDICT", current); ! break; ! case VAR_ANY: ! smsg("%4d STOREINDEX", current); ! break; ! default: break; ! } break; case ISN_STORERANGE: --- 4443,4450 ---- break; case ISN_STOREINDEX: ! smsg("%4d STOREINDEX %s", current, ! vartype_name(iptr->isn_arg.vartype)); break; case ISN_STORERANGE: *** ../vim-8.2.2776/src/errors.h 2021-04-14 20:35:19.400232653 +0200 --- src/errors.h 2021-04-17 20:11:15.597023429 +0200 *************** *** 403,405 **** --- 403,407 ---- INIT(= N_("E1182: Blob required")); EXTERN char e_cannot_use_range_with_assignment_operator_str[] INIT(= N_("E1183: Cannot use a range with an assignment operator: %s")); + EXTERN char e_blob_not_set[] + INIT(= N_("E1184: Blob not set")); *** ../vim-8.2.2776/src/blob.c 2021-04-14 21:30:02.923966486 +0200 --- src/blob.c 2021-04-17 20:20:20.232207749 +0200 *************** *** 125,137 **** } /* ! * Store one byte "c" in blob "b" at "idx". * Caller must make sure that "idx" is valid. */ void ! blob_set(blob_T *b, int idx, char_u c) { ! ((char_u*)b->bv_ga.ga_data)[idx] = c; } /* --- 125,157 ---- } /* ! * Store one byte "byte" in blob "blob" at "idx". * Caller must make sure that "idx" is valid. */ void ! blob_set(blob_T *blob, int idx, int byte) { ! ((char_u*)blob->bv_ga.ga_data)[idx] = byte; ! } ! ! /* ! * Store one byte "byte" in blob "blob" at "idx". ! * Append one byte if needed. ! */ ! void ! blob_set_append(blob_T *blob, int idx, int byte) ! { ! garray_T *gap = &blob->bv_ga; ! ! // Allow for appending a byte. Setting a byte beyond ! // the end is an error otherwise. ! if (idx < gap->ga_len ! || (idx == gap->ga_len && ga_grow(gap, 1) == OK)) ! { ! blob_set(blob, idx, byte); ! if (idx == gap->ga_len) ! ++gap->ga_len; ! } } /* *** ../vim-8.2.2776/src/proto/blob.pro 2021-04-14 21:30:02.927966474 +0200 --- src/proto/blob.pro 2021-04-17 20:20:06.120177865 +0200 *************** *** 7,13 **** void blob_unref(blob_T *b); long blob_len(blob_T *b); int blob_get(blob_T *b, int idx); ! void blob_set(blob_T *b, int idx, char_u c); int blob_equal(blob_T *b1, blob_T *b2); int read_blob(FILE *fd, blob_T *blob); int write_blob(FILE *fd, blob_T *blob); --- 7,14 ---- void blob_unref(blob_T *b); long blob_len(blob_T *b); int blob_get(blob_T *b, int idx); ! void blob_set(blob_T *blob, int idx, int byte); ! void blob_set_append(blob_T *blob, int idx, int byte); int blob_equal(blob_T *b1, blob_T *b2); int read_blob(FILE *fd, blob_T *blob); int write_blob(FILE *fd, blob_T *blob); *** ../vim-8.2.2776/src/testdir/test_blob.vim 2021-04-14 20:35:19.412232623 +0200 --- src/testdir/test_blob.vim 2021-04-17 20:38:09.607446820 +0200 *************** *** 120,207 **** endfunc func Test_blob_get_range() let b = 0z0011223344 call assert_equal(0z2233, b[2:3]) - call assert_equal(0z223344, b[2:-1]) - call assert_equal(0z00, b[0:-5]) - call assert_equal(0z, b[0:-11]) - call assert_equal(0z44, b[-1:]) - call assert_equal(0z0011223344, b[:]) - call assert_equal(0z0011223344, b[:-1]) - call assert_equal(0z, b[5:6]) - call assert_equal(0z0011, b[-10:1]) endfunc func Test_blob_get() ! let b = 0z0011223344 ! call assert_equal(0x00, get(b, 0)) ! call assert_equal(0x22, get(b, 2, 999)) ! call assert_equal(0x44, get(b, 4)) ! call assert_equal(0x44, get(b, -1)) ! call assert_equal(-1, get(b, 5)) ! call assert_equal(999, get(b, 5, 999)) ! call assert_equal(-1, get(b, -8)) ! call assert_equal(999, get(b, -8, 999)) ! call assert_equal(10, get(test_null_blob(), 2, 10)) ! ! call assert_equal(0x00, b[0]) ! call assert_equal(0x22, b[2]) ! call assert_equal(0x44, b[4]) ! call assert_equal(0x44, b[-1]) ! call assert_fails('echo b[5]', 'E979:') ! call assert_fails('echo b[-8]', 'E979:') endfunc func Test_blob_to_string() ! let b = 0z00112233445566778899aabbccdd ! call assert_equal('0z00112233.44556677.8899AABB.CCDD', string(b)) ! call assert_equal(b, eval(string(b))) ! call remove(b, 4, -1) ! call assert_equal('0z00112233', string(b)) ! call remove(b, 0, 3) ! call assert_equal('0z', string(b)) ! call assert_equal('0z', string(test_null_blob())) endfunc func Test_blob_compare() ! let b1 = 0z0011 ! let b2 = 0z1100 ! let b3 = 0z001122 ! call assert_true(b1 == b1) ! call assert_false(b1 == b2) ! call assert_false(b1 == b3) ! call assert_true(b1 != b2) ! call assert_true(b1 != b3) ! call assert_true(b1 == 0z0011) ! call assert_fails('echo b1 == 9', 'E977:') ! call assert_fails('echo b1 != 9', 'E977:') ! ! call assert_false(b1 is b2) ! let b2 = b1 ! call assert_true(b1 == b2) ! call assert_true(b1 is b2) ! let b2 = copy(b1) ! call assert_true(b1 == b2) ! call assert_false(b1 is b2) ! let b2 = b1[:] ! call assert_true(b1 == b2) ! call assert_false(b1 is b2) ! call assert_true(b1 isnot b2) ! ! call assert_fails('let x = b1 > b2') ! call assert_fails('let x = b1 < b2') ! call assert_fails('let x = b1 - b2') ! call assert_fails('let x = b1 / b2') ! call assert_fails('let x = b1 * b2') ! endfunc ! ! " test for range assign ! func Test_blob_range_assign() ! let b = 0z00 ! let b[1] = 0x11 ! let b[2] = 0x22 ! call assert_equal(0z001122, b) ! call assert_fails('let b[4] = 0x33', 'E979:') endfunc func Test_blob_for_loop() --- 120,285 ---- endfunc func Test_blob_get_range() + let lines =<< trim END + VAR b = 0z0011223344 + call assert_equal(0z2233, b[2 : 3]) + call assert_equal(0z223344, b[2 : -1]) + call assert_equal(0z00, b[0 : -5]) + call assert_equal(0z, b[0 : -11]) + call assert_equal(0z44, b[-1 :]) + call assert_equal(0z0011223344, b[:]) + call assert_equal(0z0011223344, b[: -1]) + call assert_equal(0z, b[5 : 6]) + call assert_equal(0z0011, b[-10 : 1]) + END + call CheckLegacyAndVim9Success(lines) + + " legacy script white space let b = 0z0011223344 call assert_equal(0z2233, b[2:3]) endfunc func Test_blob_get() ! let lines =<< trim END ! VAR b = 0z0011223344 ! call assert_equal(0x00, get(b, 0)) ! call assert_equal(0x22, get(b, 2, 999)) ! call assert_equal(0x44, get(b, 4)) ! call assert_equal(0x44, get(b, -1)) ! call assert_equal(-1, get(b, 5)) ! call assert_equal(999, get(b, 5, 999)) ! call assert_equal(-1, get(b, -8)) ! call assert_equal(999, get(b, -8, 999)) ! call assert_equal(10, get(test_null_blob(), 2, 10)) ! ! call assert_equal(0x00, b[0]) ! call assert_equal(0x22, b[2]) ! call assert_equal(0x44, b[4]) ! call assert_equal(0x44, b[-1]) ! END ! call CheckLegacyAndVim9Success(lines) ! ! let lines =<< trim END ! VAR b = 0z0011223344 ! echo b[5] ! END ! call CheckLegacyAndVim9Failure(lines, 'E979:') ! ! let lines =<< trim END ! VAR b = 0z0011223344 ! echo b[-8] ! END ! call CheckLegacyAndVim9Failure(lines, 'E979:') endfunc func Test_blob_to_string() ! let lines =<< trim END ! VAR b = 0z00112233445566778899aabbccdd ! call assert_equal('0z00112233.44556677.8899AABB.CCDD', string(b)) ! call assert_equal(b, eval(string(b))) ! call remove(b, 4, -1) ! call assert_equal('0z00112233', string(b)) ! call remove(b, 0, 3) ! call assert_equal('0z', string(b)) ! call assert_equal('0z', string(test_null_blob())) ! END ! call CheckLegacyAndVim9Success(lines) endfunc func Test_blob_compare() ! let lines =<< trim END ! VAR b1 = 0z0011 ! VAR b2 = 0z1100 ! VAR b3 = 0z001122 ! call assert_true(b1 == b1) ! call assert_false(b1 == b2) ! call assert_false(b1 == b3) ! call assert_true(b1 != b2) ! call assert_true(b1 != b3) ! call assert_true(b1 == 0z0011) ! ! call assert_false(b1 is b2) ! LET b2 = b1 ! call assert_true(b1 == b2) ! call assert_true(b1 is b2) ! LET b2 = copy(b1) ! call assert_true(b1 == b2) ! call assert_false(b1 is b2) ! LET b2 = b1[:] ! call assert_true(b1 == b2) ! call assert_false(b1 is b2) ! call assert_true(b1 isnot b2) ! END ! call CheckLegacyAndVim9Success(lines) ! ! let lines =<< trim END ! VAR b1 = 0z0011 ! echo b1 == 9 ! END ! call CheckLegacyAndVim9Failure(lines, ['E977:', 'E1072', 'E1072']) ! ! let lines =<< trim END ! VAR b1 = 0z0011 ! echo b1 != 9 ! END ! call CheckLegacyAndVim9Failure(lines, ['E977:', 'E1072', 'E1072']) ! ! let lines =<< trim END ! VAR b1 = 0z0011 ! VAR b2 = 0z1100 ! VAR x = b1 > b2 ! END ! call CheckLegacyAndVim9Failure(lines, ['E978:', 'E1072:', 'E1072:']) ! ! let lines =<< trim END ! VAR b1 = 0z0011 ! VAR b2 = 0z1100 ! VAR x = b1 < b2 ! END ! call CheckLegacyAndVim9Failure(lines, ['E978:', 'E1072:', 'E1072:']) ! ! let lines =<< trim END ! VAR b1 = 0z0011 ! VAR b2 = 0z1100 ! VAR x = b1 - b2 ! END ! call CheckLegacyAndVim9Failure(lines, ['E974:', 'E1036:', 'E974:']) ! ! let lines =<< trim END ! VAR b1 = 0z0011 ! VAR b2 = 0z1100 ! VAR x = b1 / b2 ! END ! call CheckLegacyAndVim9Failure(lines, ['E974:', 'E1036:', 'E974:']) ! ! let lines =<< trim END ! VAR b1 = 0z0011 ! VAR b2 = 0z1100 ! VAR x = b1 * b2 ! END ! call CheckLegacyAndVim9Failure(lines, ['E974:', 'E1036:', 'E974:']) ! endfunc ! ! func Test_blob_index_assign() ! let lines =<< trim END ! VAR b = 0z00 ! LET b[1] = 0x11 ! LET b[2] = 0x22 ! call assert_equal(0z001122, b) ! END ! call CheckLegacyAndVim9Success(lines) ! ! let lines =<< trim END ! VAR b = 0z00 ! LET b[2] = 0x33 ! END ! call CheckLegacyAndVim9Failure(lines, 'E979:') ! ! let lines =<< trim END ! VAR b = 0z00 ! LET b[-2] = 0x33 ! END ! call CheckLegacyAndVim9Failure(lines, 'E979:') endfunc func Test_blob_for_loop() *** ../vim-8.2.2776/src/testdir/test_vim9_disassemble.vim 2021-04-14 12:39:56.656454570 +0200 --- src/testdir/test_vim9_disassemble.vim 2021-04-17 20:43:13.202759951 +0200 *************** *** 246,251 **** --- 246,253 ---- locallist[0] = 123 var localdict: dict = {} localdict["a"] = 456 + var localblob: blob = 0z1122 + localblob[1] = 33 enddef def Test_disassemble_store_member() *************** *** 259,265 **** '\d PUSHNR 123\_s*' .. '\d PUSHNR 0\_s*' .. '\d LOAD $0\_s*' .. ! '\d STORELIST\_s*' .. 'var localdict: dict = {}\_s*' .. '\d NEWDICT size 0\_s*' .. '\d SETTYPE dict\_s*' .. --- 261,267 ---- '\d PUSHNR 123\_s*' .. '\d PUSHNR 0\_s*' .. '\d LOAD $0\_s*' .. ! '\d STOREINDEX list\_s*' .. 'var localdict: dict = {}\_s*' .. '\d NEWDICT size 0\_s*' .. '\d SETTYPE dict\_s*' .. *************** *** 268,274 **** '\d\+ PUSHNR 456\_s*' .. '\d\+ PUSHS "a"\_s*' .. '\d\+ LOAD $1\_s*' .. ! '\d\+ STOREDICT\_s*' .. '\d\+ RETURN 0', res) enddef --- 270,284 ---- '\d\+ PUSHNR 456\_s*' .. '\d\+ PUSHS "a"\_s*' .. '\d\+ LOAD $1\_s*' .. ! '\d\+ STOREINDEX dict\_s*' .. ! 'var localblob: blob = 0z1122\_s*' .. ! '\d\+ PUSHBLOB 0z1122\_s*' .. ! '\d\+ STORE $2\_s*' .. ! 'localblob\[1\] = 33\_s*' .. ! '\d\+ PUSHNR 33\_s*' .. ! '\d\+ PUSHNR 1\_s*' .. ! '\d\+ LOAD $2\_s*' .. ! '\d\+ STOREINDEX blob\_s*' .. '\d\+ RETURN 0', res) enddef *************** *** 291,297 **** '\d PUSHNR 0\_s*' .. '\d LOAD $0\_s*' .. '\d MEMBER dd\_s*' .. ! '\d STOREINDEX\_s*' .. '\d\+ RETURN 0', res) enddef --- 301,307 ---- '\d PUSHNR 0\_s*' .. '\d LOAD $0\_s*' .. '\d MEMBER dd\_s*' .. ! '\d STOREINDEX any\_s*' .. '\d\+ RETURN 0', res) enddef *** ../vim-8.2.2776/src/version.c 2021-04-17 18:38:49.888758511 +0200 --- src/version.c 2021-04-17 20:43:30.762718027 +0200 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2777, /**/ -- hundred-and-one symptoms of being an internet addict: 115. You are late picking up your kid from school and try to explain to the teacher you were stuck in Web traffic. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///