changeset 15496:f1c33409e908 v8.1.0756

patch 8.1.0756: copy() does not make a copy of a Blob commit https://github.com/vim/vim/commit/3d28b58c519c9fc3427587201423c74746cc219e Author: Bram Moolenaar <Bram@vim.org> Date: Tue Jan 15 22:44:17 2019 +0100 patch 8.1.0756: copy() does not make a copy of a Blob Problem: copy() does not make a copy of a Blob. Solution: Make a copy.
author Bram Moolenaar <Bram@vim.org>
date Tue, 15 Jan 2019 22:45:05 +0100
parents 617ca1eb76f8
children bf6ba67f1a1c
files src/eval.c src/testdir/test_blob.vim src/version.c
diffstat 3 files changed, 24 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/eval.c
+++ b/src/eval.c
@@ -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;
--- a/src/testdir/test_blob.vim
+++ b/src/testdir/test_blob.vim
@@ -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')
--- a/src/version.c
+++ b/src/version.c
@@ -796,6 +796,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    756,
+/**/
     755,
 /**/
     754,