diff mbox series

[ovs-dev,v2] ofproto, ovsdb, vswitchd: Avoid using protected as variable name

Message ID 1512427077-106108-1-git-send-email-yihung.wei@gmail.com
State Changes Requested
Headers show
Series [ovs-dev,v2] ofproto, ovsdb, vswitchd: Avoid using protected as variable name | expand

Commit Message

Yi-Hung Wei Dec. 4, 2017, 10:37 p.m. UTC
In C++, 'protected' is a keyword. This patch renames 'protected'
to 'protected_' in a couple files so that C++ compiler will
not get confused.

Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com>
---
 ofproto/ofproto-dpif.c | 10 +++++-----
 ofproto/ofproto.h      |  2 +-
 ovsdb/ovsdb-idlc.1     |  6 ++++--
 ovsdb/ovsdb-idlc.in    | 18 ++++++++++++++++--
 vswitchd/bridge.c      |  2 +-
 5 files changed, 27 insertions(+), 11 deletions(-)

Comments

Ben Pfaff Dec. 8, 2017, 10:51 p.m. UTC | #1
On Mon, Dec 04, 2017 at 02:37:57PM -0800, Yi-Hung Wei wrote:
> In C++, 'protected' is a keyword. This patch renames 'protected'
> to 'protected_' in a couple files so that C++ compiler will
> not get confused.
> 
> Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com>
> ---
>  ofproto/ofproto-dpif.c | 10 +++++-----
>  ofproto/ofproto.h      |  2 +-
>  ovsdb/ovsdb-idlc.1     |  6 ++++--
>  ovsdb/ovsdb-idlc.in    | 18 ++++++++++++++++--
>  vswitchd/bridge.c      |  2 +-
>  5 files changed, 27 insertions(+), 11 deletions(-)

I don't think that any C++ code includes any of the .c or .h files that
this patch changes.  I don't think that even third-party C code should
be using these files.  If that is happening, then I want to discourage
that, not encourage it.  So, let's leave those files as-is (except as
necessary to work with the idlc changes).

C and C++ have many keywords, but this only lists a few of them.  Please
use a complete list.

Thanks,

Ben.
Yi-Hung Wei Dec. 12, 2017, 9:19 p.m. UTC | #2
On Fri, Dec 8, 2017 at 2:51 PM, Ben Pfaff <blp@ovn.org> wrote:
> I don't think that any C++ code includes any of the .c or .h files that
> this patch changes.  I don't think that even third-party C code should
> be using these files.  If that is happening, then I want to discourage
> that, not encourage it.  So, let's leave those files as-is (except as
> necessary to work with the idlc changes).
>
> C and C++ have many keywords, but this only lists a few of them.  Please
> use a complete list.
>
> Thanks,
>
> Ben.

Hi Ben,

Thanks for the review. I remove the unrelated changes in the .c an .h
files, and include a list of C and C++ keywords in a follow up patch.
Please find it here: https://patchwork.ozlabs.org/patch/847642/

Thanks,

-Yi-Hung
diff mbox series

Patch

diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index b99f04fad300..cdfd09ee2ee7 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -103,7 +103,7 @@  struct ofbundle {
     struct bond *bond;          /* Nonnull iff more than one port. */
     bool use_priority_tags;     /* Use 802.1p tag for frames in VLAN 0? */
 
-    bool protected;             /* Protected port mode */
+    bool protected_;             /* Protected port mode */
 
     /* Status. */
     bool floodable;          /* True if no port has OFPUTIL_PC_NO_FLOOD set. */
@@ -456,7 +456,7 @@  type_run(const char *type)
                                  bundle->vlan, bundle->trunks, bundle->cvlans,
                                  bundle->use_priority_tags,
                                  bundle->bond, bundle->lacp,
-                                 bundle->floodable, bundle->protected);
+                                 bundle->floodable, bundle->protected_);
             }
 
             HMAP_FOR_EACH (ofport, up.hmap_node, &ofproto->up.ports) {
@@ -3049,7 +3049,7 @@  bundle_set(struct ofproto *ofproto_, void *aux,
         bundle->bond = NULL;
 
         bundle->floodable = true;
-        bundle->protected = false;
+        bundle->protected_ = false;
         mbridge_register_bundle(ofproto->mbridge, bundle);
     }
 
@@ -3207,8 +3207,8 @@  bundle_set(struct ofproto *ofproto_, void *aux,
     }
 
     /* Set proteced port mode */
-    if (s->protected != bundle->protected) {
-        bundle->protected = s->protected;
+    if (s->protected_ != bundle->protected_) {
+        bundle->protected_ = s->protected_;
         need_flush = true;
     }
 
diff --git a/ofproto/ofproto.h b/ofproto/ofproto.h
index 1e48e1952aa2..c45b12041e85 100644
--- a/ofproto/ofproto.h
+++ b/ofproto/ofproto.h
@@ -414,7 +414,7 @@  struct ofproto_bundle_settings {
     struct lacp_settings *lacp;              /* Nonnull to enable LACP. */
     struct lacp_slave_settings *lacp_slaves; /* Array of n_slaves elements. */
 
-    bool protected;             /* Protected port mode */
+    bool protected_;             /* Protected port mode */
 };
 
 int ofproto_bundle_register(struct ofproto *, void *aux,
diff --git a/ovsdb/ovsdb-idlc.1 b/ovsdb/ovsdb-idlc.1
index b44757b820b8..393badfbd4da 100644
--- a/ovsdb/ovsdb-idlc.1
+++ b/ovsdb/ovsdb-idlc.1
@@ -50,11 +50,13 @@  modified is re-serialized as JSON on standard output.
 .
 .IP "\fBc\-idl\-header\fI idl\fR"
 Reads \fIidl\fR and prints on standard output a C header file that
-defines a structure for each table defined by the schema.
+defines a structure for each table defined by the schema.  If a column
+name in \fIidl\fR is a C++ keyword, it will be appended with an underscore.
 .
 .IP "\fBc\-idl\-source\fI idl\fR"
 Reads \fIidl\fR and prints on standard output a C source file that
-implements C bindings for the database defined by the schema.
+implements C bindings for the database defined by the schema.  If a column
+name in \fIidl\fR is a C++ keyword, it will be appended with an underscore.
 .
 .SS "Options"
 .so lib/common.man
diff --git a/ovsdb/ovsdb-idlc.in b/ovsdb/ovsdb-idlc.in
index c3973e4f5982..1ca1b977e049 100755
--- a/ovsdb/ovsdb-idlc.in
+++ b/ovsdb/ovsdb-idlc.in
@@ -122,8 +122,20 @@  def cMembers(prefix, tableName, columnName, column, const, refTable=True):
 def sorted_columns(table):
     return sorted(table.columns.items())
 
+# If a column name in the schema is a C++ keyword, append an underscore
+# to the column name.
+def replace_cplusplus_keyword(schema):
+    keywords = {'class', 'default', 'delete', 'mutable', 'new', 'private',
+                'protected', 'public'}
+
+    for tableName, table in schema.tables.items():
+        for columnName in table.columns:
+            if columnName in keywords:
+                table.columns[columnName + '_'] = table.columns.pop(columnName)
+
 def printCIDLHeader(schemaFile):
     schema = parseSchema(schemaFile)
+    replace_cplusplus_keyword(schema)
     prefix = schema.idlPrefix
     print('''\
 /* Generated automatically -- do not modify!    -*- buffer-read-only: t -*- */
@@ -328,6 +340,7 @@  def printEnum(type, members):
 
 def printCIDLSource(schemaFile):
     schema = parseSchema(schemaFile)
+    replace_cplusplus_keyword(schema)
     prefix = schema.idlPrefix
     print('''\
 /* Generated automatically -- do not modify!    -*- buffer-read-only: t -*- */
@@ -1273,7 +1286,7 @@  void
                                   for x in column.type.cInitType("%s_col_%s" % (tableName, columnName), prereqs))
             print("""\
     [%(P)s%(T)s_COL_%(C)s] = {
-         .name = "%(c)s",
+         .name = "%(column_name_in_schema)s",
          .type = {
 %(type)s
          },
@@ -1286,7 +1299,8 @@  void
                'C': columnName.upper(),
                's': structName,
                'mutable': mutable,
-               'type': type_init})
+               'type': type_init,
+               'column_name_in_schema': column.name})
         print("};")
 
     # Table classes.
diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
index 630c6fa535e2..66c6a1776c2b 100644
--- a/vswitchd/bridge.c
+++ b/vswitchd/bridge.c
@@ -1046,7 +1046,7 @@  port_configure(struct port *port)
     }
 
     /* Protected port mode */
-    s.protected = cfg->protected;
+    s.protected_ = cfg->protected_;
 
     /* Register. */
     ofproto_bundle_register(port->bridge->ofproto, port, &s);