Patchwork [v2,3/6] qapi: avoid reserved keywords

login
register
mail settings
Submitter Blue Swirl
Date Aug. 1, 2012, 6:21 p.m.
Message ID <5b7f43cadcf27396ce5b40f7505a08cc36b2e6cd.1343845033.git.blauwirbel@gmail.com>
Download mbox | patch
Permalink /patch/174563/
State New
Headers show

Comments

Blue Swirl - Aug. 1, 2012, 6:21 p.m.
Clang compiler complained about use of reserved word 'restrict' in SLIRP
and QAPI.

Prefix C keywords with "q_", adjust SLIRP accordingly.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
 net/slirp.c     |    6 +++---
 scripts/qapi.py |   16 ++++++++++++++++
 2 files changed, 19 insertions(+), 3 deletions(-)
Markus Armbruster - Aug. 2, 2012, 8:32 a.m.
Blue Swirl <blauwirbel@gmail.com> writes:

> Clang compiler complained about use of reserved word 'restrict' in SLIRP
> and QAPI.
>
> Prefix C keywords with "q_", adjust SLIRP accordingly.
>
> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>

I like this solution.

Reviewed-by: Markus Armbruster <armbru@redhat.com>
Luiz Capitulino - Aug. 2, 2012, 8:52 p.m.
On Thu, 02 Aug 2012 10:32:59 +0200
Markus Armbruster <armbru@redhat.com> wrote:

> Blue Swirl <blauwirbel@gmail.com> writes:
> 
> > Clang compiler complained about use of reserved word 'restrict' in SLIRP
> > and QAPI.
> >
> > Prefix C keywords with "q_", adjust SLIRP accordingly.
> >
> > Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
> 
> I like this solution.

Yeah, looks good.

Would be nice to add a note to docs/writing-qmp-commands.txt (can be in an
incremental patch).

> 
> Reviewed-by: Markus Armbruster <armbru@redhat.com>
>

Patch

diff --git a/net/slirp.c b/net/slirp.c
index 5c2e6b2..b818ea2 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -722,9 +722,9 @@  int net_init_slirp(const NetClientOptions *opts, const char *name,
     net_init_slirp_configs(user->hostfwd, SLIRP_CFG_HOSTFWD);
     net_init_slirp_configs(user->guestfwd, 0);
 
-    ret = net_slirp_init(vlan, "user", name, user->restrict, vnet, user->host,
-                         user->hostname, user->tftp, user->bootfile,
-                         user->dhcpstart, user->dns, user->smb,
+    ret = net_slirp_init(vlan, "user", name, user->q_restrict, vnet,
+                         user->host, user->hostname, user->tftp,
+                         user->bootfile, user->dhcpstart, user->dns, user->smb,
                          user->smbserver);
 
     while (slirp_configs) {
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 8082af3..80f28f8 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -131,6 +131,22 @@  def camel_case(name):
     return new_name
 
 def c_var(name):
+    # ANSI X3J11/88-090, 3.1.1
+    c89_words = set(['auto', 'break', 'case', 'char', 'const', 'continue',
+                     'default', 'do', 'double', 'else', 'enum', 'extern', 'float',
+                     'for', 'goto', 'if', 'int', 'long', 'register', 'return',
+                     'short', 'signed', 'sizeof', 'static', 'struct', 'switch',
+                     'typedef', 'union', 'unsigned', 'void', 'volatile', 'while'])
+    # ISO/IEC 9899:1999, 6.4.1
+    c99_words = set(['inline', 'restrict', '_Bool', '_Complex', '_Imaginary'])
+    # ISO/IEC 9899:2011, 6.4.1
+    c11_words = set(['_Alignas', '_Alignof', '_Atomic', '_Generic', '_Noreturn',
+                     '_Static_assert', '_Thread_local'])
+    # GCC http://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/C-Extensions.html
+    # excluding _.*
+    gcc_words = set(['asm', 'typeof'])
+    if name in c89_words | c99_words | c11_words | gcc_words:
+        return "q_" + name
     return name.replace('-', '_').lstrip("*")
 
 def c_fun(name):