From patchwork Mon Sep 21 08:03:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 520172 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C9F78140180 for ; Mon, 21 Sep 2015 18:06:57 +1000 (AEST) Received: from localhost ([::1]:56496 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zdw7j-0007SL-UO for incoming@patchwork.ozlabs.org; Mon, 21 Sep 2015 04:06:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55758) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zdw52-0002pO-RH for qemu-devel@nongnu.org; Mon, 21 Sep 2015 04:04:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zdw51-0004vk-LL for qemu-devel@nongnu.org; Mon, 21 Sep 2015 04:04:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38659) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zdw51-0004vE-FV for qemu-devel@nongnu.org; Mon, 21 Sep 2015 04:04:07 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 1DDD5425A3 for ; Mon, 21 Sep 2015 08:04:07 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-38.ams2.redhat.com [10.36.116.38]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t8L844L6029095 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Mon, 21 Sep 2015 04:04:06 -0400 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 176883002548; Mon, 21 Sep 2015 10:04:02 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 21 Sep 2015 10:03:46 +0200 Message-Id: <1442822640-29912-13-git-send-email-armbru@redhat.com> In-Reply-To: <1442822640-29912-1-git-send-email-armbru@redhat.com> References: <1442822640-29912-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 12/26] qapi: Replace dirty is_c_ptr() by method c_null() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Reviewed-by: Daniel P. Berrange Message-Id: <1442401589-24189-13-git-send-email-armbru@redhat.com> --- 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 ba32aac..0ffd02d 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -1441,9 +1441,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):