home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 7.2 / 7.2.188 < prev    next >
Encoding:
Internet Message Format  |  2009-05-23  |  8.3 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 7.2.188
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. Patch 7.2.188
  11. Problem:    Crash with specific use of function calls. (Meikel Brandmeyer)
  12. Solution:   Make sure the items referenced by a function call are not freed
  13.         twice.  (based on patch from Nico Weber)
  14. Files:        src/eval.c
  15.  
  16.  
  17. *** ../vim-7.2.187/src/eval.c    2009-05-16 17:29:37.000000000 +0200
  18. --- src/eval.c    2009-05-22 20:04:22.000000000 +0200
  19. ***************
  20. *** 129,136 ****
  21. --- 129,139 ----
  22.   /*
  23.    * When recursively copying lists and dicts we need to remember which ones we
  24.    * have done to avoid endless recursiveness.  This unique ID is used for that.
  25. +  * The last bit is used for previous_funccal, ignored when comparing.
  26.    */
  27.   static int current_copyID = 0;
  28. + #define COPYID_INC 2
  29. + #define COPYID_MASK (~0x1)
  30.   
  31.   /*
  32.    * Array to hold the hashtab with variables local to each sourced script.
  33. ***************
  34. *** 439,444 ****
  35. --- 442,448 ----
  36.   static void list_remove __ARGS((list_T *l, listitem_T *item, listitem_T *item2));
  37.   static char_u *list2string __ARGS((typval_T *tv, int copyID));
  38.   static int list_join __ARGS((garray_T *gap, list_T *l, char_u *sep, int echo, int copyID));
  39. + static int free_unref_items __ARGS((int copyID));
  40.   static void set_ref_in_ht __ARGS((hashtab_T *ht, int copyID));
  41.   static void set_ref_in_list __ARGS((list_T *l, int copyID));
  42.   static void set_ref_in_item __ARGS((typval_T *tv, int copyID));
  43. ***************
  44. *** 6494,6507 ****
  45.       int
  46.   garbage_collect()
  47.   {
  48. !     dict_T    *dd;
  49. !     list_T    *ll;
  50. !     int        copyID = ++current_copyID;
  51.       buf_T    *buf;
  52.       win_T    *wp;
  53.       int        i;
  54.       funccall_T    *fc, **pfc;
  55. !     int        did_free = FALSE;
  56.   #ifdef FEAT_WINDOWS
  57.       tabpage_T    *tp;
  58.   #endif
  59. --- 6498,6510 ----
  60.       int
  61.   garbage_collect()
  62.   {
  63. !     int        copyID;
  64.       buf_T    *buf;
  65.       win_T    *wp;
  66.       int        i;
  67.       funccall_T    *fc, **pfc;
  68. !     int        did_free;
  69. !     int        did_free_funccal = FALSE;
  70.   #ifdef FEAT_WINDOWS
  71.       tabpage_T    *tp;
  72.   #endif
  73. ***************
  74. *** 6511,6520 ****
  75. --- 6514,6538 ----
  76.       may_garbage_collect = FALSE;
  77.       garbage_collect_at_exit = FALSE;
  78.   
  79. +     /* We advance by two because we add one for items referenced through
  80. +      * previous_funccal. */
  81. +     current_copyID += COPYID_INC;
  82. +     copyID = current_copyID;
  83.       /*
  84.        * 1. Go through all accessible variables and mark all lists and dicts
  85.        *    with copyID.
  86.        */
  87. +     /* Don't free variables in the previous_funccal list unless they are only
  88. +      * referenced through previous_funccal.  This must be first, because if
  89. +      * the item is referenced elsewhere it must not be freed. */
  90. +     for (fc = previous_funccal; fc != NULL; fc = fc->caller)
  91. +     {
  92. +     set_ref_in_ht(&fc->l_vars.dv_hashtab, copyID + 1);
  93. +     set_ref_in_ht(&fc->l_avars.dv_hashtab, copyID + 1);
  94. +     }
  95.       /* script-local variables */
  96.       for (i = 1; i <= ga_scripts.ga_len; ++i)
  97.       set_ref_in_ht(&SCRIPT_VARS(i), copyID);
  98. ***************
  99. *** 6546,6556 ****
  100.       /* v: vars */
  101.       set_ref_in_ht(&vimvarht, copyID);
  102.   
  103.       /*
  104. !      * 2. Go through the list of dicts and free items without the copyID.
  105.        */
  106.       for (dd = first_dict; dd != NULL; )
  107. !     if (dd->dv_copyID != copyID)
  108.       {
  109.           /* Free the Dictionary and ordinary items it contains, but don't
  110.            * recurse into Lists and Dictionaries, they will be in the list
  111. --- 6564,6610 ----
  112.       /* v: vars */
  113.       set_ref_in_ht(&vimvarht, copyID);
  114.   
  115. +     /* Free lists and dictionaries that are not referenced. */
  116. +     did_free = free_unref_items(copyID);
  117. +     /* check if any funccal can be freed now */
  118. +     for (pfc = &previous_funccal; *pfc != NULL; )
  119. +     {
  120. +     if (can_free_funccal(*pfc, copyID))
  121. +     {
  122. +         fc = *pfc;
  123. +         *pfc = fc->caller;
  124. +         free_funccal(fc, TRUE);
  125. +         did_free = TRUE;
  126. +         did_free_funccal = TRUE;
  127. +     }
  128. +     else
  129. +         pfc = &(*pfc)->caller;
  130. +     }
  131. +     if (did_free_funccal)
  132. +     /* When a funccal was freed some more items might be garbage
  133. +      * collected, so run again. */
  134. +     (void)garbage_collect();
  135. +     return did_free;
  136. + }
  137. + /*
  138. +  * Free lists and dictionaries that are no longer referenced.
  139. +  */
  140. +     static int
  141. + free_unref_items(copyID)
  142. +     int copyID;
  143. + {
  144. +     dict_T    *dd;
  145. +     list_T    *ll;
  146. +     int        did_free = FALSE;
  147.       /*
  148. !      * Go through the list of dicts and free items without the copyID.
  149.        */
  150.       for (dd = first_dict; dd != NULL; )
  151. !     if ((dd->dv_copyID & COPYID_MASK) != (copyID & COPYID_MASK))
  152.       {
  153.           /* Free the Dictionary and ordinary items it contains, but don't
  154.            * recurse into Lists and Dictionaries, they will be in the list
  155. ***************
  156. *** 6565,6576 ****
  157.           dd = dd->dv_used_next;
  158.   
  159.       /*
  160. !      * 3. Go through the list of lists and free items without the copyID.
  161. !      *    But don't free a list that has a watcher (used in a for loop), these
  162. !      *    are not referenced anywhere.
  163.        */
  164.       for (ll = first_list; ll != NULL; )
  165. !     if (ll->lv_copyID != copyID && ll->lv_watch == NULL)
  166.       {
  167.           /* Free the List and ordinary items it contains, but don't recurse
  168.            * into Lists and Dictionaries, they will be in the list of dicts
  169. --- 6619,6631 ----
  170.           dd = dd->dv_used_next;
  171.   
  172.       /*
  173. !      * Go through the list of lists and free items without the copyID.
  174. !      * But don't free a list that has a watcher (used in a for loop), these
  175. !      * are not referenced anywhere.
  176.        */
  177.       for (ll = first_list; ll != NULL; )
  178. !     if ((ll->lv_copyID & COPYID_MASK) != (copyID & COPYID_MASK)
  179. !                               && ll->lv_watch == NULL)
  180.       {
  181.           /* Free the List and ordinary items it contains, but don't recurse
  182.            * into Lists and Dictionaries, they will be in the list of dicts
  183. ***************
  184. *** 6584,6603 ****
  185.       else
  186.           ll = ll->lv_used_next;
  187.   
  188. -     /* check if any funccal can be freed now */
  189. -     for (pfc = &previous_funccal; *pfc != NULL; )
  190. -     {
  191. -     if (can_free_funccal(*pfc, copyID))
  192. -     {
  193. -         fc = *pfc;
  194. -         *pfc = fc->caller;
  195. -         free_funccal(fc, TRUE);
  196. -         did_free = TRUE;
  197. -     }
  198. -     else
  199. -         pfc = &(*pfc)->caller;
  200. -     }
  201.       return did_free;
  202.   }
  203.   
  204. --- 6639,6644 ----
  205. ***************
  206. *** 18842,18847 ****
  207. --- 18883,18889 ----
  208.   {
  209.       hash_init(&dict->dv_hashtab);
  210.       dict->dv_refcount = DO_NOT_FREE_CNT;
  211. +     dict->dv_copyID = 0;
  212.       dict_var->di_tv.vval.v_dict = dict;
  213.       dict_var->di_tv.v_type = VAR_DICT;
  214.       dict_var->di_tv.v_lock = VAR_FIXED;
  215. ***************
  216. *** 21294,21301 ****
  217.       current_funccal = fc->caller;
  218.       --depth;
  219.   
  220. !     /* if the a:000 list and the a: dict are not referenced we can free the
  221. !      * funccall_T and what's in it. */
  222.       if (fc->l_varlist.lv_refcount == DO_NOT_FREE_CNT
  223.           && fc->l_vars.dv_refcount == DO_NOT_FREE_CNT
  224.           && fc->l_avars.dv_refcount == DO_NOT_FREE_CNT)
  225. --- 21336,21343 ----
  226.       current_funccal = fc->caller;
  227.       --depth;
  228.   
  229. !     /* If the a:000 list and the l: and a: dicts are not referenced we can
  230. !      * free the funccall_T and what's in it. */
  231.       if (fc->l_varlist.lv_refcount == DO_NOT_FREE_CNT
  232.           && fc->l_vars.dv_refcount == DO_NOT_FREE_CNT
  233.           && fc->l_avars.dv_refcount == DO_NOT_FREE_CNT)
  234. ***************
  235. *** 21334,21340 ****
  236.   
  237.   /*
  238.    * Return TRUE if items in "fc" do not have "copyID".  That means they are not
  239. !  * referenced from anywhere.
  240.    */
  241.       static int
  242.   can_free_funccal(fc, copyID)
  243. --- 21376,21382 ----
  244.   
  245.   /*
  246.    * Return TRUE if items in "fc" do not have "copyID".  That means they are not
  247. !  * referenced from anywhere that is in use.
  248.    */
  249.       static int
  250.   can_free_funccal(fc, copyID)
  251. *** ../vim-7.2.187/src/version.c    2009-05-23 14:27:43.000000000 +0200
  252. --- src/version.c    2009-05-24 13:20:49.000000000 +0200
  253. ***************
  254. *** 678,679 ****
  255. --- 678,681 ----
  256.   {   /* Add new patch number below this line */
  257. + /**/
  258. +     188,
  259.   /**/
  260.  
  261. -- 
  262. ARTHUR:    ... and I am your king ....
  263. OLD WOMAN: Ooooh!  I didn't know we had a king.  I thought we were an
  264.            autonomous collective ...
  265.                  "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
  266.  
  267.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  268. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  269. \\\        download, build and distribute -- http://www.A-A-P.org        ///
  270.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  271.