Skip to content

Commit

Permalink
ovsdb-idlc: Make set and map update operations take const arguments.
Browse files Browse the repository at this point in the history
In a call like "ovsrec_bridge_update_ports_delvalue(bridge, port)", there's
no reason for the port argument to be nonconst, because the call doesn't
do anything to the port at all--it only searches the list of ports in the
bridge for that particular port and, if it finds it, removes it.

Signed-off-by: Ben Pfaff <[email protected]>
Acked-by: Russell Bryant <[email protected]>
  • Loading branch information
blp committed Sep 1, 2016
1 parent 23c16b5 commit 05ba459
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
38 changes: 19 additions & 19 deletions ovsdb/ovsdb-idlc.in
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,14 @@ bool %(s)s_is_updated(const struct %(s)s *, enum %(s)s_column_id);
for columnName, column in sorted(table.columns.iteritems()):
if column.type.is_map():
print 'void %(s)s_update_%(c)s_setkey(const struct %(s)s *, ' % {'s': structName, 'c': columnName},
print '%(coltype)s, %(valtype)s);' % {'coltype':column.type.key.toCType(prefix), 'valtype':column.type.value.toCType(prefix)}
print '%(coltype)s, %(valtype)s);' % {'coltype':column.type.key.to_const_c_type(prefix), 'valtype':column.type.value.to_const_c_type(prefix)}
print 'void %(s)s_update_%(c)s_delkey(const struct %(s)s *, ' % {'s': structName, 'c': columnName},
print '%(coltype)s);' % {'coltype':column.type.key.toCType(prefix)}
print '%(coltype)s);' % {'coltype':column.type.key.to_const_c_type(prefix)}
if column.type.is_set():
print 'void %(s)s_update_%(c)s_addvalue(const struct %(s)s *, ' % {'s': structName, 'c': columnName},
print '%(valtype)s);' % {'valtype':column.type.key.toCType(prefix)}
print '%(valtype)s);' % {'valtype':column.type.key.to_const_c_type(prefix)}
print 'void %(s)s_update_%(c)s_delvalue(const struct %(s)s *, ' % {'s': structName, 'c': columnName},
print '%(valtype)s);' % {'valtype':column.type.key.toCType(prefix)}
print '%(valtype)s);' % {'valtype':column.type.key.to_const_c_type(prefix)}

print 'void %(s)s_add_clause_%(c)s(struct ovsdb_idl *idl, enum ovsdb_function function,' % {'s': structName, 'c': columnName},
if column.type.is_smap():
Expand Down Expand Up @@ -817,8 +817,8 @@ void
datum->n = 1;
datum->keys = xmalloc(datum->n * sizeof *datum->keys);
datum->values = xmalloc(datum->n * sizeof *datum->values);
''' % {'s': structName, 'c': columnName,'coltype':column.type.key.toCType(prefix),
'valtype':column.type.value.toCType(prefix), 'S': structName.upper(),
''' % {'s': structName, 'c': columnName,'coltype':column.type.key.to_const_c_type(prefix),
'valtype':column.type.value.to_const_c_type(prefix), 'S': structName.upper(),
'C': columnName.upper(), 't': tableName}

