[ovs-dev] [PATCH 1/2] ovsdb-idlc: Make set and map update operations take const arguments.

Ben Pfaff blp at ovn.org
Wed Aug 31 21:25:40 UTC 2016


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 <blp at ovn.org>
---
 ovsdb/ovsdb-idlc.in    | 38 +++++++++++++++++++-------------------
 python/ovs/db/types.py | 14 +++++++++++++-
 2 files changed, 32 insertions(+), 20 deletions(-)

diff --git a/ovsdb/ovsdb-idlc.in b/ovsdb/ovsdb-idlc.in
index db4fa32..79db4b4 100755
--- a/ovsdb/ovsdb-idlc.in
+++ b/ovsdb/ovsdb-idlc.in
@@ -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():
@@ -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")
@@ -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'
@@ -846,8 +846,8 @@ 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")
@@ -855,8 +855,8 @@ void
     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
@@ -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
@@ -904,8 +904,8 @@ 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")
@@ -913,8 +913,8 @@ void
     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
 
diff --git a/python/ovs/db/types.py b/python/ovs/db/types.py
index a87c83c..3550303 100644
--- a/python/ovs/db/types.py
+++ b/python/ovs/db/types.py
@@ -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.
@@ -352,6 +352,18 @@ class BaseType(object):
                     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()
 
-- 
2.1.3




More information about the dev mailing list