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