fix iteration over ggc's extra_root_vec

Submitted by Nathan Froyd on Aug. 20, 2010, 1:59 p.m.

Details

Message ID 20100820135908.GR25394@codesourcery.com
State New
Headers show

Commit Message

Nathan Froyd Aug. 20, 2010, 1:59 p.m.
The patch below fixes a problem with garbage collecting data provided by
plugins.  The nested loop over extra_root_vec used i for both the
outermost and innermost iteration variable.  Any problems caused by this
probably weren't visible, since having two plugins loaded at one time is
not that common.  But it could be a problem as plugins become more
popular.

Instead of adding another index variable for the inner loop, I chose to
split out a separate function.

Tested on x86_64-unknown-linux-gnu.  OK to commit?

-Nathan

	* ggc-common.c (ggc_mark_root_tab): New function, split out from...
	(ggc_mark_roots): ...here.

Comments

Diego Novillo Aug. 20, 2010, 2:08 p.m.
On 10-08-20 09:59 , Nathan Froyd wrote:

> 	* ggc-common.c (ggc_mark_root_tab): New function, split out from...
> 	(ggc_mark_roots): ...here.

OK with a comment documenting ggc_mark_root_tab().


Diego.

Patch hide | download patch | download mbox

Index: ggc-common.c
===================================================================
--- ggc-common.c	(revision 163401)
+++ ggc-common.c	(working copy)
@@ -147,14 +147,23 @@  ggc_scan_cache_tab (const_ggc_cache_tab_
       }
 }
 
+static void
+ggc_mark_root_tab (const_ggc_root_tab_t rt)
+{
+  size_t i;
+
+  for ( ; rt->base != NULL; rt++)
+    for (i = 0; i < rt->nelt; i++)
+      (*rt->cb) (*(void **) ((char *)rt->base + rt->stride * i));
+}
+
 /* Iterate through all registered roots and mark each element.  */
 
 void
 ggc_mark_roots (void)
 {
   const struct ggc_root_tab *const *rt;
-  const struct ggc_root_tab *rti;
-  const_ggc_root_tab_t rtp;
+  const_ggc_root_tab_t rtp, rti;
   const struct ggc_cache_tab *const *ct;
   const_ggc_cache_tab_t ctp;
   size_t i;
@@ -164,16 +173,10 @@  ggc_mark_roots (void)
       memset (rti->base, 0, rti->stride);
 
   for (rt = gt_ggc_rtab; *rt; rt++)
-    for (rti = *rt; rti->base != NULL; rti++)
-      for (i = 0; i < rti->nelt; i++)
-	(*rti->cb) (*(void **)((char *)rti->base + rti->stride * i));
+    ggc_mark_root_tab (*rt);
 
   FOR_EACH_VEC_ELT (const_ggc_root_tab_t, extra_root_vec, i, rtp)
-    {
-      for (rti = rtp; rti->base != NULL; rti++)
-        for (i = 0; i < rti->nelt; i++)
-          (*rti->cb) (*(void **) ((char *)rti->base + rti->stride * i));
-    }
+    ggc_mark_root_tab (rtp);
 
   if (ggc_protect_identifiers)
     ggc_mark_stringpool ();