qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Amos Kong <akong@redhat.com>
To: lcapitulino@redhat.com, qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, armbru@redhat.com, mdroth@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH v4 2/3] qapi: add const prefix to 'char *' insider c_type()
Date: Thu,  8 May 2014 09:14:39 +0800	[thread overview]
Message-ID: <1399511680-12811-3-git-send-email-akong@redhat.com> (raw)
In-Reply-To: <1399511680-12811-1-git-send-email-akong@redhat.com>

It's ugly to add const prefix for parameter type by a if statement
outsider c_type(). This patch adds a parameter to do it.

Signed-off-by: Amos Kong <akong@redhat.com>
Suggested-by: Markus Armbruster <armbru@redhat.com>
---
 scripts/qapi-commands.py | 4 +---
 scripts/qapi.py          | 4 +++-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index 8d9096f..8f8a258 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -26,9 +26,7 @@ def type_visitor(name):
 def generate_command_decl(name, args, ret_type):
     arglist=""
     for argname, argtype, optional, structured in parse_args(args):
-        argtype = c_type(argtype)
-        if argtype == "char *":
-            argtype = "const char *"
+        argtype = c_type(argtype, is_param=True)
         if optional:
             arglist += "bool has_%s, " % c_var(argname)
         arglist += "%s %s, " % (argtype, c_var(argname))
diff --git a/scripts/qapi.py b/scripts/qapi.py
index ec806aa..1bc2bd9 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -462,8 +462,10 @@ def find_enum(name):
 def is_enum(name):
     return find_enum(name) != None
 
-def c_type(name):
+def c_type(name, is_param=False):
     if name == 'str':
+        if is_param:
+            return 'const char *'
         return 'char *'
     elif name == 'int':
         return 'int64_t'
-- 
1.9.0

  parent reply	other threads:[~2014-05-08  1:15 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-08  1:14 [Qemu-devel] [PATCH v4 0/3] qapi: fix coding style in generated code Amos Kong
2014-05-08  1:14 ` [Qemu-devel] [PATCH v4 1/3] qapi: fix coding style in parameters list Amos Kong
2014-05-13  2:57   ` Eric Blake
2014-05-21  2:08     ` Amos Kong
2014-05-08  1:14 ` Amos Kong [this message]
2014-05-13  2:59   ` [Qemu-devel] [PATCH v4 2/3] qapi: add const prefix to 'char *' insider c_type() Eric Blake
2014-05-08  1:14 ` [Qemu-devel] [PATCH v4 3/3] qapi: Suppress unwanted space between type and identifier Amos Kong
2014-05-15 19:36   ` Eric Blake
2014-05-15 19:05 ` [Qemu-devel] [PATCH v4 0/3] qapi: fix coding style in generated code Luiz Capitulino
2014-05-16 10:56   ` Paolo Bonzini
2014-05-16 14:19 ` Luiz Capitulino
2014-05-22 11:57   ` Amos Kong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1399511680-12811-3-git-send-email-akong@redhat.com \
    --to=akong@redhat.com \
    --cc=armbru@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).