On Mon, Feb 08, 2016 at 04:52:45PM -0800, Ben Pfaff wrote:
> Some of our data structures derived from hmap use the same member names.
> This means it's possible to confuse them in iteration, e.g. to iterate a
> shash with SIMAP_FOR_EACH.  Of course this will crash at runtime, but it
> seems even better to catch it at compile time.
> 
> An alternative would be to use unique member names, e.g. shash_map and
> simap_map instead of just map.  I like short names, though.
> 
> It's kind of nasty that we need support from the hmap code to do this.
> An alternative would be to insert the build assertions as statements before
> the for loop.  But that would cause nasty surprises if someone forgets the
> {} around a block of statements; even though the OVS coding style requires
> them in all cases, I suspect that programmers doing debugging, etc. tend
> to omit them sometimes.
> 
> It's not actually necessary to have multiple variants of these macros,
> e.g. one can write a C99-compliant HMAP_FOR_EACH that accepts 3 or 4 or
> more arguments.  But such a macro is harder to read, so I don't know
> whether this is a good tradeoff.
> 
> Signed-off-by: Ben Pfaff <b...@ovn.org>

Does anyone want to advocate against this patch on the basis of any of
the above tradeoffs?  Or for another reason?  I like that it makes our
data structures safer, but I don't know whether I'm choosing the right
tradeoff here.
_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to