Received: from eggs.gnu.org ([2001:4830:134:3::10]:42495) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkXLf-0001h4-Hr for qemu-devel@nongnu.org; Thu, 15 Sep 2016 10:09:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bkXLZ-00046Z-PZ for qemu-devel@nongnu.org; Thu, 15 Sep 2016 10:09:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46280) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkXLZ-00045v-GG for qemu-devel@nongnu.org; Thu, 15 Sep 2016 10:09:01 -0400 Date: Thu, 15 Sep 2016 16:08:56 +0200 From: Kevin Wolf Message-ID: <20160915140856.GM4726@noname.redhat.com> References: <1473943523-20270-1-git-send-email-berrange@redhat.com> <1473943523-20270-6-git-send-email-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1473943523-20270-6-git-send-email-berrange@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v12 5/6] qapi: add a QObjectInputVisitor that does string conversion List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" Cc: qemu-devel@nongnu.org, Markus Armbruster , Max Reitz , =?iso-8859-1?Q?Marc-Andr=E9?= Lureau , Paolo Bonzini , Andreas =?iso-8859-1?Q?F=E4rber?= Am 15.09.2016 um 14:45 hat Daniel P. Berrange geschrieben: > Currently the QObjectInputVisitor assumes that all scalar > values are directly represented as their final types. > ie it assumes an 'int' is using QInt, and a 'bool' is > using QBool. >=20 > This adds an alternative constructor for QObjectInputVisitor > that will set it up such that it expects a QString for > all scalar types instead. >=20 > This makes it possible to use QObjectInputVisitor with a > QDict produced from QemuOpts, where everything is in > string format. >=20 > Reviewed-by: Marc-Andr=E9 Lureau > Signed-off-by: Daniel P. Berrange > @@ -314,6 +370,7 @@ static void qobject_input_type_str(Visitor *v, cons= t char *name, char **obj, > static void qobject_input_type_number(Visitor *v, const char *name, do= uble *obj, > Error **errp) > { > + > QObjectInputVisitor *qiv =3D to_qiv(v); > QObject *qobj =3D qobject_input_get_object(qiv, name, true); > QInt *qint; This doesn't look intentional. > @@ -335,6 +392,30 @@ static void qobject_input_type_number(Visitor *v, = const char *name, double *obj, > "number"); > } > =20 > +static void qobject_input_type_number_str(Visitor *v, const char *name= , > + double *obj, Error **errp) > +{ > + QObjectInputVisitor *qiv =3D to_qiv(v); > + QString *qstr =3D qobject_to_qstring(qobject_input_get_object(qiv,= name, > + true))= ; > + char *endp; > + > + if (!qstr || !qstr->string) { > + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "n= ull", > + "string"); > + return; > + } > + > + errno =3D 0; > + *obj =3D strtod(qstr->string, &endp); > + if (errno =3D=3D 0 && endp !=3D qstr->string && *endp =3D=3D '\0')= { > + return; > + } > + > + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null"= , > + "string"); This error message is misleading. It complains that it didn't get a string, while in fact it got a string that just didn't parse as a number. > +} > + > static void qobject_input_type_any(Visitor *v, const char *name, QObje= ct **obj, > Error **errp) > { The rest looks good to me. Kevin