Blame SOURCES/7.4.260

22c937
To: vim_dev@googlegroups.com
22c937
Subject: Patch 7.4.260
22c937
Fcc: outbox
22c937
From: Bram Moolenaar <Bram@moolenaar.net>
22c937
Mime-Version: 1.0
22c937
Content-Type: text/plain; charset=UTF-8
22c937
Content-Transfer-Encoding: 8bit
22c937
------------
22c937
22c937
Patch 7.4.260
22c937
Problem:    It is possible to define a function with a colon in the name.  It
22c937
	    is possible to define a function with a lower case character if a
22c937
	    "#" appears after the name.
22c937
Solution:   Disallow using a colon other than with "s:".  Ignore "#" after the
22c937
	    name.
22c937
Files:	    runtime/doc/eval.txt, src/eval.c, src/testdir/test_eval.in,
22c937
	    src/testdir/test_eval.ok
22c937
22c937
22c937
*** ../vim-7.4.259/runtime/doc/eval.txt	2014-04-05 19:44:36.891160723 +0200
22c937
--- runtime/doc/eval.txt	2014-04-23 17:19:57.914982886 +0200
22c937
***************
22c937
*** 123,128 ****
22c937
--- 123,129 ----
22c937
  	:echo Fn()
22c937
  <							*E704* *E705* *E707*
22c937
  A Funcref variable must start with a capital, "s:", "w:", "t:" or "b:".  You
22c937
+ can use "g:" but the following name must still start with a capital.  You
22c937
  cannot have both a Funcref variable and a function with the same name.
22c937
  
22c937
  A special case is defining a function and directly assigning its Funcref to a
22c937
***************
22c937
*** 6675,6680 ****
22c937
--- 6691,6698 ----
22c937
  and autocommands defined in the script.  It is also possible to call the
22c937
  function from a mapping defined in the script, but then |<SID>| must be used
22c937
  instead of "s:" when the mapping is expanded outside of the script.
22c937
+ There are only script-local functions, no buffer-local or window-local
22c937
+ functions.
22c937
  
22c937
  					*:fu* *:function* *E128* *E129* *E123*
22c937
  :fu[nction]		List all functions and their arguments.
22c937
***************
22c937
*** 6698,6708 ****
22c937
  <
22c937
  See |:verbose-cmd| for more information.
22c937
  
22c937
! 							*E124* *E125* *E853*
22c937
  :fu[nction][!] {name}([arguments]) [range] [abort] [dict]
22c937
  			Define a new function by the name {name}.  The name
22c937
  			must be made of alphanumeric characters and '_', and
22c937
! 			must start with a capital or "s:" (see above).
22c937
  
22c937
  			{name} can also be a |Dictionary| entry that is a
22c937
  			|Funcref|: >
22c937
--- 6716,6727 ----
22c937
  <
22c937
  See |:verbose-cmd| for more information.
22c937
  
22c937
! 						*E124* *E125* *E853* *E884*
22c937
  :fu[nction][!] {name}([arguments]) [range] [abort] [dict]
22c937
  			Define a new function by the name {name}.  The name
22c937
  			must be made of alphanumeric characters and '_', and
22c937
! 			must start with a capital or "s:" (see above).  Note
22c937
! 			that using "b:" or "g:" is not allowed.
22c937
  
22c937
  			{name} can also be a |Dictionary| entry that is a
22c937
  			|Funcref|: >
22c937
*** ../vim-7.4.259/src/eval.c	2014-04-11 10:22:46.288219453 +0200
22c937
--- src/eval.c	2014-04-23 17:37:23.890957682 +0200
22c937
***************
22c937
*** 808,814 ****
22c937
  static void list_func_head __ARGS((ufunc_T *fp, int indent));
22c937
  static ufunc_T *find_func __ARGS((char_u *name));
22c937
  static int function_exists __ARGS((char_u *name));
22c937
! static int builtin_function __ARGS((char_u *name));
22c937
  #ifdef FEAT_PROFILE
22c937
  static void func_do_profile __ARGS((ufunc_T *fp));
22c937
  static void prof_sort_list __ARGS((FILE *fd, ufunc_T **sorttab, int st_len, char *title, int prefer_self));
22c937
--- 808,814 ----
22c937
  static void list_func_head __ARGS((ufunc_T *fp, int indent));
