From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43821) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WiCvh-0003d0-C4 for qemu-devel@nongnu.org; Wed, 07 May 2014 21:15:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WiCvc-0008AB-Bi for qemu-devel@nongnu.org; Wed, 07 May 2014 21:15:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47009) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WiCvc-00089v-3R for qemu-devel@nongnu.org; Wed, 07 May 2014 21:15:16 -0400 From: Amos Kong Date: Thu, 8 May 2014 09:14:39 +0800 Message-Id: <1399511680-12811-3-git-send-email-akong@redhat.com> In-Reply-To: <1399511680-12811-1-git-send-email-akong@redhat.com> References: <1399511680-12811-1-git-send-email-akong@redhat.com> Subject: [Qemu-devel] [PATCH v4 2/3] qapi: add const prefix to 'char *' insider c_type() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: lcapitulino@redhat.com, qemu-devel@nongnu.org Cc: pbonzini@redhat.com, armbru@redhat.com, mdroth@linux.vnet.ibm.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 Suggested-by: Markus Armbruster --- 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