Received: from eggs.gnu.org ([2001:4830:134:3::10]:55660) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1blzL9-0004oq-Lp for qemu-devel@nongnu.org; Mon, 19 Sep 2016 10:14:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1blzL5-00054o-Ed for qemu-devel@nongnu.org; Mon, 19 Sep 2016 10:14:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57150) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1blzL5-00054K-5L for qemu-devel@nongnu.org; Mon, 19 Sep 2016 10:14:31 -0400 From: Markus Armbruster References: <1472117833-10236-1-git-send-email-dgilbert@redhat.com> <1472117833-10236-2-git-send-email-dgilbert@redhat.com> <87wpi8f310.fsf@dusky.pond.sub.org> <20160919134736.GC2041@work-vm> Date: Mon, 19 Sep 2016 16:14:27 +0200 In-Reply-To: <20160919134736.GC2041@work-vm> (David Alan Gilbert's message of "Mon, 19 Sep 2016 14:47:37 +0100") Message-ID: <871t0gdlj0.fsf@dusky.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 1/2] qapi: Stub out StringOutputVisitor struct support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Dr. David Alan Gilbert" Cc: kwolf@redhat.com, qemu-devel@nongnu.org, lcapitulino@redhat.com, arei.gonglei@huawei.com, pbonzini@redhat.com, afaerber@suse.de "Dr. David Alan Gilbert" writes: > * Markus Armbruster (armbru@redhat.com) wrote: >> "Dr. David Alan Gilbert (git)" writes: >>=20 >> > From: "Dr. David Alan Gilbert" >> > >> > Avoid a segfault when visiting, e.g., the QOM rtc-time property, >> > by implementing the struct callbacks and raising an Error. >> > >> > Signed-off-by: Andreas F=C3=A4rber >> > >> > Updated for changed interface: >> > Signed-off-by: Dr. David Alan Gilbert >> > --- >> > qapi/string-output-visitor.c | 13 +++++++++++++ >> > 1 file changed, 13 insertions(+) >> > >> > diff --git a/qapi/string-output-visitor.c b/qapi/string-output-visitor= .c >> > index 94ac821..4e7e97f 100644 >> > --- a/qapi/string-output-visitor.c >> > +++ b/qapi/string-output-visitor.c >> > @@ -12,6 +12,7 @@ >> >=20=20 >> > #include "qemu/osdep.h" >> > #include "qemu-common.h" >> > +#include "qapi/error.h" >> > #include "qapi/string-output-visitor.h" >> > #include "qapi/visitor-impl.h" >> > #include "qemu/host-utils.h" >> > @@ -266,6 +267,16 @@ static void print_type_number(Visitor *v, const c= har *name, double *obj, >> > string_output_set(sov, g_strdup_printf("%f", *obj)); >> > } >> >=20=20 >> > +static void start_struct(Visitor *v, const char *name, void **obj, si= ze_t size, >> > + Error **errp) >> > +{ >> > + error_setg(errp, "struct type not implemented"); >> > +} >> > + >> > +static void end_struct(Visitor *v, void **obj) >> > +{ >> > +} >> > + >>=20 >> This is just one of the several things this visitor doesn't implement. >> See the comment in string-output-visitor.h. >>=20 >> String input visitor and options visitor have similar holes; see the >> comments in string-input-visitor.h and opts-visitor.h. >>=20 >> Should we change all of them together to report errors instead of crash? >> With common "error out because this isn't implemented" methods? > > In that case wouldn't it be best to change visit_start_struct/visit_end_s= truct > to do the check (Like visit_check_struct does). In my opinion. if (v->foo) { v->foo(...); } else { ... default action ... } is an anti-pattern. Wrap the default action in a default method, and put that in the function pointer.