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