qemu-devel
[Top][All Lists]
Advanced

[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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]