[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r13379: Add (and use) a MAP_DEL_CURRENT macro to augment a non-const (in tor/trunk: . src/common src/or)



Author: nickm
Date: 2008-02-05 14:40:17 -0500 (Tue, 05 Feb 2008)
New Revision: 13379

Modified:
   tor/trunk/
   tor/trunk/src/common/container.h
   tor/trunk/src/or/dirserv.c
Log:
 r17898@catbus:  nickm | 2008-02-05 14:01:35 -0500
 Add (and use) a MAP_DEL_CURRENT macro to augment a non-const variant of MAP_FOREACH.



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

Modified: tor/trunk/src/common/container.h
===================================================================
--- tor/trunk/src/common/container.h	2008-02-05 19:40:15 UTC (rev 13378)
+++ tor/trunk/src/common/container.h	2008-02-05 19:40:17 UTC (rev 13379)
@@ -220,10 +220,33 @@
       prefix##iter_get(key##_iter, &keyvar, &valvar##_voidp);           \
       valvar = valvar##_voidp;
 
+#define MAP_FOREACH_MODIFY(prefix, map, keytype, keyvar, valtype, valvar) \
+  STMT_BEGIN                                                            \
+    prefix##iter_t *key##_iter;                                         \
+    int keyvar##_del=0;                                                 \
+    for (key##_iter = prefix##iter_init(map);                           \
+         !prefix##iter_done(key##_iter);                                \
+         key##_iter = keyvar##_del ?                                    \
+           prefix##iter_next_rmv(map, key##_iter) :                     \
+           prefix##iter_next(map, key##_iter)) {                        \
+      keytype keyvar;                                                   \
+      void *valvar##_voidp;                                             \
+      valtype valvar;                                                   \
+      keyvar##_del=0;                                                   \
+      prefix##iter_get(key##_iter, &keyvar, &valvar##_voidp);           \
+      valvar = valvar##_voidp;
+
+#define MAP_DEL_CURRENT(keyvar)                   \
+  STMT_BEGIN                                      \
+    keyvar##_del = 1;                             \
+  STMT_END
+
 #define MAP_FOREACH_END } STMT_END ;
 
 #define DIGESTMAP_FOREACH(map, keyvar, valtype, valvar)                 \
   MAP_FOREACH(digestmap_, map, const char *, keyvar, valtype, valvar)
+#define DIGESTMAP_FOREACH_MODIFY(map, keyvar, valtype, valvar)          \
+  MAP_FOREACH_MODIFY(digestmap_, map, const char *, keyvar, valtype, valvar)
 #define DIGESTMAP_FOREACH_END MAP_FOREACH_END
 
 void* strmap_set_lc(strmap_t *map, const char *key, void *val);

Modified: tor/trunk/src/or/dirserv.c
===================================================================
--- tor/trunk/src/or/dirserv.c	2008-02-05 19:40:15 UTC (rev 13378)
+++ tor/trunk/src/or/dirserv.c	2008-02-05 19:40:17 UTC (rev 13379)
@@ -1396,22 +1396,13 @@
 void
 dirserv_clear_old_networkstatuses(time_t cutoff)
 {
-  digestmap_iter_t *iter;
-
   if (!cached_v2_networkstatus)
     return;
 
-  for (iter = digestmap_iter_init(cached_v2_networkstatus);
-       !digestmap_iter_done(iter); ) {
-    const char *ident;
-    void *val;
-    cached_dir_t *dir;
-    digestmap_iter_get(iter, &ident, &val);
-    dir = val;
+  DIGESTMAP_FOREACH_MODIFY(cached_v2_networkstatus, id, cached_dir_t *, dir) {
     if (dir->published < cutoff) {
       char *fname;
-      iter = digestmap_iter_next_rmv(cached_v2_networkstatus, iter);
-      fname = networkstatus_get_cache_filename(ident);
+      fname = networkstatus_get_cache_filename(id);
       if (file_status(fname) == FN_FILE) {
         log_info(LD_DIR, "Removing too-old untrusted networkstatus in %s",
                  fname);
@@ -1419,10 +1410,9 @@
       }
       tor_free(fname);
       cached_dir_decref(dir);
-    } else {
-      iter = digestmap_iter_next(cached_v2_networkstatus, iter);
+      MAP_DEL_CURRENT(id);
     }
-  }
+  } DIGESTMAP_FOREACH_END
 }
 
 /** Remove any v1 info from the directory cache that was published