Karsten Hopp c38828
To: vim_dev@googlegroups.com
Karsten Hopp c38828
Subject: Patch 7.4.717
Karsten Hopp c38828
Fcc: outbox
Karsten Hopp c38828
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp c38828
Mime-Version: 1.0
Karsten Hopp c38828
Content-Type: text/plain; charset=UTF-8
Karsten Hopp c38828
Content-Transfer-Encoding: 8bit
Karsten Hopp c38828
------------
Karsten Hopp c38828
Karsten Hopp c38828
Patch 7.4.717
Karsten Hopp c38828
Problem:    ":let list += list" can change a locked list.
Karsten Hopp c38828
Solution:   Check for the lock earlier. (Olaf Dabrunz)
Karsten Hopp c38828
Files:      src/eval.c, src/testdir/test55.in, src/testdir/test55.ok
Karsten Hopp c38828
Karsten Hopp c38828
Karsten Hopp c38828
*** ../vim-7.4.716/src/eval.c	2015-04-21 16:48:55.028917216 +0200
Karsten Hopp c38828
--- src/eval.c	2015-05-04 11:06:30.878541202 +0200
Karsten Hopp c38828
***************
Karsten Hopp c38828
*** 783,789 ****
Karsten Hopp c38828
  static char_u * make_expanded_name __ARGS((char_u *in_start, char_u *expr_start, char_u *expr_end, char_u *in_end));
Karsten Hopp c38828
  static int eval_isnamec __ARGS((int c));
Karsten Hopp c38828
  static int eval_isnamec1 __ARGS((int c));
Karsten Hopp c38828
! static int get_var_tv __ARGS((char_u *name, int len, typval_T *rettv, int verbose, int no_autoload));
Karsten Hopp c38828
  static int handle_subscript __ARGS((char_u **arg, typval_T *rettv, int evaluate, int verbose));
Karsten Hopp c38828
  static typval_T *alloc_tv __ARGS((void));
Karsten Hopp c38828
  static typval_T *alloc_string_tv __ARGS((char_u *string));
Karsten Hopp c38828
--- 783,789 ----
Karsten Hopp c38828
  static char_u * make_expanded_name __ARGS((char_u *in_start, char_u *expr_start, char_u *expr_end, char_u *in_end));
Karsten Hopp c38828
  static int eval_isnamec __ARGS((int c));
Karsten Hopp c38828
  static int eval_isnamec1 __ARGS((int c));
Karsten Hopp c38828
! static int get_var_tv __ARGS((char_u *name, int len, typval_T *rettv, dictitem_T **dip, int verbose, int no_autoload));
Karsten Hopp c38828
  static int handle_subscript __ARGS((char_u **arg, typval_T *rettv, int evaluate, int verbose));
Karsten Hopp c38828
  static typval_T *alloc_tv __ARGS((void));
Karsten Hopp c38828
  static typval_T *alloc_string_tv __ARGS((char_u *string));
