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