22c937
  static ufunc_T *find_func __ARGS((char_u *name));
22c937
  static int function_exists __ARGS((char_u *name));
22c937
! static int builtin_function __ARGS((char_u *name, int len));
22c937
  #ifdef FEAT_PROFILE
22c937
  static void func_do_profile __ARGS((ufunc_T *fp));
22c937
  static void prof_sort_list __ARGS((FILE *fd, ufunc_T **sorttab, int st_len, char *title, int prefer_self));
22c937
***************
22c937
*** 8489,8495 ****
22c937
  	rettv->vval.v_number = 0;
22c937
  	error = ERROR_UNKNOWN;
22c937
  
22c937
! 	if (!builtin_function(fname))
22c937
  	{
22c937
  	    /*
22c937
  	     * User defined function.
22c937
--- 8489,8495 ----
22c937
  	rettv->vval.v_number = 0;
22c937
  	error = ERROR_UNKNOWN;
22c937
  
22c937
! 	if (!builtin_function(fname, -1))
22c937
  	{
22c937
  	    /*
22c937
  	     * User defined function.
22c937
***************
22c937
*** 21584,21589 ****
22c937
--- 21584,21590 ----
22c937
       * Get the function name.  There are these situations:
22c937
       * func	    normal function name
22c937
       *		    "name" == func, "fudi.fd_dict" == NULL
22c937
+      * s:func	    script-local function name
22c937
       * dict.func    new dictionary entry
22c937
       *		    "name" == NULL, "fudi.fd_dict" set,
22c937
       *		    "fudi.fd_di" == NULL, "fudi.fd_newkey" == func
22c937
***************
22c937
*** 22314,22324 ****
22c937
  	    lead += (int)STRLEN(sid_buf);
22c937
  	}
22c937
      }
22c937
!     else if (!(flags & TFN_INT) && builtin_function(lv.ll_name))
22c937
      {
22c937
! 	EMSG2(_("E128: Function name must start with a capital or contain a colon: %s"), lv.ll_name);
22c937
  	goto theend;
22c937
      }
22c937
      name = alloc((unsigned)(len + lead + 1));
22c937
      if (name != NULL)
22c937
      {
22c937
--- 22315,22338 ----
22c937
  	    lead += (int)STRLEN(sid_buf);
22c937
  	}
22c937
      }
22c937
!     else if (!(flags & TFN_INT) && builtin_function(lv.ll_name, len))
22c937
      {
22c937
! 	EMSG2(_("E128: Function name must start with a capital or \"s:\": %s"),
22c937
! 								  lv.ll_name);
22c937
  	goto theend;
22c937
      }
22c937
+     if (!skip)
22c937
+     {
22c937
+ 	char_u *cp = vim_strchr(lv.ll_name, ':');
22c937
+ 
22c937
+ 	if (cp != NULL && cp < end)
22c937
+ 	{
22c937
+ 	    EMSG2(_("E884: Function name cannot contain a colon: %s"),
22c937
+ 								  lv.ll_name);
22c937
+ 	    goto theend;
22c937
+ 	}
22c937
+     }
22c937
+ 
22c937
      name = alloc((unsigned)(len + lead + 1));
22c937
      if (name != NULL)
22c937
      {
22c937
***************
22c937
*** 22331,22337 ****
22c937
  		STRCPY(name + 3, sid_buf);
22c937
  	}
22c937
  	mch_memmove(name + lead, lv.ll_name, (size_t)len);
22c937
! 	name[len + lead] = NUL;
22c937
      }
22c937
      *pp = end;
22c937
  
22c937
--- 22345,22351 ----
22c937
  		STRCPY(name + 3, sid_buf);
22c937
  	}
22c937
  	mch_memmove(name + lead, lv.ll_name, (size_t)len);
22c937
! 	name[lead + len] = NUL;
22c937
      }
22c937
      *pp = end;
22c937
  
22c937
***************
22c937
*** 22452,22458 ****
22c937
  translated_function_exists(name)
22c937
      char_u	*name;
22c937
  {
22c937
!     if (builtin_function(name))
22c937
  	return find_internal_func(name) >= 0;
22c937
      return find_func(name) != NULL;
22c937
  }
22c937
--- 22466,22472 ----
22c937
  translated_function_exists(name)
22c937
      char_u	*name;
22c937
  {
22c937
!     if (builtin_function(name, -1))
22c937
  	return find_internal_func(name) >= 0;
22c937
      return find_func(name) != NULL;
22c937
  }
22c937
***************
22c937
*** 22500,22513 ****
22c937
  
22c937
  /*
22c937
   * Return TRUE if "name" looks like a builtin function name: starts with a
22c937
!  * lower case letter and doesn't contain a ':' or AUTOLOAD_CHAR.
22c937
   */
22c937
      static int
22c937
! builtin_function(name)
22c937
      char_u *name;
22c937
  {
22c937
!     return ASCII_ISLOWER(name[0]) && vim_strchr(name, ':') == NULL
22c937
! 				   && vim_strchr(name, AUTOLOAD_CHAR) == NULL;
22c937
  }
22c937
  
22c937
  #if defined(FEAT_PROFILE) || defined(PROTO)
22c937
--- 22514,22533 ----
22c937
  
22c937
  /*
22c937
   * Return TRUE if "name" looks like a builtin function name: starts with a
22c937
!  * lower case letter and doesn't contain AUTOLOAD_CHAR.
22c937
!  * "len" is the length of "name", or -1 for NUL terminated.
22c937
   */
22c937
      static int
22c937
! builtin_function(name, len)
22c937
      char_u *name;
22c937
+     int len;
22c937
  {
22c937
!     char_u *p;
22c937
! 
22c937
!     if (!ASCII_ISLOWER(name[0]))
22c937
! 	return FALSE;
22c937
!     p = vim_strchr(name, AUTOLOAD_CHAR);
22c937
!     return p == NULL || (len > 0 && p > name + len);
22c937
  }
22c937
  
22c937
  #if defined(FEAT_PROFILE) || defined(PROTO)
22c937
*** ../vim-7.4.259/src/testdir/test_eval.in	2014-04-05 21:28:50.667174384 +0200
22c937
--- src/testdir/test_eval.in	2014-04-23 17:35:12.086960858 +0200
22c937
***************
22c937
*** 144,149 ****
22c937
--- 144,167 ----
22c937
  :delcommand AR
22c937
  :call garbagecollect(1)
22c937
  :"
22c937
+ :" function name includes a colon
22c937
+ :try
22c937
+ :func! g:test()
22c937
+ :echo "test"
22c937
+ :endfunc
22c937
+ :catch
22c937
+ :$put =v:exception
22c937
+ :endtry
22c937
+ :"
22c937
+ :" function name folowed by #
22c937
+ :try
22c937
+ :func! test2() "#
22c937
+ :echo "test2"
22c937
+ :endfunc
22c937
+ :catch
22c937
+ :$put =v:exception
22c937
+ :endtry
22c937
+ :"
22c937
  :/^start:/+1,$wq! test.out
22c937
  :" vim: et ts=4 isk-=\: fmr=???,???
22c937
  :call getchar()
22c937
*** ../vim-7.4.259/src/testdir/test_eval.ok	2014-04-05 21:28:50.667174384 +0200
22c937
--- src/testdir/test_eval.ok	2014-04-23 17:36:34.602958870 +0200
22c937
***************
22c937
*** 335,337 ****
22c937
--- 335,339 ----
22c937
  Vim(call):E883: search pattern and expression register may not contain two or more lines
22c937
  Executing call setreg(1, ["", "", [], ""])
22c937
  Vim(call):E730: using List as a String
22c937
+ Vim(function):E128: Function name must start with a capital or "s:": g:test()
22c937
+ Vim(function):E128: Function name must start with a capital or "s:": test2() "#
22c937
*** ../vim-7.4.259/src/version.c	2014-04-23 12:52:36.499369426 +0200
22c937
--- src/version.c	2014-04-23 17:17:50.994985945 +0200
22c937
***************
22c937
*** 736,737 ****
22c937
--- 736,739 ----
22c937
  {   /* Add new patch number below this line */
22c937
+ /**/
22c937
+     260,
22c937
  /**/
22c937
22c937
-- 
22c937
From "know your smileys":
22c937
 ;-0	Can't find shift key
22c937
 ,-9	Kann Umschalttaste nicht finden
22c937
22c937
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
22c937
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
22c937
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
22c937
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///