Karsten Hopp c2623c
To: vim-dev@vim.org
Karsten Hopp c2623c
Subject: Patch 7.2.070
Karsten Hopp c2623c
Fcc: outbox
Karsten Hopp c2623c
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp c2623c
Mime-Version: 1.0
Karsten Hopp c2623c
Content-Type: text/plain; charset=ISO-8859-1
Karsten Hopp c2623c
Content-Transfer-Encoding: 8bit
Karsten Hopp c2623c
------------
Karsten Hopp c2623c
Karsten Hopp c2623c
Patch 7.2.070
Karsten Hopp c2623c
Problem:    Crash when a function returns a:000. (Matt Wozkiski)
Karsten Hopp c2623c
Solution:   Don't put the function struct on the stack, allocate it.  Free it
Karsten Hopp c2623c
	    only when nothing in it is used.
Karsten Hopp c2623c
Files:	    src/eval.c
Karsten Hopp c2623c
Karsten Hopp c2623c
Karsten Hopp c2623c
*** ../vim-7.2.069/src/eval.c	Tue Dec  9 10:56:50 2008
Karsten Hopp c2623c
--- src/eval.c	Wed Dec 17 21:32:26 2008
Karsten Hopp c2623c
***************
Karsten Hopp c2623c
*** 32,37 ****
Karsten Hopp c2623c
--- 32,40 ----
Karsten Hopp c2623c
  
Karsten Hopp c2623c
  #define DICT_MAXNEST 100	/* maximum nesting of lists and dicts */
Karsten Hopp c2623c
  
Karsten Hopp c2623c
+ #define DO_NOT_FREE_CNT 99999	/* refcount for dict or list that should not
Karsten Hopp c2623c
+ 				   be freed. */
Karsten Hopp c2623c
+ 
Karsten Hopp c2623c
  /*
Karsten Hopp c2623c
   * In a hashtab item "hi_key" points to "di_key" in a dictitem.
Karsten Hopp c2623c
   * This avoids adding a pointer to the hashtab item.
Karsten Hopp c2623c
***************
Karsten Hopp c2623c
*** 789,794 ****
Karsten Hopp c2623c
--- 792,799 ----
Karsten Hopp c2623c
  static void func_unref __ARGS((char_u *name));
Karsten Hopp c2623c
  static void func_ref __ARGS((char_u *name));
Karsten Hopp c2623c
  static void call_user_func __ARGS((ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rettv, linenr_T firstline, linenr_T lastline, dict_T *selfdict));
Karsten Hopp c2623c
+ static int can_free_funccal __ARGS((funccall_T *fc, int copyID)) ;
Karsten Hopp c2623c
+ static void free_funccal __ARGS((funccall_T *fc, int free_val));
Karsten Hopp c2623c
  static void add_nr_var __ARGS((dict_T *dp, dictitem_T *v, char *name, varnumber_T nr));
Karsten Hopp c2623c
  static win_T *find_win_by_nr __ARGS((typval_T *vp, tabpage_T *tp));
Karsten Hopp c2623c
  static void getwinvar __ARGS((typval_T *argvars, typval_T *rettv, int off));
Karsten Hopp c2623c
***************
Karsten Hopp c2623c
*** 923,928 ****
Karsten Hopp c2623c
--- 928,937 ----
Karsten Hopp c2623c
  /* pointer to funccal for currently active function */
Karsten Hopp c2623c
  funccall_T *current_funccal = NULL;
Karsten Hopp c2623c
  
Karsten Hopp c2623c
+ /* pointer to list of previously used funccal, still around because some
Karsten Hopp c2623c
+  * item in it is still being used. */
Karsten Hopp c2623c
+ funccall_T *previous_funccal = NULL;
Karsten Hopp c2623c
+ 
Karsten Hopp c2623c
  /*
Karsten Hopp c2623c
   * Return TRUE when a function was ended by a ":return" command.
Karsten Hopp c2623c
   */
Karsten Hopp c2623c
***************
Karsten Hopp c2623c
*** 6490,6496 ****
Karsten Hopp c2623c
      buf_T	*buf;
Karsten Hopp c2623c
      win_T	*wp;
Karsten Hopp c2623c
      int		i;
Karsten Hopp c2623c
!     funccall_T	*fc;
Karsten Hopp c2623c
      int		did_free = FALSE;
Karsten Hopp c2623c
  #ifdef FEAT_WINDOWS
Karsten Hopp c2623c
      tabpage_T	*tp;
Karsten Hopp c2623c
--- 6499,6505 ----
Karsten Hopp c2623c
      buf_T	*buf;
Karsten Hopp c2623c
      win_T	*wp;
Karsten Hopp c2623c
      int		i;
Karsten Hopp c2623c
!     funccall_T	*fc, **pfc;
Karsten Hopp c2623c
      int		did_free = FALSE;
Karsten Hopp c2623c
  #ifdef FEAT_WINDOWS
Karsten Hopp c2623c
      tabpage_T	*tp;
