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