qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH v3 2/5] QJSON: Add JSON writer


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH v3 2/5] QJSON: Add JSON writer
Date: Tue, 06 Jan 2015 08:44:52 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0

On 12/26/2014 07:42 AM, Alexander Graf wrote:
> To support programmatic JSON assembly while keeping the code that generates it
> readable, this patch introduces a simple JSON writer. It emits JSON serially
> into a buffer in memory.
> 
> The nice thing about this writer is its simplicity and low memory overhead.
> Unlike the QMP JSON writer, this one does not need to spawn QObjects for every
> element it wants to represent.
> 
> This is a prerequisite for the migration stream format description generator.
> 
> Signed-off-by: Alexander Graf <address@hidden>
> 
> ---
> 
> v2 -> v3:
> 
>   - QOMify the QJSON object, makes for easier destruction
> ---
>  include/qjson.h |  3 ++-
>  qjson.c         | 39 ++++++++++++++++++++++++++++++++++++---
>  2 files changed, 38 insertions(+), 4 deletions(-)
> 
> diff --git a/include/qjson.h b/include/qjson.h
> index 8f8c145..7c54fdf 100644
> --- a/include/qjson.h
> +++ b/include/qjson.h
> @@ -4,7 +4,7 @@
>   * Copyright Alexander Graf
>   *
>   * Authors:
> - *  Alexander Graf <address@hidden
> + *  Alexander Graf <address@hidden>

Umm, this should be squashed into 1/5.

> @@ -85,9 +88,7 @@ const char *qjson_get_str(QJSON *json)
>  
>  QJSON *qjson_new(void)
>  {
> -    QJSON *json = g_new(QJSON, 1);
> -    json->str = qstring_from_str("{ ");
> -    json->omit_comma = true;
> +    QJSON *json = (QJSON *)object_new(TYPE_QJSON);
>      return json;

This undoes the dangling object that I complained about on patch 1;
maybe there's some more squashing to do?...


> +static void qjson_initfn(Object *obj)
> +{
> +    QJSON *json = (QJSON *)object_dynamic_cast(obj, TYPE_QJSON);
> +    assert(json);
> +
> +    json->str = qstring_from_str("{ ");
> +    json->omit_comma = true;

...or is it still an incomplete object, just now in a different location?

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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