Karsten Hopp c2623c
***************
Karsten Hopp c2623c
*** 6574,6579 ****
Karsten Hopp c2623c
--- 6583,6602 ----
Karsten Hopp c2623c
  	else
Karsten Hopp c2623c
  	    ll = ll->lv_used_next;
Karsten Hopp c2623c
  
Karsten Hopp c2623c
+     /* check if any funccal can be freed now */
Karsten Hopp c2623c
+     for (pfc = &previous_funccal; *pfc != NULL; )
Karsten Hopp c2623c
+     {
Karsten Hopp c2623c
+ 	if (can_free_funccal(*pfc, copyID))
Karsten Hopp c2623c
+ 	{
Karsten Hopp c2623c
+ 	    fc = *pfc;
Karsten Hopp c2623c
+ 	    *pfc = fc->caller;
Karsten Hopp c2623c
+ 	    free_funccal(fc, TRUE);
Karsten Hopp c2623c
+ 	    did_free = TRUE;
Karsten Hopp c2623c
+ 	}
Karsten Hopp c2623c
+ 	else
Karsten Hopp c2623c
+ 	    pfc = &(*pfc)->caller;
Karsten Hopp c2623c
+     }
Karsten Hopp c2623c
+ 
Karsten Hopp c2623c
      return did_free;
Karsten Hopp c2623c
  }
Karsten Hopp c2623c
  
Karsten Hopp c2623c
***************
Karsten Hopp c2623c
*** 18962,18968 ****
Karsten Hopp c2623c
      dictitem_T	*dict_var;
