[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v12 5/6] qapi: add a QObjectInputVisitor that do
From: |
Kevin Wolf |
Subject: |
Re: [Qemu-devel] [PATCH v12 5/6] qapi: add a QObjectInputVisitor that does string conversion |
Date: |
Thu, 15 Sep 2016 16:08:56 +0200 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
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.
>
> This adds an alternative constructor for QObjectInputVisitor
> that will set it up such that it expects a QString for
> all scalar types instead.
>
> This makes it possible to use QObjectInputVisitor with a
> QDict produced from QemuOpts, where everything is in
> string format.
>
> Reviewed-by: Marc-André Lureau <address@hidden>
> Signed-off-by: Daniel P. Berrange <address@hidden>
> @@ -314,6 +370,7 @@ static void qobject_input_type_str(Visitor *v, const char
> *name, char **obj,
> static void qobject_input_type_number(Visitor *v, const char *name, double
> *obj,
> Error **errp)
> {
> +
> QObjectInputVisitor *qiv = to_qiv(v);
> QObject *qobj = 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");
> }
>
> +static void qobject_input_type_number_str(Visitor *v, const char *name,
> + double *obj, Error **errp)
> +{
> + QObjectInputVisitor *qiv = to_qiv(v);
> + QString *qstr = 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 : "null",
> + "string");
> + return;
> + }
> +
> + errno = 0;
> + *obj = strtod(qstr->string, &endp);
> + if (errno == 0 && endp != qstr->string && *endp == '\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, QObject
> **obj,
> Error **errp)
> {
The rest looks good to me.
Kevin
- [Qemu-devel] [PATCH v12 0/6] QAPI/QOM work for non-scalar object properties, Daniel P. Berrange, 2016/09/15
- [Qemu-devel] [PATCH v12 2/6] option: make parse_option_bool/number non-static, Daniel P. Berrange, 2016/09/15
- [Qemu-devel] [PATCH v12 1/6] qdict: implement a qdict_crumple method for un-flattening a dict, Daniel P. Berrange, 2016/09/15
- [Qemu-devel] [PATCH v12 5/6] qapi: add a QObjectInputVisitor that does string conversion, Daniel P. Berrange, 2016/09/15
- Re: [Qemu-devel] [PATCH v12 5/6] qapi: add a QObjectInputVisitor that does string conversion,
Kevin Wolf <=
- [Qemu-devel] [PATCH v12 4/6] qapi: rename QmpOutputVisitor to QObjectOutputVisitor, Daniel P. Berrange, 2016/09/15
- [Qemu-devel] [PATCH v12 3/6] qapi: rename QmpInputVisitor to QObjectInputVisitor, Daniel P. Berrange, 2016/09/15
- [Qemu-devel] [PATCH v12 6/6] qom: support arbitrary non-scalar properties with -object, Daniel P. Berrange, 2016/09/15