Received: from eggs.gnu.org ([2001:4830:134:3::10]:42263) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLYrv-0004TF-Ng for qemu-devel@nongnu.org; Tue, 19 Jan 2016 11:11:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aLYrq-0001z6-SV for qemu-devel@nongnu.org; Tue, 19 Jan 2016 11:10:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44477) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLYrq-0001yq-Mh for qemu-devel@nongnu.org; Tue, 19 Jan 2016 11:10:50 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 71791C0A8477 for ; Tue, 19 Jan 2016 16:10:50 +0000 (UTC) From: Eric Blake Date: Tue, 19 Jan 2016 09:10:13 -0700 Message-Id: <1453219845-30939-6-git-send-email-eblake@redhat.com> In-Reply-To: <1453219845-30939-1-git-send-email-eblake@redhat.com> References: <1453219845-30939-1-git-send-email-eblake@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v9 05/37] vl: Improve use of qapi visitor List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: marcandre.lureau@redhat.com, armbru@redhat.com, Paolo Bonzini Cache the visitor in a local variable instead of repeatedly calling the accessor. Pass NULL for the visit_start_struct() object (which matches the fact that we were already passing 0 for the size argument, because we aren't using the visit to allocate a qapi struct). Guarantee that visit_end_struct() is called if visit_start_struct() succeeded. Signed-off-by: Eric Blake Reviewed-by: Marc-Andr=C3=A9 Lureau --- v9: no change v8: no change v7: place earlier in series, drop attempts to provide a 'kind' string, drop bogus avoidance of qmp_object_del() on error v6: new patch, split from RFC on v5 7/46 --- vl.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/vl.c b/vl.c index f043009..aaa5403 100644 --- a/vl.c +++ b/vl.c @@ -2822,44 +2822,47 @@ static bool object_create_delayed(const char *typ= e) static int object_create(void *opaque, QemuOpts *opts, Error **errp) { Error *err =3D NULL; + Error *err_end =3D NULL; char *type =3D NULL; char *id =3D NULL; - void *dummy =3D NULL; OptsVisitor *ov; QDict *pdict; bool (*type_predicate)(const char *) =3D opaque; + Visitor *v; ov =3D opts_visitor_new(opts); pdict =3D qemu_opts_to_qdict(opts, NULL); + v =3D opts_get_visitor(ov); - visit_start_struct(opts_get_visitor(ov), &dummy, NULL, NULL, 0, &err= ); + visit_start_struct(v, NULL, NULL, NULL, 0, &err); if (err) { goto out; } qdict_del(pdict, "qom-type"); - visit_type_str(opts_get_visitor(ov), &type, "qom-type", &err); + visit_type_str(v, &type, "qom-type", &err); if (err) { goto out; } if (!type_predicate(type)) { + visit_end_struct(v, NULL); goto out; } qdict_del(pdict, "id"); - visit_type_str(opts_get_visitor(ov), &id, "id", &err); + visit_type_str(v, &id, "id", &err); if (err) { - goto out; + goto out_end; } - object_add(type, id, pdict, opts_get_visitor(ov), &err); - if (err) { - goto out; - } - visit_end_struct(opts_get_visitor(ov), &err); - if (err) { + object_add(type, id, pdict, v, &err); + +out_end: + visit_end_struct(v, &err_end); + if (!err && err_end) { qmp_object_del(id, NULL); } + error_propagate(&err, err_end); out: opts_visitor_cleanup(ov); @@ -2867,7 +2870,6 @@ out: QDECREF(pdict); g_free(id); g_free(type); - g_free(dummy); if (err) { error_report_err(err); return -1; --=20 2.5.0