Karsten Hopp c2623c
  {
Karsten Hopp c2623c
      hash_init(&dict->dv_hashtab);
Karsten Hopp c2623c
!     dict->dv_refcount = 99999;
Karsten Hopp c2623c
      dict_var->di_tv.vval.v_dict = dict;
Karsten Hopp c2623c
      dict_var->di_tv.v_type = VAR_DICT;
Karsten Hopp c2623c
      dict_var->di_tv.v_lock = VAR_FIXED;
Karsten Hopp c2623c
--- 18985,18991 ----
Karsten Hopp c2623c
      dictitem_T	*dict_var;
Karsten Hopp c2623c
  {
Karsten Hopp c2623c
      hash_init(&dict->dv_hashtab);
Karsten Hopp c2623c
!     dict->dv_refcount = DO_NOT_FREE_CNT;
Karsten Hopp c2623c
      dict_var->di_tv.vval.v_dict = dict;
Karsten Hopp c2623c
      dict_var->di_tv.v_type = VAR_DICT;
Karsten Hopp c2623c
      dict_var->di_tv.v_lock = VAR_FIXED;
Karsten Hopp c2623c
***************
Karsten Hopp c2623c
*** 19299,19304 ****
Karsten Hopp c2623c
--- 19322,19329 ----
Karsten Hopp c2623c
   * Copy the values from typval_T "from" to typval_T "to".
Karsten Hopp c2623c
   * When needed allocates string or increases reference count.
Karsten Hopp c2623c
   * Does not make a copy of a list or dict but copies the reference!
Karsten Hopp c2623c
+  * It is OK for "from" and "to" to point to the same item.  This is used to
Karsten Hopp c2623c
+  * make a copy later.
Karsten Hopp c2623c
   */
Karsten Hopp c2623c
      static void
Karsten Hopp c2623c
  copy_tv(from, to)
Karsten Hopp c2623c
***************
Karsten Hopp c2623c
*** 21111,21117 ****
Karsten Hopp c2623c
      char_u	*save_sourcing_name;
Karsten Hopp c2623c
      linenr_T	save_sourcing_lnum;
Karsten Hopp c2623c
      scid_T	save_current_SID;
Karsten Hopp c2623c
!     funccall_T	fc;
Karsten Hopp c2623c
      int		save_did_emsg;
Karsten Hopp c2623c
      static int	depth = 0;
Karsten Hopp c2623c
      dictitem_T	*v;
Karsten Hopp c2623c
--- 21136,21142 ----
Karsten Hopp c2623c
      char_u	*save_sourcing_name;
Karsten Hopp c2623c
      linenr_T	save_sourcing_lnum;
Karsten Hopp c2623c
      scid_T	save_current_SID;
Karsten Hopp c2623c
!     funccall_T	*fc;
Karsten Hopp c2623c
      int		save_did_emsg;
Karsten Hopp c2623c
      static int	depth = 0;
Karsten Hopp c2623c
      dictitem_T	*v;
Karsten Hopp c2623c
***************
Karsten Hopp c2623c
*** 21137,21172 ****
Karsten Hopp c2623c
  
Karsten Hopp c2623c
      line_breakcheck();		/* check for CTRL-C hit */
Karsten Hopp c2623c
  
Karsten Hopp c2623c
!     fc.caller = current_funccal;
Karsten Hopp c2623c
!     current_funccal = &fc;
Karsten Hopp c2623c
!     fc.func = fp;
Karsten Hopp c2623c
!     fc.rettv = rettv;
Karsten Hopp c2623c
      rettv->vval.v_number = 0;
Karsten Hopp c2623c
!     fc.linenr = 0;
Karsten Hopp c2623c
!     fc.returned = FALSE;
Karsten Hopp c2623c
!     fc.level = ex_nesting_level;
Karsten Hopp c2623c
      /* Check if this function has a breakpoint. */
Karsten Hopp c2623c
!     fc.breakpoint = dbg_find_breakpoint(FALSE, fp->uf_name, (linenr_T)0);
Karsten Hopp c2623c
!     fc.dbg_tick = debug_tick;
Karsten Hopp c2623c
  
Karsten Hopp c2623c
      /*
Karsten Hopp c2623c
!      * Note about using fc.fixvar[]: This is an array of FIXVAR_CNT variables
Karsten Hopp c2623c
       * with names up to VAR_SHORT_LEN long.  This avoids having to alloc/free
Karsten Hopp c2623c
       * each argument variable and saves a lot of time.
Karsten Hopp c2623c
       */
Karsten Hopp c2623c
      /*
Karsten Hopp c2623c
       * Init l: variables.
Karsten Hopp c2623c
       */
Karsten Hopp c2623c
!     init_var_dict(&fc.l_vars, &fc.l_vars_var);
Karsten Hopp c2623c
      if (selfdict != NULL)
Karsten Hopp c2623c
      {
Karsten Hopp c2623c
  	/* Set l:self to "selfdict".  Use "name" to avoid a warning from
Karsten Hopp c2623c
  	 * some compiler that checks the destination size. */
Karsten Hopp c2623c
! 	v = &fc.fixvar[fixvar_idx++].var;
Karsten Hopp c2623c
  	name = v->di_key;
Karsten Hopp c2623c
  	STRCPY(name, "self");
Karsten Hopp c2623c
  	v->di_flags = DI_FLAGS_RO + DI_FLAGS_FIX;
Karsten Hopp c2623c
! 	hash_add(&fc.l_vars.dv_hashtab, DI2HIKEY(v));
Karsten Hopp c2623c
  	v->di_tv.v_type = VAR_DICT;
Karsten Hopp c2623c
  	v->di_tv.v_lock = 0;
Karsten Hopp c2623c
  	v->di_tv.vval.v_dict = selfdict;
Karsten Hopp c2623c
--- 21162,21198 ----
Karsten Hopp c2623c
  
Karsten Hopp c2623c
      line_breakcheck();		/* check for CTRL-C hit */
Karsten Hopp c2623c
  
Karsten Hopp c2623c
!     fc = (funccall_T *)alloc(sizeof(funccall_T));
Karsten Hopp c2623c
!     fc->caller = current_funccal;
Karsten Hopp c2623c
!     current_funccal = fc;
Karsten Hopp c2623c
!     fc->func = fp;
Karsten Hopp c2623c
!     fc->rettv = rettv;
Karsten Hopp c2623c
      rettv->vval.v_number = 0;
Karsten Hopp c2623c
!     fc->linenr = 0;
Karsten Hopp c2623c
!     fc->returned = FALSE;
Karsten Hopp c2623c
!     fc->level = ex_nesting_level;
Karsten Hopp c2623c
      /* Check if this function has a breakpoint. */
Karsten Hopp c2623c
!     fc->breakpoint = dbg_find_breakpoint(FALSE, fp->uf_name, (linenr_T)0);
Karsten Hopp c2623c
!     fc->dbg_tick = debug_tick;
Karsten Hopp c2623c
  
Karsten Hopp c2623c
      /*
Karsten Hopp c2623c
!      * Note about using fc->fixvar[]: This is an array of FIXVAR_CNT variables
Karsten Hopp c2623c
       * with names up to VAR_SHORT_LEN long.  This avoids having to alloc/free
Karsten Hopp c2623c
       * each argument variable and saves a lot of time.
Karsten Hopp c2623c
       */
Karsten Hopp c2623c
      /*
Karsten Hopp c2623c
       * Init l: variables.
Karsten Hopp c2623c
       */
Karsten Hopp c2623c
!     init_var_dict(&fc->l_vars, &fc->l_vars_var);
Karsten Hopp c2623c
      if (selfdict != NULL)
Karsten Hopp c2623c
      {
Karsten Hopp c2623c
  	/* Set l:self to "selfdict".  Use "name" to avoid a warning from
Karsten Hopp c2623c
  	 * some compiler that checks the destination size. */
Karsten Hopp c2623c
! 	v = &fc->fixvar[fixvar_idx++].var;
Karsten Hopp c2623c
  	name = v->di_key;
Karsten Hopp c2623c
  	STRCPY(name, "self");
Karsten Hopp c2623c
  	v->di_flags = DI_FLAGS_RO + DI_FLAGS_FIX;
Karsten Hopp c2623c
! 	hash_add(&fc->l_vars.dv_hashtab, DI2HIKEY(v));
Karsten Hopp c2623c
  	v->di_tv.v_type = VAR_DICT;
Karsten Hopp c2623c
  	v->di_tv.v_lock = 0;
Karsten Hopp c2623c
  	v->di_tv.vval.v_dict = selfdict;
Karsten Hopp c2623c
***************
Karsten Hopp c2623c
*** 21178,21208 ****
Karsten Hopp c2623c
       * Set a:0 to "argcount".
Karsten Hopp c2623c
       * Set a:000 to a list with room for the "..." arguments.
Karsten Hopp c2623c
       */
Karsten Hopp c2623c
!     init_var_dict(&fc.l_avars, &fc.l_avars_var);
Karsten Hopp c2623c
!     add_nr_var(&fc.l_avars, &fc.fixvar[fixvar_idx++].var, "0",
Karsten Hopp c2623c
  				(varnumber_T)(argcount - fp->uf_args.ga_len));
Karsten Hopp c2623c
      /* Use "name" to avoid a warning from some compiler that checks the
Karsten Hopp c2623c
       * destination size. */
Karsten Hopp c2623c
!     v = &fc.fixvar[fixvar_idx++].var;
Karsten Hopp c2623c
      name = v->di_key;
Karsten Hopp c2623c
      STRCPY(name, "000");
Karsten Hopp c2623c
      v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX;
Karsten Hopp c2623c
!     hash_add(&fc.l_avars.dv_hashtab, DI2HIKEY(v));
Karsten Hopp c2623c
      v->di_tv.v_type = VAR_LIST;
Karsten Hopp c2623c
      v->di_tv.v_lock = VAR_FIXED;
Karsten Hopp c2623c
!     v->di_tv.vval.v_list = &fc.l_varlist;
Karsten Hopp c2623c
!     vim_memset(&fc.l_varlist, 0, sizeof(list_T));
Karsten Hopp c2623c
!     fc.l_varlist.lv_refcount = 99999;
Karsten Hopp c2623c
!     fc.l_varlist.lv_lock = VAR_FIXED;
Karsten Hopp c2623c
  
Karsten Hopp c2623c
      /*
Karsten Hopp c2623c
       * Set a:firstline to "firstline" and a:lastline to "lastline".
Karsten Hopp c2623c
       * Set a:name to named arguments.
Karsten Hopp c2623c
       * Set a:N to the "..." arguments.
Karsten Hopp c2623c
       */
Karsten Hopp c2623c
!     add_nr_var(&fc.l_avars, &fc.fixvar[fixvar_idx++].var, "firstline",
Karsten Hopp c2623c
  						      (varnumber_T)firstline);
Karsten Hopp c2623c
!     add_nr_var(&fc.l_avars, &fc.fixvar[fixvar_idx++].var, "lastline",
Karsten Hopp c2623c
  						       (varnumber_T)lastline);
Karsten Hopp c2623c
      for (i = 0; i < argcount; ++i)
Karsten Hopp c2623c
      {
Karsten Hopp c2623c
--- 21204,21234 ----
Karsten Hopp c2623c
       * Set a:0 to "argcount".
Karsten Hopp c2623c
       * Set a:000 to a list with room for the "..." arguments.
Karsten Hopp c2623c
       */
Karsten Hopp c2623c
!     init_var_dict(&fc->l_avars, &fc->l_avars_var);
Karsten Hopp c2623c
!     add_nr_var(&fc->l_avars, &fc->fixvar[fixvar_idx++].var, "0",
Karsten Hopp c2623c
  				(varnumber_T)(argcount - fp->uf_args.ga_len));
Karsten Hopp c2623c
      /* Use "name" to avoid a warning from some compiler that checks the
Karsten Hopp c2623c
       * destination size. */
Karsten Hopp c2623c
!     v = &fc->fixvar[fixvar_idx++].var;
Karsten Hopp c2623c
      name = v->di_key;
Karsten Hopp c2623c
      STRCPY(name, "000");
Karsten Hopp c2623c
      v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX;
Karsten Hopp c2623c
!     hash_add(&fc->l_avars.dv_hashtab, DI2HIKEY(v));
Karsten Hopp c2623c
      v->di_tv.v_type = VAR_LIST;
Karsten Hopp c2623c
      v->di_tv.v_lock = VAR_FIXED;
Karsten Hopp c2623c
!     v->di_tv.vval.v_list = &fc->l_varlist;
Karsten Hopp c2623c
!     vim_memset(&fc->l_varlist, 0, sizeof(list_T));
Karsten Hopp c2623c
!     fc->l_varlist.lv_refcount = DO_NOT_FREE_CNT;
Karsten Hopp c2623c
!     fc->l_varlist.lv_lock = VAR_FIXED;
Karsten Hopp c2623c
  
Karsten Hopp c2623c
      /*
Karsten Hopp c2623c
       * Set a:firstline to "firstline" and a:lastline to "lastline".
Karsten Hopp c2623c
       * Set a:name to named arguments.
Karsten Hopp c2623c
       * Set a:N to the "..." arguments.
Karsten Hopp c2623c
       */
Karsten Hopp c2623c
!     add_nr_var(&fc->l_avars, &fc->fixvar[fixvar_idx++].var, "firstline",
Karsten Hopp c2623c
  						      (varnumber_T)firstline);
Karsten Hopp c2623c
!     add_nr_var(&fc->l_avars, &fc->fixvar[fixvar_idx++].var, "lastline",
Karsten Hopp c2623c
  						       (varnumber_T)lastline);
Karsten Hopp c2623c
      for (i = 0; i < argcount; ++i)
Karsten Hopp c2623c
      {
Karsten Hopp c2623c
***************
Karsten Hopp c2623c
*** 21218,21224 ****
Karsten Hopp c2623c
  	}
Karsten Hopp c2623c
  	if (fixvar_idx < FIXVAR_CNT && STRLEN(name) <= VAR_SHORT_LEN)
Karsten Hopp c2623c
  	{
Karsten Hopp c2623c
! 	    v = &fc.fixvar[fixvar_idx++].var;
Karsten Hopp c2623c
  	    v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX;
Karsten Hopp c2623c
  	}
Karsten Hopp c2623c
  	else
Karsten Hopp c2623c
--- 21244,21250 ----
Karsten Hopp c2623c
  	}
Karsten Hopp c2623c
  	if (fixvar_idx < FIXVAR_CNT && STRLEN(name) <= VAR_SHORT_LEN)
Karsten Hopp c2623c
  	{
Karsten Hopp c2623c
! 	    v = &fc->fixvar[fixvar_idx++].var;
Karsten Hopp c2623c
  	    v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX;
Karsten Hopp c2623c
  	}
Karsten Hopp c2623c
  	else
Karsten Hopp c2623c
***************
Karsten Hopp c2623c
*** 21230,21236 ****
Karsten Hopp c2623c
  	    v->di_flags = DI_FLAGS_RO;
Karsten Hopp c2623c
  	}
Karsten Hopp c2623c
  	STRCPY(v->di_key, name);
Karsten Hopp c2623c
! 	hash_add(&fc.l_avars.dv_hashtab, DI2HIKEY(v));
Karsten Hopp c2623c
  
Karsten Hopp c2623c
  	/* Note: the values are copied directly to avoid alloc/free.
Karsten Hopp c2623c
  	 * "argvars" must have VAR_FIXED for v_lock. */
Karsten Hopp c2623c
--- 21256,21262 ----
Karsten Hopp c2623c
  	    v->di_flags = DI_FLAGS_RO;
Karsten Hopp c2623c
  	}
Karsten Hopp c2623c
  	STRCPY(v->di_key, name);
Karsten Hopp c2623c
! 	hash_add(&fc->l_avars.dv_hashtab, DI2HIKEY(v));
Karsten Hopp c2623c
  
Karsten Hopp c2623c
  	/* Note: the values are copied directly to avoid alloc/free.
Karsten Hopp c2623c
  	 * "argvars" must have VAR_FIXED for v_lock. */
Karsten Hopp c2623c
***************
Karsten Hopp c2623c
*** 21239,21247 ****
Karsten Hopp c2623c
  
Karsten Hopp c2623c
  	if (ai >= 0 && ai < MAX_FUNC_ARGS)
Karsten Hopp c2623c
  	{
Karsten Hopp c2623c
! 	    list_append(&fc.l_varlist, &fc.l_listitems[ai]);
Karsten Hopp c2623c
! 	    fc.l_listitems[ai].li_tv = argvars[i];
Karsten Hopp c2623c
! 	    fc.l_listitems[ai].li_tv.v_lock = VAR_FIXED;
Karsten Hopp c2623c
  	}
Karsten Hopp c2623c
      }
Karsten Hopp c2623c
  
Karsten Hopp c2623c
--- 21265,21273 ----
Karsten Hopp c2623c
  
Karsten Hopp c2623c
  	if (ai >= 0 && ai < MAX_FUNC_ARGS)
Karsten Hopp c2623c
  	{
Karsten Hopp c2623c
! 	    list_append(&fc->l_varlist, &fc->l_listitems[ai]);
Karsten Hopp c2623c
! 	    fc->l_listitems[ai].li_tv = argvars[i];
Karsten Hopp c2623c
! 	    fc->l_listitems[ai].li_tv.v_lock = VAR_FIXED;
Karsten Hopp c2623c
  	}
Karsten Hopp c2623c
      }
