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 <[email protected]> > > --- > > 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 <[email protected] > + * Alexander Graf <[email protected]>
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
signature.asc
Description: OpenPGP digital signature
