From patchwork Wed Aug 31 21:25:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 664685 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (archives.nicira.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 3sPdjP0Mbfz9s8x for ; Thu, 1 Sep 2016 07:26:00 +1000 (AEST) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id D252F10975; Wed, 31 Aug 2016 14:25:52 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx1e4.cudamail.com (mx1.cudamail.com [69.90.118.67]) by archives.nicira.com (Postfix) with ESMTPS id 756A110885 for ; Wed, 31 Aug 2016 14:25:51 -0700 (PDT) Received: from bar5.cudamail.com (unknown [192.168.21.12]) by mx1e4.cudamail.com (Postfix) with ESMTPS id 8E39B1E029C for ; Wed, 31 Aug 2016 15:25:50 -0600 (MDT) X-ASG-Debug-ID: 1472678750-09eadd3356a2870001-byXFYA Received: from mx1-pf1.cudamail.com ([192.168.24.1]) by bar5.cudamail.com with ESMTP id onpMo2jwsRfqkYel (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Wed, 31 Aug 2016 15:25:50 -0600 (MDT) X-Barracuda-Envelope-From: blp@ovn.org X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.1 Received: from unknown (HELO relay3-d.mail.gandi.net) (217.70.183.195) by mx1-pf1.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 31 Aug 2016 21:25:49 -0000 Received-SPF: pass (mx1-pf1.cudamail.com: SPF record at ovn.org designates 217.70.183.195 as permitted sender) X-Barracuda-Apparent-Source-IP: 217.70.183.195 X-Barracuda-RBL-IP: 217.70.183.195 Received: from mfilter10-d.gandi.net (mfilter10-d.gandi.net [217.70.178.139]) by relay3-d.mail.gandi.net (Postfix) with ESMTP id 257DAA80D2; Wed, 31 Aug 2016 23:25:48 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter10-d.gandi.net Received: from relay3-d.mail.gandi.net ([IPv6:::ffff:217.70.183.195]) by mfilter10-d.gandi.net (mfilter10-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id 3CVXLXihK90k; Wed, 31 Aug 2016 23:25:46 +0200 (CEST) X-Originating-IP: 208.91.2.3 Received: from sigabrt.benpfaff.org (unknown [208.91.2.3]) (Authenticated sender: blp@ovn.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 9F90FA80D3; Wed, 31 Aug 2016 23:25:45 +0200 (CEST) X-CudaMail-Envelope-Sender: blp@ovn.org From: Ben Pfaff To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-E1-830074582 X-CudaMail-DTE: 083116 X-CudaMail-Originating-IP: 217.70.183.195 Date: Wed, 31 Aug 2016 14:25:40 -0700 X-ASG-Orig-Subj: [##CM-E1-830074582##][PATCH 1/2] ovsdb-idlc: Make set and map update operations take const arguments. Message-Id: <1472678741-15009-1-git-send-email-blp@ovn.org> X-Mailer: git-send-email 2.1.3 X-Barracuda-Connect: UNKNOWN[192.168.24.1] X-Barracuda-Start-Time: 1472678750 X-Barracuda-Encrypted: ECDHE-RSA-AES256-GCM-SHA384 X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 Cc: Ben Pfaff Subject: [ovs-dev] [PATCH 1/2] ovsdb-idlc: Make set and map update operations take const arguments. X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" 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 Acked-by: Russell Bryant --- 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()