[or-cvs] r9633: Move tricky "delete the member of the smartlist currently un (in tor/trunk: . src/common src/or)

nickm at seul.org nickm at seul.org
Sat Feb 24 07:37:50 UTC 2007


Author: nickm
Date: 2007-02-24 02:37:45 -0500 (Sat, 24 Feb 2007)
New Revision: 9633

Modified:
   tor/trunk/
   tor/trunk/src/common/container.h
   tor/trunk/src/or/circuitbuild.c
Log:
 r11909 at catbus:  nickm | 2007-02-24 02:37:40 -0500
 Move tricky "delete the member of the smartlist currently under iteration" logic into its own happyfun macro.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r11909] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/src/common/container.h
===================================================================
--- tor/trunk/src/common/container.h	2007-02-24 06:44:40 UTC (rev 9632)
+++ tor/trunk/src/common/container.h	2007-02-24 07:37:45 UTC (rev 9633)
@@ -156,6 +156,16 @@
       cmd;                                                      \
     } } while (0)
 
+/** Helper: While in a SMARTLIST_FOREACH loop over the list <b>sl</b> indexed
+ * with the variable <b>var</b>, remover the current element in a way that
+ * won't confuse the loop. */
+#define SMARTLIST_DEL_CURRENT(sl, var)          \
+  do {                                          \
+    smartlist_del(sl, var ## _sl_idx);          \
+    --var ## _sl_idx;                           \
+    --var ## _sl_len;                           \
+  } while (0);
+
 #define DECLARE_MAP_FNS(maptype, keytype, prefix)                       \
   typedef struct maptype maptype;                                       \
   typedef struct prefix##entry_t *prefix##iter_t;                       \

Modified: tor/trunk/src/or/circuitbuild.c
===================================================================
--- tor/trunk/src/or/circuitbuild.c	2007-02-24 06:44:40 UTC (rev 9632)
+++ tor/trunk/src/or/circuitbuild.c	2007-02-24 07:37:45 UTC (rev 9633)
@@ -2280,8 +2280,7 @@
   /* Remove all currently configured entry guards from entry_routers. */
   SMARTLIST_FOREACH(entry_routers, routerinfo_t *, ri, {
     if (is_an_entry_guard(ri->cache_info.identity_digest)) {
-      smartlist_del(entry_routers, ri_sl_idx--);
-      ri_sl_len--;
+      SMARTLIST_DEL_CURRENT(entry_routers, ri);
     }
   });
 



More information about the tor-commits mailing list