Patchwork [1/9] QJSON: Introduce qobject_from_json_va()

login
register
mail settings
Submitter Luiz Capitulino
Date Nov. 12, 2009, 8:42 p.m.
Message ID <1258058554-22872-2-git-send-email-lcapitulino@redhat.com>
Download mbox | patch
Permalink /patch/38278/
State New
Headers show

Comments

Luiz Capitulino - Nov. 12, 2009, 8:42 p.m.
Accepts a va_list, will be used by QError.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 qjson.c |   14 ++++++++++++++
 qjson.h |    2 ++
 2 files changed, 16 insertions(+), 0 deletions(-)
Anthony Liguori - Nov. 12, 2009, 9:39 p.m.
Luiz Capitulino wrote:
> Accepts a va_list, will be used by QError.
>
> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> ---
>  qjson.c |   14 ++++++++++++++
>  qjson.h |    2 ++
>  2 files changed, 16 insertions(+), 0 deletions(-)
>
> diff --git a/qjson.c b/qjson.c
> index 7270909..491b61e 100644
> --- a/qjson.c
> +++ b/qjson.c
> @@ -64,6 +64,20 @@ QObject *qobject_from_jsonf(const char *string, ...)
>      return state.result;
>  }
>  
> +QObject *qobject_from_json_va(const char *string, va_list *ap)
> +{
> +    JSONParsingState state = {};
> +
> +    state.ap = ap;
> +
> +    json_message_parser_init(&state.parser, parse_json);
> +    json_message_parser_feed(&state.parser, string, strlen(string));
> +    json_message_parser_flush(&state.parser);
> +    json_message_parser_destroy(&state.parser);
> +
> +    return state.result;
> +}
> +
>   

qobject_from_jsonf() should just call qobject_from_json_va().

>  typedef struct ToJsonIterState
>  {
>      int count;
> diff --git a/qjson.h b/qjson.h
> index 7fce742..8b89e41 100644
> --- a/qjson.h
> +++ b/qjson.h
> @@ -14,12 +14,14 @@
>  #ifndef QJSON_H
>  #define QJSON_H
>  
> +#include <stdarg.h>
>   

qemu-common.h is a better way to get stdarg.h

>  #include "qobject.h"
>  #include "qstring.h"
>  
>  QObject *qobject_from_json(const char *string);
>  QObject *qobject_from_jsonf(const char *string, ...)
>      __attribute__((__format__ (__printf__, 1, 2)));
> +QObject *qobject_from_json_va(const char *string, va_list *ap);
>  
>  QString *qobject_to_json(const QObject *obj);
>  
>   

Regards,

Anthony Liguori
Luiz Capitulino - Nov. 13, 2009, 12:31 p.m.
On Thu, 12 Nov 2009 15:39:14 -0600
Anthony Liguori <anthony@codemonkey.ws> wrote:

> Luiz Capitulino wrote:
> > Accepts a va_list, will be used by QError.
> >
> > Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> > ---
> >  qjson.c |   14 ++++++++++++++
> >  qjson.h |    2 ++
> >  2 files changed, 16 insertions(+), 0 deletions(-)
> >
> > diff --git a/qjson.c b/qjson.c
> > index 7270909..491b61e 100644
> > --- a/qjson.c
> > +++ b/qjson.c
> > @@ -64,6 +64,20 @@ QObject *qobject_from_jsonf(const char *string, ...)
> >      return state.result;
> >  }
> >  
> > +QObject *qobject_from_json_va(const char *string, va_list *ap)
> > +{
> > +    JSONParsingState state = {};
> > +
> > +    state.ap = ap;
> > +
> > +    json_message_parser_init(&state.parser, parse_json);
> > +    json_message_parser_feed(&state.parser, string, strlen(string));
> > +    json_message_parser_flush(&state.parser);
> > +    json_message_parser_destroy(&state.parser);
> > +
> > +    return state.result;
> > +}
> > +
> >   
> 
> qobject_from_jsonf() should just call qobject_from_json_va().

 Right.

> >  typedef struct ToJsonIterState
> >  {
> >      int count;
> > diff --git a/qjson.h b/qjson.h
> > index 7fce742..8b89e41 100644
> > --- a/qjson.h
> > +++ b/qjson.h
> > @@ -14,12 +14,14 @@
> >  #ifndef QJSON_H
> >  #define QJSON_H
> >  
> > +#include <stdarg.h>
> >   
> 
> qemu-common.h is a better way to get stdarg.h

 Why? I usually don't include qemu-common.h when all I need
are one or two headers.

Patch

diff --git a/qjson.c b/qjson.c
index 7270909..491b61e 100644
--- a/qjson.c
+++ b/qjson.c
@@ -64,6 +64,20 @@  QObject *qobject_from_jsonf(const char *string, ...)
     return state.result;
 }
 
+QObject *qobject_from_json_va(const char *string, va_list *ap)
+{
+    JSONParsingState state = {};
+
+    state.ap = ap;
+
+    json_message_parser_init(&state.parser, parse_json);
+    json_message_parser_feed(&state.parser, string, strlen(string));
+    json_message_parser_flush(&state.parser);
+    json_message_parser_destroy(&state.parser);
+
+    return state.result;
+}
+
 typedef struct ToJsonIterState
 {
     int count;
diff --git a/qjson.h b/qjson.h
index 7fce742..8b89e41 100644
--- a/qjson.h
+++ b/qjson.h
@@ -14,12 +14,14 @@ 
 #ifndef QJSON_H
 #define QJSON_H
 
+#include <stdarg.h>
 #include "qobject.h"
 #include "qstring.h"
 
 QObject *qobject_from_json(const char *string);
 QObject *qobject_from_jsonf(const char *string, ...)
     __attribute__((__format__ (__printf__, 1, 2)));
+QObject *qobject_from_json_va(const char *string, va_list *ap);
 
 QString *qobject_to_json(const QObject *obj);