X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=ovsdb%2Fovsdb-idlc.in;h=e5c81832a59f831e44b0bc61c3cf97e87a12eb68;hb=6d8ffe18982370d2c46665d7924c340030d53565;hp=c6870cc3aedb3e1675e7cf718c611d47d7fb526c;hpb=c5c7c7c5c0d379c49121d63b77067aa32bce22b7;p=openvswitch diff --git a/ovsdb/ovsdb-idlc.in b/ovsdb/ovsdb-idlc.in index c6870cc3..e5c81832 100755 --- a/ovsdb/ovsdb-idlc.in +++ b/ovsdb/ovsdb-idlc.in @@ -20,15 +20,15 @@ def annotateSchema(schemaFile, annotationFile): ovs.json.to_stream(schemaJson, sys.stdout) def constify(cType, const): - if (const - and cType.endswith('*') and not cType.endswith('**') - and (cType.startswith('struct uuid') or cType.startswith('char'))): + if (const and cType.endswith('*') and not cType.endswith('**')): return 'const %s' % cType else: return cType def cMembers(prefix, columnName, column, const): type = column.type + if is_optional_bool(type): + const = True if type.n_min == 1 and type.n_max == 1: singleton = True pointer = '' @@ -167,6 +167,10 @@ def printEnum(members): print " %s" % members[-1] print "};" +def is_optional_bool(type): + return (type.key.type == ovs.db.types.BooleanType and not type.value + and type.n_min == 0 and type.n_max == 1) + def printCIDLSource(schemaFile): schema = parseSchema(schemaFile) prefix = schema.idlPrefix @@ -217,7 +221,23 @@ static void keyVar = "row->%s" % columnName valueVar = None - if (type.n_min == 1 and type.n_max == 1) or type.is_optional_pointer(): + if is_optional_bool(type): + # Special case for an optional bool. This is only here because + # sparse does not like the "normal" case below ("warning: + # expression using sizeof bool"). + print + print " assert(inited);" + print " if (datum->n >= 1) {" + print " static const bool false_value = false;" + print " static const bool true_value = true;" + print + print " row->n_%s = 1;" % columnName + print " %s = datum->keys[0].boolean ? &true_value : &false_value;" % keyVar + print " } else {" + print " row->n_%s = 0;" % columnName + print " %s = NULL;" % keyVar + print " }" + elif (type.n_min == 1 and type.n_max == 1) or type.is_optional_pointer(): print print " assert(inited);" print " if (datum->n >= 1) {" @@ -285,7 +305,15 @@ static void # Unparse functions. for columnName, column in sorted(table.columns.iteritems()): type = column.type - if (type.n_min != 1 or type.n_max != 1) and not type.is_optional_pointer(): + if (type.key.type == ovs.db.types.BooleanType and not type.value + and type.n_min == 0 and type.n_max == 1): + print ''' +static void +%(s)s_unparse_%(c)s(struct ovsdb_idl_row *row OVS_UNUSED) +{ + /* Nothing to do. */ +}''' % {'s': structName, 'c': columnName} + elif (type.n_min != 1 or type.n_max != 1) and not type.is_optional_pointer(): print ''' static void %(s)s_unparse_%(c)s(struct ovsdb_idl_row *row_) @@ -489,7 +517,11 @@ static void\n%s_columns_init(void) print "struct ovsdb_idl_table_class %stable_classes[%sN_TABLES] = {" % (prefix, prefix.upper()) for tableName, table in sorted(schema.tables.iteritems()): structName = "%s%s" % (prefix, tableName.lower()) - print " {\"%s\"," % tableName + if table.is_root: + is_root = "true" + else: + is_root = "false" + print " {\"%s\", %s," % (tableName, is_root) print " %s_columns, ARRAY_SIZE(%s_columns)," % ( structName, structName) print " sizeof(struct %s)}," % structName