diff mbox

[v3,2/3] qapi: add const prefix to 'char *' insider c_type()

Message ID 1398668558-16687-3-git-send-email-akong@redhat.com
State New
Headers show

Commit Message

Amos Kong April 28, 2014, 7:02 a.m. UTC
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(-)

Comments

Markus Armbruster April 28, 2014, 12:34 p.m. UTC | #1
Amos Kong <akong@redhat.com> writes:

> 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.

"outside".
diff mbox

Patch

diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index 9734ab0..c25bdcd 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 b474c39..a980594 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -421,8 +421,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'