X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=ovsdb%2Fovsdb-idlc.in;h=1f2195078a5dd1d7acc6b75f85ca5877ef933ce0;hb=485e2766d816a18e1a51ddf5e12e55f38aeedf89;hp=0b1933b3598dd95c73d911f01d57d42b5a11af4c;hpb=1e3f34c7693bcabae8e443ac1b246680ef9b60e2;p=sliver-openvswitch.git diff --git a/ovsdb/ovsdb-idlc.in b/ovsdb/ovsdb-idlc.in index 0b1933b35..1f2195078 100755 --- a/ovsdb/ovsdb-idlc.in +++ b/ovsdb/ovsdb-idlc.in @@ -185,10 +185,10 @@ def printCIDLSource(schemaFile): #include #include %s -#include #include #include "ovsdb-data.h" #include "ovsdb-error.h" +#include "util.h" #ifdef __CHECKER__ /* Sparse dislikes sizeof(bool) ("warning: expression using sizeof bool"). */ @@ -236,7 +236,7 @@ static void if type.is_smap(): print " size_t i;" print - print " assert(inited);" + print " ovs_assert(inited);" print " smap_init(&row->%s);" % columnName print " for (i = 0; i < datum->n; i++) {" print " smap_add(&row->%s," % columnName @@ -245,7 +245,7 @@ static void print " }" elif (type.n_min == 1 and type.n_max == 1) or type.is_optional_pointer(): print - print " assert(inited);" + print " ovs_assert(inited);" print " if (datum->n >= 1) {" if not type.key.ref_table: print " %s = datum->keys[0].%s;" % (keyVar, type.key.type.to_string()) @@ -270,7 +270,7 @@ static void nMax = "datum->n" print " size_t i;" print - print " assert(inited);" + print " ovs_assert(inited);" print " %s = NULL;" % keyVar if valueVar: print " %s = NULL;" % valueVar @@ -333,7 +333,7 @@ static void { struct %(s)s *row = %(s)s_cast(row_); - assert(inited);''' % {'s': structName, 'c': columnName} + ovs_assert(inited);''' % {'s': structName, 'c': columnName} if type.is_smap(): print " smap_destroy(&row->%s);" % columnName @@ -415,7 +415,7 @@ struct %(s)s * void %(s)s_verify_%(c)s(const struct %(s)s *row) { - assert(inited); + ovs_assert(inited); ovsdb_idl_txn_verify(&row->header_, &%(s)s_columns[%(S)s_COL_%(C)s]); }''' % {'s': structName, 'S': structName.upper(), @@ -426,7 +426,7 @@ void for columnName, column in sorted(table.columns.iteritems()): if column.type.value: valueParam = ',\n\tenum ovsdb_atomic_type value_type OVS_UNUSED' - valueType = '\n assert(value_type == %s);' % column.type.value.toAtomicType() + valueType = '\n ovs_assert(value_type == %s);' % column.type.value.toAtomicType() valueComment = "\n * 'value_type' must be %s." % column.type.value.toAtomicType() else: valueParam = '' @@ -452,7 +452,7 @@ const struct ovsdb_datum * %(s)s_get_%(c)s(const struct %(s)s *row, \tenum ovsdb_atomic_type key_type OVS_UNUSED%(v)s) { - assert(key_type == %(kt)s);%(vt)s + ovs_assert(key_type == %(kt)s);%(vt)s return ovsdb_idl_read(&row->header_, &%(s)s_col_%(c)s); }""" % {'s': structName, 'c': columnName, 'kt': column.type.key.toAtomicType(), @@ -469,7 +469,7 @@ void { struct ovsdb_datum datum; - assert(inited); + ovs_assert(inited); if (smap) { struct smap_node *node; size_t i; @@ -517,34 +517,54 @@ void print "{" print " struct ovsdb_datum datum;" if type.n_min == 1 and type.n_max == 1: + print " union ovsdb_atom key;" + if type.value: + print " union ovsdb_atom value;" print - print " assert(inited);" + print " ovs_assert(inited);" print " datum.n = 1;" - print " datum.keys = xmalloc(sizeof *datum.keys);" - print " " + type.key.copyCValue("datum.keys[0].%s" % type.key.type.to_string(), keyVar) + print " datum.keys = &key;" + print " " + type.key.assign_c_value_casting_away_const("key.%s" % type.key.type.to_string(), keyVar) if type.value: - print " datum.values = xmalloc(sizeof *datum.values);" - print " "+ type.value.copyCValue("datum.values[0].%s" % type.value.type.to_string(), valueVar) + print " datum.values = &value;" + print " "+ type.value.assign_c_value_casting_away_const("value.%s" % type.value.type.to_string(), valueVar) else: print " datum.values = NULL;" + txn_write_func = "ovsdb_idl_txn_write_clone" elif type.is_optional_pointer(): + print " union ovsdb_atom key;" print - print " assert(inited);" + print " ovs_assert(inited);" print " if (%s) {" % keyVar print " datum.n = 1;" - print " datum.keys = xmalloc(sizeof *datum.keys);" - print " " + type.key.copyCValue("datum.keys[0].%s" % type.key.type.to_string(), keyVar) + print " datum.keys = &key;" + print " " + type.key.assign_c_value_casting_away_const("key.%s" % type.key.type.to_string(), keyVar) print " } else {" print " datum.n = 0;" print " datum.keys = NULL;" print " }" print " datum.values = NULL;" + txn_write_func = "ovsdb_idl_txn_write_clone" + elif type.n_max == 1: + print " union ovsdb_atom key;" + print + print " ovs_assert(inited);" + print " if (%s) {" % nVar + print " datum.n = 1;" + print " datum.keys = &key;" + print " " + type.key.assign_c_value_casting_away_const("key.%s" % type.key.type.to_string(), "*" + keyVar) + print " } else {" + print " datum.n = 0;" + print " datum.keys = NULL;" + print " }" + print " datum.values = NULL;" + txn_write_func = "ovsdb_idl_txn_write_clone" else: print " size_t i;" print - print " assert(inited);" + print " ovs_assert(inited);" print " datum.n = %s;" % nVar - print " datum.keys = xmalloc(%s * sizeof *datum.keys);" % nVar + print " datum.keys = %s ? xmalloc(%s * sizeof *datum.keys) : NULL;" % (nVar, nVar) if type.value: print " datum.values = xmalloc(%s * sizeof *datum.values);" % nVar else: @@ -560,8 +580,10 @@ void 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, + txn_write_func = "ovsdb_idl_txn_write" + print " %(f)s(&row->header_, &%(s)s_columns[%(S)s_COL_%(C)s], &datum);" \ + % {'f': txn_write_func, + 's': structName, 'S': structName.upper(), 'C': columnName.upper()} print "}" @@ -577,11 +599,16 @@ static void\n%s_columns_init(void) for columnName, column in sorted(table.columns.iteritems()): cs = "%s_col_%s" % (structName, columnName) d = {'cs': cs, 'c': columnName, 's': structName} + if column.mutable: + mutable = "true" + else: + mutable = "false" print print " /* Initialize %(cs)s. */" % d print " c = &%(cs)s;" % d print " c->name = \"%(c)s\";" % d print column.type.cInitType(" ", "c->type") + print " c->mutable = %s;" % mutable print " c->parse = %(s)s_parse_%(c)s;" % d print " c->unparse = %(s)s_unparse_%(c)s;" % d print "}"