print " "+ type.key.copyCValue("datum->keys[0].%s" % type.key.type.to_string(), "new_key")
Expand All @@ -827,8 +827,8 @@ void
ovsdb_idl_txn_write_partial_map(&row->header_,
&%(s)s_columns[%(S)s_COL_%(C)s],
datum);
}''' % {'s': structName, 'c': columnName,'coltype':column.type.key.toCType(prefix),
'valtype':column.type.value.toCType(prefix), 'S': structName.upper(),
}''' % {'s': structName, 'c': columnName,'coltype':column.type.key.to_const_c_type(prefix),
'valtype':column.type.value.to_const_c_type(prefix), 'S': structName.upper(),
'C': columnName.upper()}
print '''
/* Deletes an element of the "%(c)s" map column from the "%(t)s" table in 'row'
Expand All @@ -846,17 +846,17 @@ void
datum->n = 1;
datum->keys = xmalloc(datum->n * sizeof *datum->keys);
datum->values = NULL;
''' % {'s': structName, 'c': columnName,'coltype':column.type.key.toCType(prefix),
'valtype':column.type.value.toCType(prefix), 'S': structName.upper(),
''' % {'s': structName, 'c': columnName,'coltype':column.type.key.to_const_c_type(prefix),
'valtype':column.type.value.to_const_c_type(prefix), 'S': structName.upper(),
'C': columnName.upper(), 't': tableName}

print " "+ type.key.copyCValue("datum->keys[0].%s" % type.key.type.to_string(), "delete_key")
print '''
ovsdb_idl_txn_delete_partial_map(&row->header_,
&%(s)s_columns[%(S)s_COL_%(C)s],
datum);
}''' % {'s': structName, 'c': columnName,'coltype':column.type.key.toCType(prefix),
'valtype':column.type.value.toCType(prefix), 'S': structName.upper(),
}''' % {'s': structName, 'c': columnName,'coltype':column.type.key.to_const_c_type(prefix),
'valtype':column.type.value.to_const_c_type(prefix), 'S': structName.upper(),
'C': columnName.upper()}
# End Update/Delete of partial maps
# Update/Delete of partial set column functions
Expand All @@ -878,15 +878,15 @@ void
datum->keys = xmalloc(datum->n * sizeof *datum->values);
datum->values = NULL;
''' % {'s': structName, 'c': columnName,
'valtype':column.type.key.toCType(prefix), 't': tableName}
'valtype':column.type.key.to_const_c_type(prefix), 't': tableName}

print " "+ type.key.copyCValue("datum->keys[0].%s" % type.key.type.to_string(), "new_value")
print '''
ovsdb_idl_txn_write_partial_set(&row->header_,
&%(s)s_columns[%(S)s_COL_%(C)s],
datum);
}''' % {'s': structName, 'c': columnName,'coltype':column.type.key.toCType(prefix),
'valtype':column.type.key.toCType(prefix), 'S': structName.upper(),
}''' % {'s': structName, 'c': columnName,'coltype':column.type.key.to_const_c_type(prefix),
'valtype':column.type.key.to_const_c_type(prefix), 'S': structName.upper(),
'C': columnName.upper()}
print '''
/* Deletes the value 'delete_value' from the "%(c)s" set column from the
Expand All @@ -904,17 +904,17 @@ void
datum->n = 1;
datum->keys = xmalloc(datum->n * sizeof *datum->values);
datum->values = NULL;
''' % {'s': structName, 'c': columnName,'coltype':column.type.key.toCType(prefix),
'valtype':column.type.key.toCType(prefix), 'S': structName.upper(),
''' % {'s': structName, 'c': columnName,'coltype':column.type.key.to_const_c_type(prefix),
'valtype':column.type.key.to_const_c_type(prefix), 'S': structName.upper(),
'C': columnName.upper(), 't': tableName}

print " "+ type.key.copyCValue("datum->keys[0].%s" % type.key.type.to_string(), "delete_value")
print '''
ovsdb_idl_txn_delete_partial_set(&row->header_,
&%(s)s_columns[%(S)s_COL_%(C)s],
datum);
}''' % {'s': structName, 'c': columnName,'coltype':column.type.key.toCType(prefix),
'valtype':column.type.key.toCType(prefix), 'S': structName.upper(),
}''' % {'s': structName, 'c': columnName,'coltype':column.type.key.to_const_c_type(prefix),
'valtype':column.type.key.to_const_c_type(prefix), 'S': structName.upper(),
'C': columnName.upper()}
# End Update/Delete of partial set

Expand Down
14 changes: 13 additions & 1 deletion python/ovs/db/types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
# Copyright (c) 2009, 2010, 2011, 2012, 2013, 2016 Nicira, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -352,6 +352,18 @@ def toCType(self, prefix, refTable=True):
BooleanType: 'bool ',
StringType: 'char *'}[self.type]

def to_const_c_type(self, prefix, refTable=True):
nonconst = self.toCType(prefix, refTable)

# A "const" prefix works OK for the types we use, but it's a little
# weird to write "const bool" as, e.g., a function parameter since
# there's no real "const"ness there. So, omit the "const" except
# when a pointer is involved.
if '*' in nonconst:
return 'const ' + nonconst
else:
return nonconst

def toAtomicType(self):
return "OVSDB_TYPE_%s" % self.type.to_string().upper()

Expand Down

0 comments on commit 05ba459

Please sign in to comment.