2b60012
To: vim-dev@vim.org
2b60012
Subject: Patch 7.0.082
2b60012
Fcc: outbox
2b60012
From: Bram Moolenaar <Bram@moolenaar.net>
2b60012
Mime-Version: 1.0
2b60012
Content-Type: text/plain; charset=ISO-8859-1
2b60012
Content-Transfer-Encoding: 8bit
2b60012
------------
2b60012
2b60012
Patch 7.0.082
2b60012
Problem:    Calling a function that waits for input may cause List and
2b60012
	    Dictionary arguments to be freed by the garbage collector.
2b60012
Solution:   Keep a list of all arguments to internal functions.
2b60012
Files:	    src/eval.c
2b60012
2b60012
2b60012
*** ../vim-7.0.081/src/eval.c	Sat Sep  2 13:45:01 2006
2b60012
--- src/eval.c	Sun Sep  3 15:36:10 2006
2b60012
***************
2b60012
*** 248,253 ****
2b60012
--- 248,264 ----
2b60012
  };
2b60012
  
2b60012
  /*
2b60012
+  * Struct used to make a list of all arguments used in internal functions.
2b60012
+  */
2b60012
+ typedef struct av_list_item_S av_list_item_T;
2b60012
+ struct av_list_item_S {
2b60012
+     av_list_item_T  *avl_next;
2b60012
+     typval_T	    *avl_argvars;
2b60012
+ };
2b60012
+ 
2b60012
+ av_list_item_T *argvars_list = NULL;
2b60012
+ 
2b60012
+ /*
2b60012
   * Info used by a ":for" loop.
2b60012
   */
2b60012
  typedef struct
2b60012
***************
2b60012
*** 6058,6063 ****
2b60012
--- 6069,6075 ----
2b60012
      int		i;
2b60012
      funccall_T	*fc;
2b60012
      int		did_free = FALSE;
2b60012
+     av_list_item_T *av;
2b60012
  #ifdef FEAT_WINDOWS
2b60012
      tabpage_T	*tp;
2b60012
  #endif
2b60012
***************
2b60012
*** 6094,6099 ****
2b60012
--- 6106,6116 ----
2b60012
  	set_ref_in_ht(&fc->l_avars.dv_hashtab, copyID);
2b60012
      }
2b60012
  
2b60012
+     /* arguments for internal functions */
2b60012
+     for (av = argvars_list; av != NULL; av = av->avl_next)
2b60012
+ 	for (i = 0; av->avl_argvars[i].v_type != VAR_UNKNOWN; ++i)
2b60012
+ 	    set_ref_in_item(&av->avl_argvars[i], copyID);
2b60012
+ 
2b60012
      /*
2b60012
       * 2. Go through the list of dicts and free items without the copyID.
2b60012
       */
2b60012
***************
2b60012
*** 7537,7545 ****
2b60012
--- 7554,7574 ----
2b60012
  		    error = ERROR_TOOMANY;
2b60012
  		else
2b60012
  		{
2b60012
+ 		    av_list_item_T  av_list_item;
2b60012
+ 
2b60012
+ 		    /* Add the arguments to the "argvars_list" to avoid the
2b60012
+ 		     * garbage collector not seeing them.  This isn't needed
2b60012
+ 		     * for user functions, because the arguments are available
2b60012
+ 		     * in the a: hashtab. */
2b60012
+ 		    av_list_item.avl_argvars = argvars;
2b60012
+ 		    av_list_item.avl_next = argvars_list;
2b60012
+ 		    argvars_list = &av_list_item;
2b60012
+ 
2b60012
  		    argvars[argcount].v_type = VAR_UNKNOWN;
2b60012
  		    functions[i].f_func(argvars, rettv);
2b60012
  		    error = ERROR_NONE;
2b60012
+ 
2b60012
+ 		    argvars_list = av_list_item.avl_next;
2b60012
  		}
2b60012
  	    }
2b60012
  	}
2b60012
*** ../vim-7.0.081/src/version.c	Sat Sep  2 17:58:36 2006
2b60012
--- src/version.c	Sun Sep  3 15:35:16 2006
2b60012
***************
2b60012
*** 668,669 ****
2b60012
--- 668,671 ----
2b60012
  {   /* Add new patch number below this line */
2b60012
+ /**/
2b60012
+     82,
2b60012
  /**/
2b60012
2b60012
-- 
2b60012
Just think of all the things we haven't thought of yet.
2b60012
2b60012
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
2b60012
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
2b60012
\\\        download, build and distribute -- http://www.A-A-P.org        ///
2b60012
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///