Skip to content

Commit

Permalink
ovsdb-idlc: Consolidate assertions.
Browse files Browse the repository at this point in the history
There were lots of bits of code emitting "assert(inited);".  This combines
many of them.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Andy Zhou <azhou@ovn.org>
  • Loading branch information
blp committed Oct 19, 2016
1 parent cb9d556 commit cad9a99
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions ovsdb/ovsdb-idlc.in
Expand Up @@ -345,6 +345,7 @@ static struct %(s)s *
static void
%(s)s_parse_%(c)s(struct ovsdb_idl_row *row_, const struct ovsdb_datum *datum)
{
ovs_assert(inited);
struct %(s)s *row = %(s)s_cast(row_);''' % {'s': structName,
'c': columnName}
type = column.type
Expand All @@ -356,7 +357,6 @@ static void
valueVar = None

if type.is_smap():
print " ovs_assert(inited);"
print " smap_init(&row->%s);" % columnName
print " for (size_t i = 0; i < datum->n; i++) {"
print " smap_add(&row->%s," % columnName
Expand All @@ -365,7 +365,6 @@ static void
print " }"
elif (type.n_min == 1 and type.n_max == 1) or type.is_optional_pointer():
print
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())
Expand All @@ -388,7 +387,6 @@ static void
nMax = "n"
else:
nMax = "datum->n"
print " ovs_assert(inited);"
print " %s = NULL;" % keyVar
if valueVar:
print " %s = NULL;" % valueVar
Expand Down Expand Up @@ -706,18 +704,20 @@ const struct ovsdb_datum *
nVar = members[1]['name']

print comment
print 'void'
print '%(s)s_set_%(c)s(const struct %(s)s *row, %(args)s)' % \
{'s': structName, 'c': columnName,
'args': ', '.join(['%(type)s%(name)s' % m for m in members])}
print "{"
print " struct ovsdb_datum datum;"
print """\
void
%(s)s_set_%(c)s(const struct %(s)s *row, %(args)s)
{
ovs_assert(inited);
struct ovsdb_datum datum;""" % {'s': structName,
'c': columnName,
'args': ', '.join(['%(type)s%(name)s'
% m for m in members])}
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 " ovs_assert(inited);"
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)
Expand All @@ -730,7 +730,6 @@ const struct ovsdb_datum *
elif type.is_optional_pointer():
print " union ovsdb_atom key;"
print
print " ovs_assert(inited);"
print " if (%s) {" % keyVar
print " datum.n = 1;"
print " datum.keys = &key;"
Expand All @@ -744,7 +743,6 @@ const struct ovsdb_datum *
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;"
Expand All @@ -757,7 +755,6 @@ const struct ovsdb_datum *
txn_write_func = "ovsdb_idl_txn_write_clone"
else:
print
print " ovs_assert(inited);"
print " datum.n = %s;" % nVar
print " datum.keys = %s ? xmalloc(%s * sizeof *datum.keys) : NULL;" % (nVar, nVar)
if type.value:
Expand Down Expand Up @@ -955,14 +952,14 @@ void
{'s': structName, 'c': columnName,
'args': ', '.join(['%(type)s%(name)s' % m for m in members])}
print "{"
print " ovs_assert(inited);"
print " struct ovsdb_datum datum;"
free = []
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 " ovs_assert(inited);"
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, refTable=False)
Expand All @@ -974,7 +971,6 @@ void
elif type.is_optional_pointer():
print " union ovsdb_atom key;"
print
print " ovs_assert(inited);"
print " if (%s) {" % keyVar
print " datum.n = 1;"
print " datum.keys = &key;"
Expand All @@ -987,7 +983,6 @@ void
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;"
Expand All @@ -998,7 +993,6 @@ void
print " }"
print " datum.values = NULL;"
else:
print " ovs_assert(inited);"
print " datum.n = %s;" % nVar
print " datum.keys = %s ? xmalloc(%s * sizeof *datum.keys) : NULL;" % (nVar, nVar)
free += ['datum.keys']
Expand Down Expand Up @@ -1112,14 +1106,14 @@ void
{'s': structName, 'c': columnName,
'args': ', '.join(['%(type)s%(name)s' % m for m in members])}
print "{"
print " ovs_assert(inited);"
print " struct ovsdb_datum datum;"
free = []
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 " ovs_assert(inited);"
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, refTable=False)
Expand All @@ -1131,7 +1125,6 @@ void
elif type.is_optional_pointer():
print " union ovsdb_atom key;"
print
print " ovs_assert(inited);"
print " if (%s) {" % keyVar
print " datum.n = 1;"
print " datum.keys = &key;"
Expand All @@ -1144,7 +1137,6 @@ void
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;"
Expand All @@ -1155,7 +1147,6 @@ void
print " }"
print " datum.values = NULL;"
else:
print " ovs_assert(inited);"
print " datum.n = %s;" % nVar
print " datum.keys = %s ? xmalloc(%s * sizeof *datum.keys) : NULL;" % (nVar, nVar)
free += ['datum.keys']
Expand Down

0 comments on commit cad9a99

Please sign in to comment.