Karsten Hopp c38828
***************
Karsten Hopp c38828
*** 2257,2263 ****
Karsten Hopp c38828
  	    {
Karsten Hopp c38828
  		if (tofree != NULL)
Karsten Hopp c38828
  		    name = tofree;
Karsten Hopp c38828
! 		if (get_var_tv(name, len, &tv, TRUE, FALSE) == FAIL)
Karsten Hopp c38828
  		    error = TRUE;
Karsten Hopp c38828
  		else
Karsten Hopp c38828
  		{
Karsten Hopp c38828
--- 2257,2263 ----
Karsten Hopp c38828
  	    {
Karsten Hopp c38828
  		if (tofree != NULL)
Karsten Hopp c38828
  		    name = tofree;
Karsten Hopp c38828
! 		if (get_var_tv(name, len, &tv, NULL, TRUE, FALSE) == FAIL)
Karsten Hopp c38828
  		    error = TRUE;
Karsten Hopp c38828
  		else
Karsten Hopp c38828
  		{
Karsten Hopp c38828
***************
Karsten Hopp c38828
*** 2926,2935 ****
Karsten Hopp c38828
  		typval_T tv;
Karsten Hopp c38828
  
Karsten Hopp c38828
  		/* handle +=, -= and .= */
Karsten Hopp c38828
  		if (get_var_tv(lp->ll_name, (int)STRLEN(lp->ll_name),
Karsten Hopp c38828
! 						      &tv, TRUE, FALSE) == OK)
Karsten Hopp c38828
  		{
Karsten Hopp c38828
! 		    if (tv_op(&tv, rettv, op) == OK)
Karsten Hopp c38828
  			set_var(lp->ll_name, &tv, FALSE);
Karsten Hopp c38828
  		    clear_tv(&tv;;
Karsten Hopp c38828
  		}
Karsten Hopp c38828
--- 2926,2940 ----
Karsten Hopp c38828
  		typval_T tv;
Karsten Hopp c38828
  
Karsten Hopp c38828
  		/* handle +=, -= and .= */
Karsten Hopp c38828
+ 		di = NULL;
Karsten Hopp c38828
  		if (get_var_tv(lp->ll_name, (int)STRLEN(lp->ll_name),
Karsten Hopp c38828
! 						 &tv, &di, TRUE, FALSE) == OK)
Karsten Hopp c38828
  		{
Karsten Hopp c38828
! 		    if ((di == NULL
Karsten Hopp c38828
! 			   || (!var_check_ro(di->di_flags, lp->ll_name, FALSE)
Karsten Hopp c38828
! 			      && !tv_check_lock(di->di_tv.v_lock, lp->ll_name,
Karsten Hopp c38828
! 								      FALSE)))
Karsten Hopp c38828
! 			    && tv_op(&tv, rettv, op) == OK)
Karsten Hopp c38828
  			set_var(lp->ll_name, &tv, FALSE);
Karsten Hopp c38828
  		    clear_tv(&tv;;
Karsten Hopp c38828
  		}
Karsten Hopp c38828
***************
Karsten Hopp c38828
*** 5246,5252 ****
Karsten Hopp c38828
  		}
Karsten Hopp c38828
  	    }
Karsten Hopp c38828
  	    else if (evaluate)
Karsten Hopp c38828
! 		ret = get_var_tv(s, len, rettv, TRUE, FALSE);
Karsten Hopp c38828
  	    else
Karsten Hopp c38828
  		ret = OK;
Karsten Hopp c38828
  	}
Karsten Hopp c38828
--- 5251,5257 ----
Karsten Hopp c38828
  		}
Karsten Hopp c38828
  	    }
Karsten Hopp c38828
  	    else if (evaluate)
Karsten Hopp c38828
! 		ret = get_var_tv(s, len, rettv, NULL, TRUE, FALSE);
Karsten Hopp c38828
  	    else
Karsten Hopp c38828
  		ret = OK;
Karsten Hopp c38828
  	}
