ovsdb-idlc: Check and restore ovsdb_datum invariants when setting data.
authorBen Pfaff <blp@nicira.com>
Wed, 16 Jun 2010 21:08:49 +0000 (14:08 -0700)
committerBen Pfaff <blp@nicira.com>
Mon, 12 Jul 2010 17:07:36 +0000 (10:07 -0700)
ovsdb_datum has an important invariant (documented in the large comment
on the declaration of struct ovsdb_datum) that a lot of code relies upon:
keys must be unique and in sorted order.  Most code that creates or
modifies ovsdb_datum structures maintains this invariant.  However, the
"set" functions generated by ovsdb-idlc.in do not check or restore it.
This commit adds that checking.

This might fix an actual bug or two--none have been reported--but mostly it
is just to add some additional checking to avoid future subtle bugs.

ovsdb/ovsdb-idlc.in

index 9a235e2..e8ec76e 100755 (executable)
@@ -456,6 +456,12 @@ void
                 if type.value:
                     print "        " + type.value.copyCValue("datum.values[i].%s" % type.value.type, "%s[i]" % valueVar)
                 print "    }"
+                if type.value:
+                    valueType = type.value.toAtomicType()
+                else:
+                    valueType = "OVSDB_TYPE_VOID"
+                print "    ovsdb_datum_sort_unique(&datum, %s, %s);" % (
+                    type.key.toAtomicType(), valueType)
             print "    ovsdb_idl_txn_write(&row->header_, &%(s)s_columns[%(S)s_COL_%(C)s], &datum);" \
                 % {'s': structName,
                    'S': structName.upper(),