Re: [PATCH 6/9] util: json: Improve handling and docs for adding JSON objects

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 10/14/2014 03:29 AM, Peter Krempa wrote:
> The JSON structure constructor has an option to add JSON arrays to the
> constructed object. The description is inaccurate as it can add any json
> object even a dict. Change the docs to cover this option and add
> possibility to specify NULL object to be added. These will be skipped as
> we have with other specifiers.
> ---
>  src/util/virjson.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
> 

Seems reasonable and I assume in line with other uses although I could
see cause for making two patches...

#1 to handle the error of 'a' nothing having 'args'

and

#2 to allow 'A' to avoid that check.

Your call if you want to make that split and how it could be used to
resolve some unknown bug...

> diff --git a/src/util/virjson.c b/src/util/virjson.c
> index 0dfeaed..f490f2c 100644
> --- a/src/util/virjson.c
> +++ b/src/util/virjson.c
> @@ -97,8 +97,9 @@ struct _virJSONParser {
>   *
>   * d: double precision floating point number
>   * n: json null value
> - * a: json array
>   *
> + * a: json object, must be non-NULL
> + * A: json object, omitted if NULL

NIT: there used to be an empty line between "a" and the following
comment and that's now removed...  Consider adding it back in.  I like
the spacing between 'n' and 'a'...


ACK,

John

>   * The value corresponds to the selected type.
>   *
>   * Returns -1 on error. 1 on success, if at least one key:pair was valid 0
> @@ -229,8 +230,20 @@ virJSONValueObjectCreateVArgs(virJSONValuePtr *obj, va_list args)
>              rc = virJSONValueObjectAppendNull(jargs, key);
>          }   break;
> 
> +        case 'A':
>          case 'a': {
>              virJSONValuePtr val = va_arg(args, virJSONValuePtr);
> +
> +            if (!val) {
> +                if (type == 'A')
> +                    continue;
> +
> +                virReportError(VIR_ERR_INTERNAL_ERROR,
> +                               _("argument key '%s' must not have null value"),
> +                               key);
> +                goto cleanup;
> +            }
> +
>              rc = virJSONValueObjectAppend(jargs, key, val);
>          }   break;
> 

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]