Karsten Hopp c38828
***************
Karsten Hopp c38828
*** 10375,10381 ****
Karsten Hopp c38828
  	{
Karsten Hopp c38828
  	    if (tofree != NULL)
Karsten Hopp c38828
  		name = tofree;
Karsten Hopp c38828
! 	    n = (get_var_tv(name, len, &tv, FALSE, TRUE) == OK);
Karsten Hopp c38828
  	    if (n)
Karsten Hopp c38828
  	    {
Karsten Hopp c38828
  		/* handle d.key, l[idx], f(expr) */
Karsten Hopp c38828
--- 10380,10386 ----
Karsten Hopp c38828
  	{
Karsten Hopp c38828
  	    if (tofree != NULL)
Karsten Hopp c38828
  		name = tofree;
Karsten Hopp c38828
! 	    n = (get_var_tv(name, len, &tv, NULL, FALSE, TRUE) == OK);
Karsten Hopp c38828
  	    if (n)
Karsten Hopp c38828
  	    {
Karsten Hopp c38828
  		/* handle d.key, l[idx], f(expr) */
Karsten Hopp c38828
***************
Karsten Hopp c38828
*** 20646,20655 ****
Karsten Hopp c38828
   * Return OK or FAIL.
Karsten Hopp c38828
   */
Karsten Hopp c38828
      static int
Karsten Hopp c38828
! get_var_tv(name, len, rettv, verbose, no_autoload)
Karsten Hopp c38828
      char_u	*name;
Karsten Hopp c38828
      int		len;		/* length of "name" */
Karsten Hopp c38828
      typval_T	*rettv;		/* NULL when only checking existence */
Karsten Hopp c38828
      int		verbose;	/* may give error message */
Karsten Hopp c38828
      int		no_autoload;	/* do not use script autoloading */
Karsten Hopp c38828
  {
Karsten Hopp c38828
--- 20651,20661 ----
Karsten Hopp c38828
   * Return OK or FAIL.
Karsten Hopp c38828
   */
Karsten Hopp c38828
      static int
Karsten Hopp c38828
! get_var_tv(name, len, rettv, dip, verbose, no_autoload)
Karsten Hopp c38828
      char_u	*name;
Karsten Hopp c38828
      int		len;		/* length of "name" */
Karsten Hopp c38828
      typval_T	*rettv;		/* NULL when only checking existence */
Karsten Hopp c38828
+     dictitem_T	**dip;		/* non-NULL when typval's dict item is needed */
Karsten Hopp c38828
      int		verbose;	/* may give error message */
Karsten Hopp c38828
      int		no_autoload;	/* do not use script autoloading */
Karsten Hopp c38828
  {
Karsten Hopp c38828
***************
Karsten Hopp c38828
*** 20680,20686 ****
Karsten Hopp c38828
--- 20686,20696 ----
Karsten Hopp c38828
      {
Karsten Hopp c38828
  	v = find_var(name, NULL, no_autoload);
Karsten Hopp c38828
  	if (v != NULL)
Karsten Hopp c38828
+ 	{
Karsten Hopp c38828
  	    tv = &v->di_tv;
Karsten Hopp c38828
+ 	    if (dip != NULL)
Karsten Hopp c38828
+ 		*dip = v;
Karsten Hopp c38828
+ 	}
Karsten Hopp c38828
      }
Karsten Hopp c38828
  
Karsten Hopp c38828
      if (tv == NULL)
Karsten Hopp c38828
***************
Karsten Hopp c38828
*** 21474,21481 ****
Karsten Hopp c38828
  	}
Karsten Hopp c38828
  
Karsten Hopp c38828
  	/*
Karsten Hopp c38828
! 	 * Handle setting internal v: variables separately: we don't change
Karsten Hopp c38828
! 	 * the type.
Karsten Hopp c38828
  	 */
Karsten Hopp c38828
  	if (ht == &vimvarht)
Karsten Hopp c38828
  	{
Karsten Hopp c38828
--- 21484,21491 ----
Karsten Hopp c38828
  	}
Karsten Hopp c38828
  
Karsten Hopp c38828
  	/*
Karsten Hopp c38828
! 	 * Handle setting internal v: variables separately where needed to
Karsten Hopp c38828
! 	 * prevent changing the type.
Karsten Hopp c38828
  	 */
Karsten Hopp c38828
  	if (ht == &vimvarht)
Karsten Hopp c38828
  	{
Karsten Hopp c38828
***************
Karsten Hopp c38828
*** 21490,21499 ****
Karsten Hopp c38828
  		    v->di_tv.vval.v_string = tv->vval.v_string;
Karsten Hopp c38828
  		    tv->vval.v_string = NULL;
Karsten Hopp c38828
  		}
Karsten Hopp c38828
  	    }
Karsten Hopp c38828
! 	    else if (v->di_tv.v_type != VAR_NUMBER)
Karsten Hopp c38828
! 		EMSG2(_(e_intern2), "set_var()");
Karsten Hopp c38828
! 	    else
Karsten Hopp c38828
  	    {
Karsten Hopp c38828
  		v->di_tv.vval.v_number = get_tv_number(tv);
Karsten Hopp c38828
  		if (STRCMP(varname, "searchforward") == 0)
Karsten Hopp c38828
--- 21500,21508 ----
Karsten Hopp c38828
  		    v->di_tv.vval.v_string = tv->vval.v_string;
Karsten Hopp c38828
  		    tv->vval.v_string = NULL;
Karsten Hopp c38828
  		}
Karsten Hopp c38828
+ 		return;
Karsten Hopp c38828
  	    }
Karsten Hopp c38828
! 	    else if (v->di_tv.v_type == VAR_NUMBER)
Karsten Hopp c38828
  	    {
Karsten Hopp c38828
  		v->di_tv.vval.v_number = get_tv_number(tv);
Karsten Hopp c38828
  		if (STRCMP(varname, "searchforward") == 0)
Karsten Hopp c38828
***************
Karsten Hopp c38828
*** 21505,21512 ****
Karsten Hopp c38828
  		    redraw_all_later(SOME_VALID);
Karsten Hopp c38828
  		}
Karsten Hopp c38828
  #endif
Karsten Hopp c38828
  	    }
Karsten Hopp c38828
! 	    return;
Karsten Hopp c38828
  	}
Karsten Hopp c38828
  
Karsten Hopp c38828
  	clear_tv(&v->di_tv);
Karsten Hopp c38828
--- 21514,21523 ----
Karsten Hopp c38828
  		    redraw_all_later(SOME_VALID);
Karsten Hopp c38828
  		}
