hmap: Add comment warning about pitfall in HMAP_FOR_EACH_* usage.
authorBen Pfaff <blp@nicira.com>
Mon, 6 Apr 2015 21:39:06 +0000 (14:39 -0700)
committerBen Pfaff <blp@nicira.com>
Tue, 7 Apr 2015 04:26:44 +0000 (21:26 -0700)
CC: Russell Bryant <rbryant@redhat.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Justin Pettit <jpettit@nicira.com>
lib/hmap.h

index dc1e85c..345bf7f 100644 (file)
@@ -123,6 +123,16 @@ struct hmap_node *hmap_random_node(const struct hmap *);
  * iteration).
  *
  * HASH is only evaluated once.
  * iteration).
  *
  * HASH is only evaluated once.
+ *
+ *
+ * Warning
+ * -------
+ *
+ * When the loop terminates, &NODE->MEMBER will equal NULL.  Unless MEMBER is
+ * the first member in its struct, this means that NODE itself will not be
+ * NULL.
+ *
+ * (This is true for all of the HMAP_FOR_EACH_*() macros.)
  */
 #define HMAP_FOR_EACH_WITH_HASH(NODE, MEMBER, HASH, HMAP)               \
     for (INIT_CONTAINER(NODE, hmap_first_with_hash(HMAP, HASH), MEMBER); \
  */
 #define HMAP_FOR_EACH_WITH_HASH(NODE, MEMBER, HASH, HMAP)               \
     for (INIT_CONTAINER(NODE, hmap_first_with_hash(HMAP, HASH), MEMBER); \