]> granicus.if.org Git - vim/commitdiff
patch 8.1.0756: copy() does not make a copy of a Blob v8.1.0756
authorBram Moolenaar <Bram@vim.org>
Tue, 15 Jan 2019 21:44:17 +0000 (22:44 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 15 Jan 2019 21:44:17 +0000 (22:44 +0100)
Problem:    copy() does not make a copy of a Blob.
Solution:   Make a copy.

src/eval.c
src/testdir/test_blob.vim
src/version.c

index 049d15cee2e593590b53e9660f98cc7200316606..af1021bdc94e5370b8cf9012dbc867ca8fe72dc3 100644 (file)
@@ -8198,7 +8198,6 @@ item_copy(
        case VAR_SPECIAL:
        case VAR_JOB:
        case VAR_CHANNEL:
-       case VAR_BLOB:
            copy_tv(from, to);
            break;
        case VAR_LIST:
@@ -8217,6 +8216,21 @@ item_copy(
            if (to->vval.v_list == NULL)
                ret = FAIL;
            break;
+       case VAR_BLOB:
+           to->v_type = VAR_BLOB;
+           if (from->vval.v_blob == NULL)
+               to->vval.v_blob = NULL;
+           else if (rettv_blob_alloc(to) == FAIL)
+               ret = FAIL;
+           else
+           {
+               int  len = from->vval.v_blob->bv_ga.ga_len;
+
+               to->vval.v_blob->bv_ga.ga_data =
+                           vim_memsave(from->vval.v_blob->bv_ga.ga_data, len);
+               to->vval.v_blob->bv_ga.ga_len = len;
+           }
+           break;
        case VAR_DICT:
            to->v_type = VAR_DICT;
            to->v_lock = 0;
index 3eeb3d2f3aad12bbbd6b5c6505704420d6ad5b6b..d5f682f5444c6229b539798f47593493fafa8aea 100644 (file)
@@ -112,7 +112,14 @@ func Test_blob_compare()
 
   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_fails('let x = b1 > b2')
   call assert_fails('let x = b1 < b2')
index bb13765e9dae889688e1e5df097de1c39fe0ef19..6317a8e962b2f7ea67632a2e6b99f83394e19287 100644 (file)
@@ -795,6 +795,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    756,
 /**/
     755,
 /**/