From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41020) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VN1Yk-00036C-Gn for qemu-devel@nongnu.org; Fri, 20 Sep 2013 10:19:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VN1Yc-0000Ua-0c for qemu-devel@nongnu.org; Fri, 20 Sep 2013 10:19:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:4108) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VN1Yb-0000UW-OK for qemu-devel@nongnu.org; Fri, 20 Sep 2013 10:19:41 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r8KEJdo2015774 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 20 Sep 2013 10:19:40 -0400 Date: Fri, 20 Sep 2013 16:19:44 +0200 From: Kevin Wolf Message-ID: <20130920141944.GG2800@dhcp-200-207.str.redhat.com> References: <1379678070-14346-1-git-send-email-kwolf@redhat.com> <1379678070-14346-3-git-send-email-kwolf@redhat.com> <523C4EC3.5010909@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <523C4EC3.5010909@redhat.com> Subject: Re: [Qemu-devel] [PATCH 02/17] qapi-types/visit.py: Inheritance for structs List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz Cc: qemu-devel@nongnu.org, stefanha@redhat.com, armbru@redhat.com Am 20.09.2013 um 15:33 hat Max Reitz geschrieben: > On 2013-09-20 13:54, Kevin Wolf wrote: > >This introduces a new 'base' key for struct definitions that refers to > >another struct type. On the JSON level, the fields of the base type are > >included directly into the same namespace as the fields of the defined > >type, like with unions. On the C level, a pointer to a struct of the > >base type is included. > > > >Signed-off-by: Kevin Wolf > >diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py > >index 1e44004..90cedd7 100644 > >--- a/scripts/qapi-visit.py > >+++ b/scripts/qapi-visit.py > >@@ -17,7 +17,7 @@ import os > > import getopt > > import errno > >-def generate_visit_struct_fields(name, field_prefix, fn_prefix, members): > >+def generate_visit_struct_fields(name, field_prefix, fn_prefix, members, base = None): > > substructs = [] > > ret = '' > > full_name = name if not fn_prefix else "%s_%s" % (name, fn_prefix) > >@@ -42,6 +42,19 @@ static void visit_type_%(full_name)s_fields(Visitor *m, %(name)s ** obj, Error * > > name=name, full_name=full_name) > > push_indent() > >+ if base: > >+ ret += mcgen(''' > >+visit_start_implicit_struct(m, (void**) &(*obj)->%(c_name)s, sizeof(%(type)s), &err); > Why do you just dereference obj here (implying it will never be NULL)... > > >+if (!err) { > >+ visit_type_%(type)s_fields(m, obj ? &(*obj)->%(c_prefix)s%(c_name)s : NULL, &err); > ...but then you're checking whether it is NULL before dereferencing? Because I'm clearly not understanding what I'm doing here... I can change the first line into this: visit_start_implicit_struct(m, obj ? (void**) &(*obj)->%(c_name)s : NULL, sizeof(%(type)s), &err); I'm not sure what cases it would fix, but the surrounding code looks like it's doing the check, so it can't hurt. visit_start_implicit_struct seems to be able to handle NULL pointers. Kevin