From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52057) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZaTq0-0007l1-2w for qemu-devel@nongnu.org; Fri, 11 Sep 2015 15:18:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZaTpz-0001r6-4N for qemu-devel@nongnu.org; Fri, 11 Sep 2015 15:18:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40637) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZaTpy-0001qu-Vl for qemu-devel@nongnu.org; Fri, 11 Sep 2015 15:18:19 -0400 From: Markus Armbruster Date: Fri, 11 Sep 2015 21:17:55 +0200 Message-Id: <1441999089-28960-13-git-send-email-armbru@redhat.com> In-Reply-To: <1441999089-28960-1-git-send-email-armbru@redhat.com> References: <1441999089-28960-1-git-send-email-armbru@redhat.com> Subject: [Qemu-devel] [PATCH v6 12/26] qapi: Replace dirty is_c_ptr() by method c_null() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: mdroth@linux.vnet.ibm.com is_c_ptr() looks whether the end of the C text for the type looks like a pointer. Works, but is fragile. We now have a better tool: use QAPISchemaType method c_null(). The initializers for non-pointers become prettier: 0, false or the enumeration constant with the value 0 instead of {0}. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- scripts/qapi-commands.py | 16 +++++----------- scripts/qapi.py | 3 --- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py index a68517a..cbff356 100644 --- a/scripts/qapi-commands.py +++ b/scripts/qapi-commands.py @@ -91,18 +91,12 @@ def gen_visitor_input_vars_decl(args): bool has_%(argname)s = false; ''', argname=c_name(memb.name)) - if is_c_ptr(memb.type.c_type()): - ret += mcgen(''' -%(argtype)s %(argname)s = NULL; + ret += mcgen(''' +%(c_type)s %(c_name)s = %(c_null)s; ''', - argname=c_name(memb.name), - argtype=memb.type.c_type()) - else: - ret += mcgen(''' -%(argtype)s %(argname)s = {0}; -''', - argname=c_name(memb.name), - argtype=memb.type.c_type()) + c_name=c_name(memb.name), + c_type=memb.type.c_type(), + c_null=memb.type.c_null()) pop_indent() return ret diff --git a/scripts/qapi.py b/scripts/qapi.py index e1268f4..0f9537d 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -1430,9 +1430,6 @@ def c_type(value, is_param=False): assert isinstance(value, str) and value != "" return c_name(value) + pointer_suffix -def is_c_ptr(value): - return value.endswith(pointer_suffix) - def genindent(count): ret = "" for i in range(count): -- 2.4.3