Karsten Hopp c38828
  #endif
Karsten Hopp c38828
+ 		return;
Karsten Hopp c38828
  	    }
Karsten Hopp c38828
! 	    else if (v->di_tv.v_type != tv->v_type)
Karsten Hopp c38828
! 		EMSG2(_(e_intern2), "set_var()");
Karsten Hopp c38828
  	}
Karsten Hopp c38828
  
Karsten Hopp c38828
  	clear_tv(&v->di_tv);
Karsten Hopp c38828
*** ../vim-7.4.716/src/testdir/test55.in	2015-04-13 16:16:31.225091428 +0200
Karsten Hopp c38828
--- src/testdir/test55.in	2015-05-04 10:52:25.892071486 +0200
Karsten Hopp c38828
***************
Karsten Hopp c38828
*** 442,447 ****
Karsten Hopp c38828
--- 442,458 ----
Karsten Hopp c38828
  :unlockvar 1 b:
Karsten Hopp c38828
  :unlet! b:testvar
Karsten Hopp c38828
  :"
Karsten Hopp c38828
+ :$put ='No :let += of locked list variable:'
Karsten Hopp c38828
+ :let l = ['a', 'b', 3]
Karsten Hopp c38828
+ :lockvar 1 l
Karsten Hopp c38828
+ :try
Karsten Hopp c38828
+ :  let l += ['x']
Karsten Hopp c38828
+ :  $put ='did :let +='
Karsten Hopp c38828
+ :catch
Karsten Hopp c38828
+ :  $put =v:exception[:14]
Karsten Hopp c38828
+ :endtry
Karsten Hopp c38828
+ :$put =string(l)
Karsten Hopp c38828
+ :"
Karsten Hopp c38828
  :unlet l
Karsten Hopp c38828
  :let l = [1, 2, 3, 4]
Karsten Hopp c38828
  :lockvar! l
Karsten Hopp c38828
*** ../vim-7.4.716/src/testdir/test55.ok	2015-04-13 16:16:31.225091428 +0200
Karsten Hopp c38828
--- src/testdir/test55.ok	2015-05-04 10:52:25.892071486 +0200
Karsten Hopp c38828
***************
Karsten Hopp c38828
*** 144,149 ****
Karsten Hopp c38828
--- 144,152 ----
Karsten Hopp c38828
  Vim(put):E742: 
Karsten Hopp c38828
  No :unlet of variable in locked scope:
Karsten Hopp c38828
  Vim(unlet):E741: 
Karsten Hopp c38828
+ No :let += of locked list variable:
Karsten Hopp c38828
+ Vim(let):E741: 
Karsten Hopp c38828
+ ['a', 'b', 3]
Karsten Hopp c38828
  [1, 2, 3, 4]
Karsten Hopp c38828
  [1, 2, 3, 4]
Karsten Hopp c38828
  [1, 2, 3, 4]
Karsten Hopp c38828
*** ../vim-7.4.716/src/version.c	2015-05-04 10:45:57.292481564 +0200
Karsten Hopp c38828
--- src/version.c	2015-05-04 10:52:38.743925636 +0200
Karsten Hopp c38828
***************
Karsten Hopp c38828
*** 743,744 ****
Karsten Hopp c38828
--- 743,746 ----
Karsten Hopp c38828
  {   /* Add new patch number below this line */
Karsten Hopp c38828
+ /**/
Karsten Hopp c38828
+     717,
Karsten Hopp c38828
  /**/
Karsten Hopp c38828
Karsten Hopp c38828
-- 
Karsten Hopp c38828
Anyone who is capable of getting themselves made President should on no
Karsten Hopp c38828
account be allowed to do the job.
Karsten Hopp c38828
		-- Douglas Adams, "The Hitchhiker's Guide to the Galaxy"
Karsten Hopp c38828
Karsten Hopp c38828
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp c38828
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp c38828
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp c38828
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///