Karsten Hopp c2623c
  
Karsten Hopp c2623c
***************
Karsten Hopp c2623c
*** 21306,21312 ****
Karsten Hopp c2623c
  	if (!fp->uf_profiling && has_profiling(FALSE, fp->uf_name, NULL))
Karsten Hopp c2623c
  	    func_do_profile(fp);
Karsten Hopp c2623c
  	if (fp->uf_profiling
Karsten Hopp c2623c
! 		       || (fc.caller != NULL && fc.caller->func->uf_profiling))
Karsten Hopp c2623c
  	{
Karsten Hopp c2623c
  	    ++fp->uf_tm_count;
Karsten Hopp c2623c
  	    profile_start(&call_start);
Karsten Hopp c2623c
--- 21332,21338 ----
Karsten Hopp c2623c
  	if (!fp->uf_profiling && has_profiling(FALSE, fp->uf_name, NULL))
Karsten Hopp c2623c
  	    func_do_profile(fp);
Karsten Hopp c2623c
  	if (fp->uf_profiling
Karsten Hopp c2623c
! 		    || (fc->caller != NULL && fc->caller->func->uf_profiling))
Karsten Hopp c2623c
  	{
Karsten Hopp c2623c
  	    ++fp->uf_tm_count;
Karsten Hopp c2623c
  	    profile_start(&call_start);
Karsten Hopp c2623c
***************
Karsten Hopp c2623c
*** 21322,21328 ****
Karsten Hopp c2623c
      did_emsg = FALSE;
Karsten Hopp c2623c
  
Karsten Hopp c2623c
      /* call do_cmdline() to execute the lines */
Karsten Hopp c2623c
!     do_cmdline(NULL, get_func_line, (void *)&fc,
Karsten Hopp c2623c
  				     DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT);
Karsten Hopp c2623c
  
Karsten Hopp c2623c
      --RedrawingDisabled;
Karsten Hopp c2623c
--- 21348,21354 ----
Karsten Hopp c2623c
      did_emsg = FALSE;
Karsten Hopp c2623c
  
Karsten Hopp c2623c
      /* call do_cmdline() to execute the lines */
Karsten Hopp c2623c
!     do_cmdline(NULL, get_func_line, (void *)fc,
Karsten Hopp c2623c
  				     DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT);
Karsten Hopp c2623c
  
Karsten Hopp c2623c
      --RedrawingDisabled;
Karsten Hopp c2623c
***************
Karsten Hopp c2623c
*** 21337,21352 ****
Karsten Hopp c2623c
  
Karsten Hopp c2623c
  #ifdef FEAT_PROFILE
Karsten Hopp c2623c
      if (do_profiling == PROF_YES && (fp->uf_profiling
Karsten Hopp c2623c
! 		    || (fc.caller != NULL && fc.caller->func->uf_profiling)))
Karsten Hopp c2623c
      {
Karsten Hopp c2623c
  	profile_end(&call_start);
Karsten Hopp c2623c
  	profile_sub_wait(&wait_start, &call_start);
Karsten Hopp c2623c
  	profile_add(&fp->uf_tm_total, &call_start);
Karsten Hopp c2623c
  	profile_self(&fp->uf_tm_self, &call_start, &fp->uf_tm_children);
Karsten Hopp c2623c
! 	if (fc.caller != NULL && fc.caller->func->uf_profiling)
Karsten Hopp c2623c
  	{
Karsten Hopp c2623c
! 	    profile_add(&fc.caller->func->uf_tm_children, &call_start);
Karsten Hopp c2623c
! 	    profile_add(&fc.caller->func->uf_tml_children, &call_start);
Karsten Hopp c2623c
  	}
Karsten Hopp c2623c
      }
Karsten Hopp c2623c
  #endif
Karsten Hopp c2623c
--- 21363,21378 ----
Karsten Hopp c2623c
  
Karsten Hopp c2623c
  #ifdef FEAT_PROFILE
Karsten Hopp c2623c
      if (do_profiling == PROF_YES && (fp->uf_profiling
Karsten Hopp c2623c
! 		    || (fc->caller != NULL && fc->caller->func->uf_profiling)))
Karsten Hopp c2623c
      {
Karsten Hopp c2623c
  	profile_end(&call_start);
Karsten Hopp c2623c
  	profile_sub_wait(&wait_start, &call_start);
Karsten Hopp c2623c
  	profile_add(&fp->uf_tm_total, &call_start);
Karsten Hopp c2623c
  	profile_self(&fp->uf_tm_self, &call_start, &fp->uf_tm_children);
Karsten Hopp c2623c
! 	if (fc->caller != NULL && fc->caller->func->uf_profiling)
Karsten Hopp c2623c
  	{
Karsten Hopp c2623c
! 	    profile_add(&fc->caller->func->uf_tm_children, &call_start);
Karsten Hopp c2623c
! 	    profile_add(&fc->caller->func->uf_tml_children, &call_start);
Karsten Hopp c2623c
  	}
Karsten Hopp c2623c
      }
Karsten Hopp c2623c
  #endif
Karsten Hopp c2623c
***************
Karsten Hopp c2623c
*** 21359,21367 ****
Karsten Hopp c2623c
  
Karsten Hopp c2623c
  	if (aborting())
Karsten Hopp c2623c
  	    smsg((char_u *)_("%s aborted"), sourcing_name);
Karsten Hopp c2623c
! 	else if (fc.rettv->v_type == VAR_NUMBER)
Karsten Hopp c2623c
  	    smsg((char_u *)_("%s returning #%ld"), sourcing_name,
Karsten Hopp c2623c
! 					       (long)fc.rettv->vval.v_number);
Karsten Hopp c2623c
  	else
Karsten Hopp c2623c
  	{
Karsten Hopp c2623c
  	    char_u	buf[MSG_BUF_LEN];
Karsten Hopp c2623c
--- 21385,21393 ----
Karsten Hopp c2623c
  
Karsten Hopp c2623c
  	if (aborting())
Karsten Hopp c2623c
  	    smsg((char_u *)_("%s aborted"), sourcing_name);
Karsten Hopp c2623c
! 	else if (fc->rettv->v_type == VAR_NUMBER)
Karsten Hopp c2623c
  	    smsg((char_u *)_("%s returning #%ld"), sourcing_name,
Karsten Hopp c2623c
! 					       (long)fc->rettv->vval.v_number);
Karsten Hopp c2623c
  	else
Karsten Hopp c2623c
  	{
Karsten Hopp c2623c
  	    char_u	buf[MSG_BUF_LEN];
Karsten Hopp c2623c
***************
Karsten Hopp c2623c
*** 21372,21378 ****
Karsten Hopp c2623c
  	    /* The value may be very long.  Skip the middle part, so that we
Karsten Hopp c2623c
  	     * have some idea how it starts and ends. smsg() would always
Karsten Hopp c2623c
  	     * truncate it at the end. */
Karsten Hopp c2623c
! 	    s = tv2string(fc.rettv, &tofree, numbuf2, 0);
Karsten Hopp c2623c
  	    if (s != NULL)
Karsten Hopp c2623c
  	    {
Karsten Hopp c2623c
  		trunc_string(s, buf, MSG_BUF_CLEN);
Karsten Hopp c2623c
--- 21398,21404 ----
Karsten Hopp c2623c
  	    /* The value may be very long.  Skip the middle part, so that we
Karsten Hopp c2623c
  	     * have some idea how it starts and ends. smsg() would always
Karsten Hopp c2623c
  	     * truncate it at the end. */
Karsten Hopp c2623c
! 	    s = tv2string(fc->rettv, &tofree, numbuf2, 0);
Karsten Hopp c2623c
  	    if (s != NULL)
Karsten Hopp c2623c
  	    {
Karsten Hopp c2623c
  		trunc_string(s, buf, MSG_BUF_CLEN);
Karsten Hopp c2623c
***************
Karsten Hopp c2623c
*** 21408,21421 ****
Karsten Hopp c2623c
      }
Karsten Hopp c2623c
  
Karsten Hopp c2623c
      did_emsg |= save_did_emsg;
Karsten Hopp c2623c
!     current_funccal = fc.caller;
Karsten Hopp c2623c
  
Karsten Hopp c2623c
!     /* The a: variables typevals were not allocated, only free the allocated
Karsten Hopp c2623c
!      * variables. */
Karsten Hopp c2623c
!     vars_clear_ext(&fc.l_avars.dv_hashtab, FALSE);
Karsten Hopp c2623c
  
Karsten Hopp c2623c
!     vars_clear(&fc.l_vars.dv_hashtab);		/* free all l: variables */
Karsten Hopp c2623c
!     --depth;
Karsten Hopp c2623c
  }
Karsten Hopp c2623c
  
Karsten Hopp c2623c
  /*
Karsten Hopp c2623c
--- 21434,21517 ----
Karsten Hopp c2623c
      }
Karsten Hopp c2623c
  
Karsten Hopp c2623c
      did_emsg |= save_did_emsg;
Karsten Hopp c2623c
!     current_funccal = fc->caller;
Karsten Hopp c2623c
!     --depth;
Karsten Hopp c2623c
  
Karsten Hopp c2623c
!     /* if the a:000 list and the a: dict are not referenced we can free the
Karsten Hopp c2623c
!      * funccall_T and what's in it. */
Karsten Hopp c2623c
!     if (fc->l_varlist.lv_refcount == DO_NOT_FREE_CNT
Karsten Hopp c2623c
! 	    && fc->l_vars.dv_refcount == DO_NOT_FREE_CNT
Karsten Hopp c2623c
! 	    && fc->l_avars.dv_refcount == DO_NOT_FREE_CNT)
Karsten Hopp c2623c
!     {
Karsten Hopp c2623c
! 	free_funccal(fc, FALSE);
Karsten Hopp c2623c
!     }
Karsten Hopp c2623c
!     else
Karsten Hopp c2623c
!     {
Karsten Hopp c2623c
! 	hashitem_T	*hi;
Karsten Hopp c2623c
! 	listitem_T	*li;
Karsten Hopp c2623c
! 	int		todo;
Karsten Hopp c2623c
  
Karsten Hopp c2623c
! 	/* "fc" is still in use.  This can happen when returning "a:000" or
Karsten Hopp c2623c
! 	 * assigning "l:" to a global variable.
Karsten Hopp c2623c
! 	 * Link "fc" in the list for garbage collection later. */
Karsten Hopp c2623c
! 	fc->caller = previous_funccal;
Karsten Hopp c2623c
! 	previous_funccal = fc;
Karsten Hopp c2623c
! 
Karsten Hopp c2623c
! 	/* Make a copy of the a: variables, since we didn't do that above. */
Karsten Hopp c2623c
! 	todo = (int)fc->l_avars.dv_hashtab.ht_used;
Karsten Hopp c2623c
! 	for (hi = fc->l_avars.dv_hashtab.ht_array; todo > 0; ++hi)
Karsten Hopp c2623c
! 	{
Karsten Hopp c2623c
! 	    if (!HASHITEM_EMPTY(hi))
Karsten Hopp c2623c
! 	    {
Karsten Hopp c2623c
! 		--todo;
Karsten Hopp c2623c
! 		v = HI2DI(hi);
Karsten Hopp c2623c
! 		copy_tv(&v->di_tv, &v->di_tv);
Karsten Hopp c2623c
! 	    }
Karsten Hopp c2623c
! 	}
Karsten Hopp c2623c
! 
Karsten Hopp c2623c
! 	/* Make a copy of the a:000 items, since we didn't do that above. */
Karsten Hopp c2623c
! 	for (li = fc->l_varlist.lv_first; li != NULL; li = li->li_next)
Karsten Hopp c2623c
! 	    copy_tv(&li->li_tv, &li->li_tv);
Karsten Hopp c2623c
!     }
Karsten Hopp c2623c
! }
Karsten Hopp c2623c
! 
Karsten Hopp c2623c
! /*
Karsten Hopp c2623c
!  * Return TRUE if items in "fc" do not have "copyID".  That means they are not
Karsten Hopp c2623c
!  * referenced from anywyere.
Karsten Hopp c2623c
!  */
Karsten Hopp c2623c
!     static int
Karsten Hopp c2623c
! can_free_funccal(fc, copyID)
Karsten Hopp c2623c
!     funccall_T	*fc;
Karsten Hopp c2623c
!     int		copyID;
Karsten Hopp c2623c
! {
Karsten Hopp c2623c
!     return (fc->l_varlist.lv_copyID != copyID
Karsten Hopp c2623c
! 	    && fc->l_vars.dv_copyID != copyID
Karsten Hopp c2623c
! 	    && fc->l_avars.dv_copyID != copyID);
Karsten Hopp c2623c
! }
Karsten Hopp c2623c
! 
Karsten Hopp c2623c
! /*
Karsten Hopp c2623c
!  * Free "fc" and what it contains.
Karsten Hopp c2623c
!  */
Karsten Hopp c2623c
!    static void
Karsten Hopp c2623c
! free_funccal(fc, free_val)
Karsten Hopp c2623c
!     funccall_T	*fc;
Karsten Hopp c2623c
!     int		free_val;  /* a: vars were allocated */
Karsten Hopp c2623c
! {
Karsten Hopp c2623c
!     listitem_T	*li;
Karsten Hopp c2623c
! 
Karsten Hopp c2623c
!     /* The a: variables typevals may not have been allocated, only free the
Karsten Hopp c2623c
!      * allocated variables. */
Karsten Hopp c2623c
!     vars_clear_ext(&fc->l_avars.dv_hashtab, free_val);
Karsten Hopp c2623c
! 
Karsten Hopp c2623c
!     /* free all l: variables */
Karsten Hopp c2623c
!     vars_clear(&fc->l_vars.dv_hashtab);
Karsten Hopp c2623c
! 
Karsten Hopp c2623c
!     /* Free the a:000 variables if they were allocated. */
Karsten Hopp c2623c
!     if (free_val)
Karsten Hopp c2623c
! 	for (li = fc->l_varlist.lv_first; li != NULL; li = li->li_next)
Karsten Hopp c2623c
! 	    clear_tv(&li->li_tv);
Karsten Hopp c2623c
! 
Karsten Hopp c2623c
!     vim_free(fc);
Karsten Hopp c2623c
  }
Karsten Hopp c2623c
  
Karsten Hopp c2623c
  /*
Karsten Hopp c2623c
*** ../vim-7.2.069/src/version.c	Tue Dec  9 22:34:02 2008
Karsten Hopp c2623c
--- src/version.c	Sun Dec 21 12:47:07 2008
Karsten Hopp c2623c
***************
Karsten Hopp c2623c
*** 678,679 ****
Karsten Hopp c2623c
--- 678,681 ----
Karsten Hopp c2623c
  {   /* Add new patch number below this line */
Karsten Hopp c2623c
+ /**/
Karsten Hopp c2623c
+     70,
Karsten Hopp c2623c
  /**/
Karsten Hopp c2623c
Karsten Hopp c2623c
-- 
Karsten Hopp c2623c
Close your shells, or I'll kill -9 you
Karsten Hopp c2623c
Tomorrow I'll quota you
Karsten Hopp c2623c
Remember the disks'll always be full
Karsten Hopp c2623c
And then while I'm away
Karsten Hopp c2623c
I'll write ~ everyday
Karsten Hopp c2623c
And I'll send-pr all my buggings to you.
Karsten Hopp c2623c
    [ CVS log "Beatles style" for FreeBSD ports/INDEX, Satoshi Asami ]
Karsten Hopp c2623c
Karsten Hopp c2623c
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp c2623c
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp c2623c
\\\        download, build and distribute -- http://www.A-A-P.org        ///
Karsten Hopp c2623c
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///