All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] QJSON: Use OBJECT_CHECK
@ 2015-04-25 15:28 Eduardo Habkost
  2015-04-25 17:05 ` Andreas Färber
  2015-05-01 17:16 ` Luiz Capitulino
  0 siblings, 2 replies; 17+ messages in thread
From: Eduardo Habkost @ 2015-04-25 15:28 UTC (permalink / raw)
  To: qemu-devel; +Cc: agraf, Andreas Färber, Juan Quintela

The QJSON code used casts to (QJSON*) directly, instead of OBJECT_CHECK.
There were even some functions using object_dynamic_cast() calls
followed by assert(), which is exactly what OBJECT_CHECK does (by
calling object_dynamic_cast_assert()).

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 qjson.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/qjson.c b/qjson.c
index 0cda269..e478802 100644
--- a/qjson.c
+++ b/qjson.c
@@ -24,6 +24,8 @@ struct QJSON {
     bool omit_comma;
 };
 
+#define QJSON(obj) OBJECT_CHECK(QJSON, (obj), TYPE_QJSON)
+
 static void json_emit_element(QJSON *json, const char *name)
 {
     /* Check whether we need to print a , before an element */
@@ -87,7 +89,7 @@ const char *qjson_get_str(QJSON *json)
 
 QJSON *qjson_new(void)
 {
-    QJSON *json = (QJSON *)object_new(TYPE_QJSON);
+    QJSON *json = QJSON(object_new(TYPE_QJSON));
     return json;
 }
 
@@ -98,8 +100,7 @@ void qjson_finish(QJSON *json)
 
 static void qjson_initfn(Object *obj)
 {
-    QJSON *json = (QJSON *)object_dynamic_cast(obj, TYPE_QJSON);
-    assert(json);
+    QJSON *json = QJSON(obj);
 
     json->str = qstring_from_str("{ ");
     json->omit_comma = true;
@@ -107,9 +108,8 @@ static void qjson_initfn(Object *obj)
 
 static void qjson_finalizefn(Object *obj)
 {
-    QJSON *json = (QJSON *)object_dynamic_cast(obj, TYPE_QJSON);
+    QJSON *json = QJSON(obj);
 
-    assert(json);
     qobject_decref(QOBJECT(json->str));
 }
 
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [Qemu-devel] [PATCH] QJSON: Use OBJECT_CHECK
  2015-04-25 15:28 [Qemu-devel] [PATCH] QJSON: Use OBJECT_CHECK Eduardo Habkost
@ 2015-04-25 17:05 ` Andreas Färber
  2015-04-27 17:23   ` Eduardo Habkost
  2015-05-01 17:16 ` Luiz Capitulino
  1 sibling, 1 reply; 17+ messages in thread
From: Andreas Färber @ 2015-04-25 17:05 UTC (permalink / raw)
  To: Eduardo Habkost, qemu-devel; +Cc: agraf, Juan Quintela

Am 25.04.2015 um 17:28 schrieb Eduardo Habkost:
> The QJSON code used casts to (QJSON*) directly, instead of OBJECT_CHECK.
> There were even some functions using object_dynamic_cast() calls
> followed by assert(), which is exactly what OBJECT_CHECK does (by
> calling object_dynamic_cast_assert()).

Suggest s/OBJECT_CHECK/OBJECT_CHECK()/g everywhere for clarity.

> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  qjson.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)

Reviewed-by: Andreas Färber <afaerber@suse.de>

Wasn't aware QJSON is using QOM - assuming this will go through some
QAPI/QMP tree.

Regards,
Andreas

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Jennifer Guild, Dilip Upmanyu,
Graham Norton; HRB 21284 (AG Nürnberg)

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Qemu-devel] [PATCH] QJSON: Use OBJECT_CHECK
  2015-04-25 17:05 ` Andreas Färber
@ 2015-04-27 17:23   ` Eduardo Habkost
  2015-04-29 12:38     ` Luiz Capitulino
                       ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: Eduardo Habkost @ 2015-04-27 17:23 UTC (permalink / raw)
  To: Andreas Färber
  Cc: Luiz Capitulino, Michael Roth, Juan Quintela, qemu-devel, agraf

On Sat, Apr 25, 2015 at 07:05:55PM +0200, Andreas Färber wrote:
> Am 25.04.2015 um 17:28 schrieb Eduardo Habkost:
> > The QJSON code used casts to (QJSON*) directly, instead of OBJECT_CHECK.
> > There were even some functions using object_dynamic_cast() calls
> > followed by assert(), which is exactly what OBJECT_CHECK does (by
> > calling object_dynamic_cast_assert()).
> 
> Suggest s/OBJECT_CHECK/OBJECT_CHECK()/g everywhere for clarity.

I assume it can be fixed during commit by whoever is going to queue it.

> 
> > 
> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > ---
> >  qjson.c | 10 +++++-----
> >  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> Reviewed-by: Andreas Färber <afaerber@suse.de>
> 
> Wasn't aware QJSON is using QOM - assuming this will go through some
> QAPI/QMP tree.

The only user of qjson.c right now is migration code. Should it go through
the migration tree?

Also, why do we have two JSON writers in QEMU? And why do they have
exactly the same name?

-- 
Eduardo

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Qemu-devel] [PATCH] QJSON: Use OBJECT_CHECK
  2015-04-27 17:23   ` Eduardo Habkost
@ 2015-04-29 12:38     ` Luiz Capitulino
  2015-04-29 12:46       ` Andreas Färber
  2015-04-29 12:55       ` Eduardo Habkost
  2015-04-29 19:18     ` Paolo Bonzini
  2015-05-05 12:43     ` Juan Quintela
  2 siblings, 2 replies; 17+ messages in thread
From: Luiz Capitulino @ 2015-04-29 12:38 UTC (permalink / raw)
  To: Eduardo Habkost
  Cc: Michael Roth, agraf, Juan Quintela, Andreas Färber, qemu-devel

On Mon, 27 Apr 2015 14:23:20 -0300
Eduardo Habkost <ehabkost@redhat.com> wrote:

> On Sat, Apr 25, 2015 at 07:05:55PM +0200, Andreas Färber wrote:
> > Am 25.04.2015 um 17:28 schrieb Eduardo Habkost:
> > > The QJSON code used casts to (QJSON*) directly, instead of OBJECT_CHECK.
> > > There were even some functions using object_dynamic_cast() calls
> > > followed by assert(), which is exactly what OBJECT_CHECK does (by
> > > calling object_dynamic_cast_assert()).
> > 
> > Suggest s/OBJECT_CHECK/OBJECT_CHECK()/g everywhere for clarity.

Everywhere? You mean, in other places? In this case someone has to
post a different patch.

> I assume it can be fixed during commit by whoever is going to queue it.
> 
> > 
> > > 
> > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > > ---
> > >  qjson.c | 10 +++++-----
> > >  1 file changed, 5 insertions(+), 5 deletions(-)
> > 
> > Reviewed-by: Andreas Färber <afaerber@suse.de>
> > 
> > Wasn't aware QJSON is using QOM - assuming this will go through some
> > QAPI/QMP tree.
> 
> The only user of qjson.c right now is migration code. Should it go through
> the migration tree?

It could be, but I can take it if nobody does.

> Also, why do we have two JSON writers in QEMU? And why do they have
> exactly the same name?

Not sure I got it, which writers?

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Qemu-devel] [PATCH] QJSON: Use OBJECT_CHECK
  2015-04-29 12:38     ` Luiz Capitulino
@ 2015-04-29 12:46       ` Andreas Färber
  2015-04-29 12:54         ` Luiz Capitulino
  2015-04-29 12:55       ` Eduardo Habkost
  1 sibling, 1 reply; 17+ messages in thread
From: Andreas Färber @ 2015-04-29 12:46 UTC (permalink / raw)
  To: Luiz Capitulino
  Cc: Michael Roth, agraf, Juan Quintela, Eduardo Habkost, qemu-devel

Am 29.04.2015 um 14:38 schrieb Luiz Capitulino:
> On Mon, 27 Apr 2015 14:23:20 -0300
> Eduardo Habkost <ehabkost@redhat.com> wrote:
> 
>> On Sat, Apr 25, 2015 at 07:05:55PM +0200, Andreas Färber wrote:
>>> Am 25.04.2015 um 17:28 schrieb Eduardo Habkost:
>>>> The QJSON code used casts to (QJSON*) directly, instead of OBJECT_CHECK.
>>>> There were even some functions using object_dynamic_cast() calls
>>>> followed by assert(), which is exactly what OBJECT_CHECK does (by
>>>> calling object_dynamic_cast_assert()).
>>>
>>> Suggest s/OBJECT_CHECK/OBJECT_CHECK()/g everywhere for clarity.
> 
> Everywhere? You mean, in other places?

No, I count 3x in commit message including subject.

Andreas

> In this case someone has to
> post a different patch.
> 
>> I assume it can be fixed during commit by whoever is going to queue it.
>>
>>>
>>>>
>>>> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
>>>> ---
>>>>  qjson.c | 10 +++++-----
>>>>  1 file changed, 5 insertions(+), 5 deletions(-)
>>>
>>> Reviewed-by: Andreas Färber <afaerber@suse.de>
>>>
>>> Wasn't aware QJSON is using QOM - assuming this will go through some
>>> QAPI/QMP tree.
>>
>> The only user of qjson.c right now is migration code. Should it go through
>> the migration tree?
> 
> It could be, but I can take it if nobody does.
> 
>> Also, why do we have two JSON writers in QEMU? And why do they have
>> exactly the same name?
> 
> Not sure I got it, which writers?
> 


-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Jennifer Guild, Dilip Upmanyu,
Graham Norton; HRB 21284 (AG Nürnberg)

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Qemu-devel] [PATCH] QJSON: Use OBJECT_CHECK
  2015-04-29 12:46       ` Andreas Färber
@ 2015-04-29 12:54         ` Luiz Capitulino
  0 siblings, 0 replies; 17+ messages in thread
From: Luiz Capitulino @ 2015-04-29 12:54 UTC (permalink / raw)
  To: Andreas Färber
  Cc: Michael Roth, agraf, Juan Quintela, Eduardo Habkost, qemu-devel

On Wed, 29 Apr 2015 14:46:38 +0200
Andreas Färber <afaerber@suse.de> wrote:

> Am 29.04.2015 um 14:38 schrieb Luiz Capitulino:
> > On Mon, 27 Apr 2015 14:23:20 -0300
> > Eduardo Habkost <ehabkost@redhat.com> wrote:
> > 
> >> On Sat, Apr 25, 2015 at 07:05:55PM +0200, Andreas Färber wrote:
> >>> Am 25.04.2015 um 17:28 schrieb Eduardo Habkost:
> >>>> The QJSON code used casts to (QJSON*) directly, instead of OBJECT_CHECK.
> >>>> There were even some functions using object_dynamic_cast() calls
> >>>> followed by assert(), which is exactly what OBJECT_CHECK does (by
> >>>> calling object_dynamic_cast_assert()).
> >>>
> >>> Suggest s/OBJECT_CHECK/OBJECT_CHECK()/g everywhere for clarity.
> > 
> > Everywhere? You mean, in other places?
> 
> No, I count 3x in commit message including subject.

Ah, the problem is the *commit* message. Okay...

> 
> Andreas
> 
> > In this case someone has to
> > post a different patch.
> > 
> >> I assume it can be fixed during commit by whoever is going to queue it.
> >>
> >>>
> >>>>
> >>>> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> >>>> ---
> >>>>  qjson.c | 10 +++++-----
> >>>>  1 file changed, 5 insertions(+), 5 deletions(-)
> >>>
> >>> Reviewed-by: Andreas Färber <afaerber@suse.de>
> >>>
> >>> Wasn't aware QJSON is using QOM - assuming this will go through some
> >>> QAPI/QMP tree.
> >>
> >> The only user of qjson.c right now is migration code. Should it go through
> >> the migration tree?
> > 
> > It could be, but I can take it if nobody does.
> > 
> >> Also, why do we have two JSON writers in QEMU? And why do they have
> >> exactly the same name?
> > 
> > Not sure I got it, which writers?
> > 
> 
> 

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Qemu-devel] [PATCH] QJSON: Use OBJECT_CHECK
  2015-04-29 12:38     ` Luiz Capitulino
  2015-04-29 12:46       ` Andreas Färber
@ 2015-04-29 12:55       ` Eduardo Habkost
  2015-04-29 13:00         ` Luiz Capitulino
  2015-05-01 16:19         ` Michael Roth
  1 sibling, 2 replies; 17+ messages in thread
From: Eduardo Habkost @ 2015-04-29 12:55 UTC (permalink / raw)
  To: Luiz Capitulino
  Cc: qemu-devel, Juan Quintela, Michael Roth, Andreas Färber, agraf

On Wed, Apr 29, 2015 at 08:38:02AM -0400, Luiz Capitulino wrote:
> On Mon, 27 Apr 2015 14:23:20 -0300
> Eduardo Habkost <ehabkost@redhat.com> wrote:
> 
> > On Sat, Apr 25, 2015 at 07:05:55PM +0200, Andreas Färber wrote:
> > > Am 25.04.2015 um 17:28 schrieb Eduardo Habkost:
> > > > The QJSON code used casts to (QJSON*) directly, instead of OBJECT_CHECK.
> > > > There were even some functions using object_dynamic_cast() calls
> > > > followed by assert(), which is exactly what OBJECT_CHECK does (by
> > > > calling object_dynamic_cast_assert()).
> > > 
> > > Suggest s/OBJECT_CHECK/OBJECT_CHECK()/g everywhere for clarity.
> 
> Everywhere? You mean, in other places? In this case someone has to
> post a different patch.

Just in the commit message.

> 
> > I assume it can be fixed during commit by whoever is going to queue it.
> > 
> > > 
> > > > 
> > > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > > > ---
> > > >  qjson.c | 10 +++++-----
> > > >  1 file changed, 5 insertions(+), 5 deletions(-)
> > > 
> > > Reviewed-by: Andreas Färber <afaerber@suse.de>
> > > 
> > > Wasn't aware QJSON is using QOM - assuming this will go through some
> > > QAPI/QMP tree.
> > 
> > The only user of qjson.c right now is migration code. Should it go through
> > the migration tree?
> 
> It could be, but I can take it if nobody does.

Thanks!

> 
> > Also, why do we have two JSON writers in QEMU? And why do they have
> > exactly the same name?
> 
> Not sure I got it, which writers?

qjson.c and qobject/qjson.c:to_json().

-- 
Eduardo

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Qemu-devel] [PATCH] QJSON: Use OBJECT_CHECK
  2015-04-29 12:55       ` Eduardo Habkost
@ 2015-04-29 13:00         ` Luiz Capitulino
  2015-05-01 16:19         ` Michael Roth
  1 sibling, 0 replies; 17+ messages in thread
From: Luiz Capitulino @ 2015-04-29 13:00 UTC (permalink / raw)
  To: Eduardo Habkost
  Cc: qemu-devel, Juan Quintela, Michael Roth, Andreas Färber, agraf

On Wed, 29 Apr 2015 09:55:48 -0300
Eduardo Habkost <ehabkost@redhat.com> wrote:

> > > Also, why do we have two JSON writers in QEMU? And why do they have
> > > exactly the same name?
> > 
> > Not sure I got it, which writers?
> 
> qjson.c and qobject/qjson.c:to_json().

Hmm, yeah, you're right.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Qemu-devel] [PATCH] QJSON: Use OBJECT_CHECK
  2015-04-27 17:23   ` Eduardo Habkost
  2015-04-29 12:38     ` Luiz Capitulino
@ 2015-04-29 19:18     ` Paolo Bonzini
  2015-05-01 12:04       ` Eduardo Habkost
  2015-05-05 12:43     ` Juan Quintela
  2 siblings, 1 reply; 17+ messages in thread
From: Paolo Bonzini @ 2015-04-29 19:18 UTC (permalink / raw)
  To: Eduardo Habkost, Andreas Färber
  Cc: qemu-devel, agraf, Juan Quintela, Michael Roth, Luiz Capitulino



On 27/04/2015 19:23, Eduardo Habkost wrote:
> Also, why do we have two JSON writers in QEMU? And why do they have
> exactly the same name?

qobject/qjson.c could use qjson.c... but then qjson.c probably should be
changed 1) to not use QOM 2) to use GString instead of QString, just
like most other places that use mutable QStrings.

Paolo

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Qemu-devel] [PATCH] QJSON: Use OBJECT_CHECK
  2015-04-29 19:18     ` Paolo Bonzini
@ 2015-05-01 12:04       ` Eduardo Habkost
  0 siblings, 0 replies; 17+ messages in thread
From: Eduardo Habkost @ 2015-05-01 12:04 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Juan Quintela, qemu-devel, Michael Roth, agraf, Luiz Capitulino,
	Andreas Färber

On Wed, Apr 29, 2015 at 09:18:27PM +0200, Paolo Bonzini wrote:
> On 27/04/2015 19:23, Eduardo Habkost wrote:
> > Also, why do we have two JSON writers in QEMU? And why do they have
> > exactly the same name?
> 
> qobject/qjson.c could use qjson.c... but then qjson.c probably should be
> changed 1) to not use QOM 2) to use GString instead of QString, just
> like most other places that use mutable QStrings.

3) to support a larger subset of JSON. It doesn't even escape string
   contents.

-- 
Eduardo

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Qemu-devel] [PATCH] QJSON: Use OBJECT_CHECK
  2015-04-29 12:55       ` Eduardo Habkost
  2015-04-29 13:00         ` Luiz Capitulino
@ 2015-05-01 16:19         ` Michael Roth
  2015-05-01 16:23           ` Michael Roth
  1 sibling, 1 reply; 17+ messages in thread
From: Michael Roth @ 2015-05-01 16:19 UTC (permalink / raw)
  To: Eduardo Habkost, Luiz Capitulino
  Cc: agraf, qemu-devel, Andreas Färber, Juan Quintela

Quoting Eduardo Habkost (2015-04-29 07:55:48)
> On Wed, Apr 29, 2015 at 08:38:02AM -0400, Luiz Capitulino wrote:
> > On Mon, 27 Apr 2015 14:23:20 -0300
> > Eduardo Habkost <ehabkost@redhat.com> wrote:
> > 
> > > On Sat, Apr 25, 2015 at 07:05:55PM +0200, Andreas Färber wrote:
> > > > Am 25.04.2015 um 17:28 schrieb Eduardo Habkost:
> > > > > The QJSON code used casts to (QJSON*) directly, instead of OBJECT_CHECK.
> > > > > There were even some functions using object_dynamic_cast() calls
> > > > > followed by assert(), which is exactly what OBJECT_CHECK does (by
> > > > > calling object_dynamic_cast_assert()).
> > > > 
> > > > Suggest s/OBJECT_CHECK/OBJECT_CHECK()/g everywhere for clarity.
> > 
> > Everywhere? You mean, in other places? In this case someone has to
> > post a different patch.
> 
> Just in the commit message.
> 
> > 
> > > I assume it can be fixed during commit by whoever is going to queue it.
> > > 
> > > > 
> > > > > 
> > > > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > > > > ---
> > > > >  qjson.c | 10 +++++-----
> > > > >  1 file changed, 5 insertions(+), 5 deletions(-)
> > > > 
> > > > Reviewed-by: Andreas Färber <afaerber@suse.de>
> > > > 
> > > > Wasn't aware QJSON is using QOM - assuming this will go through some
> > > > QAPI/QMP tree.
> > > 
> > > The only user of qjson.c right now is migration code. Should it go through
> > > the migration tree?
> > 
> > It could be, but I can take it if nobody does.
> 
> Thanks!
> 
> > 
> > > Also, why do we have two JSON writers in QEMU? And why do they have
> > > exactly the same name?
> > 
> > Not sure I got it, which writers?
> 
> qjson.c and qobject/qjson.c:to_json().

I'm guessing it's to avoid the need to build up a QObject throughout
the migration code, as opposed to just serializing metadata/vmstate
fields directly to string.

Does make me wonder though why we don't just use visit_type_{int,etc}()
interfaces to build up the QObject through a QMPOutputVisitor, then feed
the resulting QObject through the existing qobject/qjson.c code.

> 
> -- 
> Eduardo
> 

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Qemu-devel] [PATCH] QJSON: Use OBJECT_CHECK
  2015-05-01 16:19         ` Michael Roth
@ 2015-05-01 16:23           ` Michael Roth
  2015-05-02 14:44             ` Alexander Graf
  0 siblings, 1 reply; 17+ messages in thread
From: Michael Roth @ 2015-05-01 16:23 UTC (permalink / raw)
  To: Eduardo Habkost, Luiz Capitulino
  Cc: agraf, qemu-devel, Andreas Färber, Juan Quintela

Quoting Michael Roth (2015-05-01 11:19:05)
> Quoting Eduardo Habkost (2015-04-29 07:55:48)
> > On Wed, Apr 29, 2015 at 08:38:02AM -0400, Luiz Capitulino wrote:
> > > On Mon, 27 Apr 2015 14:23:20 -0300
> > > Eduardo Habkost <ehabkost@redhat.com> wrote:
> > > 
> > > > On Sat, Apr 25, 2015 at 07:05:55PM +0200, Andreas Färber wrote:
> > > > > Am 25.04.2015 um 17:28 schrieb Eduardo Habkost:
> > > > > > The QJSON code used casts to (QJSON*) directly, instead of OBJECT_CHECK.
> > > > > > There were even some functions using object_dynamic_cast() calls
> > > > > > followed by assert(), which is exactly what OBJECT_CHECK does (by
> > > > > > calling object_dynamic_cast_assert()).
> > > > > 
> > > > > Suggest s/OBJECT_CHECK/OBJECT_CHECK()/g everywhere for clarity.
> > > 
> > > Everywhere? You mean, in other places? In this case someone has to
> > > post a different patch.
> > 
> > Just in the commit message.
> > 
> > > 
> > > > I assume it can be fixed during commit by whoever is going to queue it.
> > > > 
> > > > > 
> > > > > > 
> > > > > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > > > > > ---
> > > > > >  qjson.c | 10 +++++-----
> > > > > >  1 file changed, 5 insertions(+), 5 deletions(-)
> > > > > 
> > > > > Reviewed-by: Andreas Färber <afaerber@suse.de>
> > > > > 
> > > > > Wasn't aware QJSON is using QOM - assuming this will go through some
> > > > > QAPI/QMP tree.
> > > > 
> > > > The only user of qjson.c right now is migration code. Should it go through
> > > > the migration tree?
> > > 
> > > It could be, but I can take it if nobody does.
> > 
> > Thanks!
> > 
> > > 
> > > > Also, why do we have two JSON writers in QEMU? And why do they have
> > > > exactly the same name?
> > > 
> > > Not sure I got it, which writers?
> > 
> > qjson.c and qobject/qjson.c:to_json().
> 
> I'm guessing it's to avoid the need to build up a QObject throughout
> the migration code, as opposed to just serializing metadata/vmstate
> fields directly to string.
> 
> Does make me wonder though why we don't just use visit_type_{int,etc}()
> interfaces to build up the QObject through a QMPOutputVisitor, then feed
> the resulting QObject through the existing qobject/qjson.c code.

I guess that would affect downtime. Don't imagine it would by much
though. A JSONOutputVisitor that simply wraps JSONMessageParser
and avoids the QObject intermediate might be another option.

> 
> > 
> > -- 
> > Eduardo
> > 

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Qemu-devel] [PATCH] QJSON: Use OBJECT_CHECK
  2015-04-25 15:28 [Qemu-devel] [PATCH] QJSON: Use OBJECT_CHECK Eduardo Habkost
  2015-04-25 17:05 ` Andreas Färber
@ 2015-05-01 17:16 ` Luiz Capitulino
  1 sibling, 0 replies; 17+ messages in thread
From: Luiz Capitulino @ 2015-05-01 17:16 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: Juan Quintela, qemu-devel, Andreas Färber, agraf

On Sat, 25 Apr 2015 12:28:06 -0300
Eduardo Habkost <ehabkost@redhat.com> wrote:

> The QJSON code used casts to (QJSON*) directly, instead of OBJECT_CHECK.
> There were even some functions using object_dynamic_cast() calls
> followed by assert(), which is exactly what OBJECT_CHECK does (by
> calling object_dynamic_cast_assert()).
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>

Applied to the qmp branch, thanks.

> ---
>  qjson.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/qjson.c b/qjson.c
> index 0cda269..e478802 100644
> --- a/qjson.c
> +++ b/qjson.c
> @@ -24,6 +24,8 @@ struct QJSON {
>      bool omit_comma;
>  };
>  
> +#define QJSON(obj) OBJECT_CHECK(QJSON, (obj), TYPE_QJSON)
> +
>  static void json_emit_element(QJSON *json, const char *name)
>  {
>      /* Check whether we need to print a , before an element */
> @@ -87,7 +89,7 @@ const char *qjson_get_str(QJSON *json)
>  
>  QJSON *qjson_new(void)
>  {
> -    QJSON *json = (QJSON *)object_new(TYPE_QJSON);
> +    QJSON *json = QJSON(object_new(TYPE_QJSON));
>      return json;
>  }
>  
> @@ -98,8 +100,7 @@ void qjson_finish(QJSON *json)
>  
>  static void qjson_initfn(Object *obj)
>  {
> -    QJSON *json = (QJSON *)object_dynamic_cast(obj, TYPE_QJSON);
> -    assert(json);
> +    QJSON *json = QJSON(obj);
>  
>      json->str = qstring_from_str("{ ");
>      json->omit_comma = true;
> @@ -107,9 +108,8 @@ static void qjson_initfn(Object *obj)
>  
>  static void qjson_finalizefn(Object *obj)
>  {
> -    QJSON *json = (QJSON *)object_dynamic_cast(obj, TYPE_QJSON);
> +    QJSON *json = QJSON(obj);
>  
> -    assert(json);
>      qobject_decref(QOBJECT(json->str));
>  }
>  

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Qemu-devel] [PATCH] QJSON: Use OBJECT_CHECK
  2015-05-01 16:23           ` Michael Roth
@ 2015-05-02 14:44             ` Alexander Graf
  0 siblings, 0 replies; 17+ messages in thread
From: Alexander Graf @ 2015-05-02 14:44 UTC (permalink / raw)
  To: Michael Roth, Eduardo Habkost, Luiz Capitulino
  Cc: qemu-devel, Andreas Färber, Juan Quintela



On 01.05.15 18:23, Michael Roth wrote:
> Quoting Michael Roth (2015-05-01 11:19:05)
>> Quoting Eduardo Habkost (2015-04-29 07:55:48)
>>> On Wed, Apr 29, 2015 at 08:38:02AM -0400, Luiz Capitulino wrote:
>>>> On Mon, 27 Apr 2015 14:23:20 -0300
>>>> Eduardo Habkost <ehabkost@redhat.com> wrote:
>>>>
>>>>> On Sat, Apr 25, 2015 at 07:05:55PM +0200, Andreas Färber wrote:
>>>>>> Am 25.04.2015 um 17:28 schrieb Eduardo Habkost:
>>>>>>> The QJSON code used casts to (QJSON*) directly, instead of OBJECT_CHECK.
>>>>>>> There were even some functions using object_dynamic_cast() calls
>>>>>>> followed by assert(), which is exactly what OBJECT_CHECK does (by
>>>>>>> calling object_dynamic_cast_assert()).
>>>>>>
>>>>>> Suggest s/OBJECT_CHECK/OBJECT_CHECK()/g everywhere for clarity.
>>>>
>>>> Everywhere? You mean, in other places? In this case someone has to
>>>> post a different patch.
>>>
>>> Just in the commit message.
>>>
>>>>
>>>>> I assume it can be fixed during commit by whoever is going to queue it.
>>>>>
>>>>>>
>>>>>>>
>>>>>>> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
>>>>>>> ---
>>>>>>>  qjson.c | 10 +++++-----
>>>>>>>  1 file changed, 5 insertions(+), 5 deletions(-)
>>>>>>
>>>>>> Reviewed-by: Andreas Färber <afaerber@suse.de>
>>>>>>
>>>>>> Wasn't aware QJSON is using QOM - assuming this will go through some
>>>>>> QAPI/QMP tree.
>>>>>
>>>>> The only user of qjson.c right now is migration code. Should it go through
>>>>> the migration tree?
>>>>
>>>> It could be, but I can take it if nobody does.
>>>
>>> Thanks!
>>>
>>>>
>>>>> Also, why do we have two JSON writers in QEMU? And why do they have
>>>>> exactly the same name?
>>>>
>>>> Not sure I got it, which writers?
>>>
>>> qjson.c and qobject/qjson.c:to_json().
>>
>> I'm guessing it's to avoid the need to build up a QObject throughout
>> the migration code, as opposed to just serializing metadata/vmstate
>> fields directly to string.
>>
>> Does make me wonder though why we don't just use visit_type_{int,etc}()
>> interfaces to build up the QObject through a QMPOutputVisitor, then feed
>> the resulting QObject through the existing qobject/qjson.c code.
> 
> I guess that would affect downtime. Don't imagine it would by much
> though. A JSONOutputVisitor that simply wraps JSONMessageParser
> and avoids the QObject intermediate might be another option.

Well, there were a number of reasons why I didn't want to use the
QObject json writer. The biggest one is complexity. We're really trying
to do something incredibly trivial, namely writing json string data
continuously. Allocating all that memory (potentially running oom)
didn't seem incredibly appealing to me.


Alex

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Qemu-devel] [PATCH] QJSON: Use OBJECT_CHECK
  2015-04-27 17:23   ` Eduardo Habkost
  2015-04-29 12:38     ` Luiz Capitulino
  2015-04-29 19:18     ` Paolo Bonzini
@ 2015-05-05 12:43     ` Juan Quintela
  2015-05-05 12:53       ` Luiz Capitulino
  2 siblings, 1 reply; 17+ messages in thread
From: Juan Quintela @ 2015-05-05 12:43 UTC (permalink / raw)
  To: Eduardo Habkost
  Cc: Michael Roth, agraf, Luiz Capitulino, Andreas Färber, qemu-devel

Eduardo Habkost <ehabkost@redhat.com> wrote:
> On Sat, Apr 25, 2015 at 07:05:55PM +0200, Andreas Färber wrote:
>> Am 25.04.2015 um 17:28 schrieb Eduardo Habkost:
>> > The QJSON code used casts to (QJSON*) directly, instead of OBJECT_CHECK.
>> > There were even some functions using object_dynamic_cast() calls
>> > followed by assert(), which is exactly what OBJECT_CHECK does (by
>> > calling object_dynamic_cast_assert()).
>> 
>> Suggest s/OBJECT_CHECK/OBJECT_CHECK()/g everywhere for clarity.
>
> I assume it can be fixed during commit by whoever is going to queue it.
>
>> 
>> > 
>> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
>> > ---
>> >  qjson.c | 10 +++++-----
>> >  1 file changed, 5 insertions(+), 5 deletions(-)
>> 
>> Reviewed-by: Andreas Färber <afaerber@suse.de>
>> 
>> Wasn't aware QJSON is using QOM - assuming this will go through some
>> QAPI/QMP tree.
>
> The only user of qjson.c right now is migration code. Should it go through
> the migration tree?


I will take it, but I trust your reviews-by O:-)

>
> Also, why do we have two JSON writers in QEMU? And why do they have
> exactly the same name?

Alex?  I guess alex have this implementation when he did the code long
ago?

Later, Juan.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Qemu-devel] [PATCH] QJSON: Use OBJECT_CHECK
  2015-05-05 12:43     ` Juan Quintela
@ 2015-05-05 12:53       ` Luiz Capitulino
  2015-05-05 13:32         ` Juan Quintela
  0 siblings, 1 reply; 17+ messages in thread
From: Luiz Capitulino @ 2015-05-05 12:53 UTC (permalink / raw)
  To: Juan Quintela
  Cc: qemu-devel, agraf, Michael Roth, Eduardo Habkost, Andreas Färber

On Tue, 05 May 2015 14:43:19 +0200
Juan Quintela <quintela@redhat.com> wrote:

> Eduardo Habkost <ehabkost@redhat.com> wrote:
> > On Sat, Apr 25, 2015 at 07:05:55PM +0200, Andreas Färber wrote:
> >> Am 25.04.2015 um 17:28 schrieb Eduardo Habkost:
> >> > The QJSON code used casts to (QJSON*) directly, instead of OBJECT_CHECK.
> >> > There were even some functions using object_dynamic_cast() calls
> >> > followed by assert(), which is exactly what OBJECT_CHECK does (by
> >> > calling object_dynamic_cast_assert()).
> >> 
> >> Suggest s/OBJECT_CHECK/OBJECT_CHECK()/g everywhere for clarity.
> >
> > I assume it can be fixed during commit by whoever is going to queue it.
> >
> >> 
> >> > 
> >> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> >> > ---
> >> >  qjson.c | 10 +++++-----
> >> >  1 file changed, 5 insertions(+), 5 deletions(-)
> >> 
> >> Reviewed-by: Andreas Färber <afaerber@suse.de>
> >> 
> >> Wasn't aware QJSON is using QOM - assuming this will go through some
> >> QAPI/QMP tree.
> >
> > The only user of qjson.c right now is migration code. Should it go through
> > the migration tree?
> 
> 
> I will take it, but I trust your reviews-by O:-)

I've already applied this one to the QMP tree.

> 
> >
> > Also, why do we have two JSON writers in QEMU? And why do they have
> > exactly the same name?
> 
> Alex?  I guess alex have this implementation when he did the code long
> ago?
> 
> Later, Juan.
> 

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Qemu-devel] [PATCH] QJSON: Use OBJECT_CHECK
  2015-05-05 12:53       ` Luiz Capitulino
@ 2015-05-05 13:32         ` Juan Quintela
  0 siblings, 0 replies; 17+ messages in thread
From: Juan Quintela @ 2015-05-05 13:32 UTC (permalink / raw)
  To: Luiz Capitulino
  Cc: qemu-devel, agraf, Michael Roth, Eduardo Habkost, Andreas Färber

Luiz Capitulino <lcapitulino@redhat.com> wrote:
> On Tue, 05 May 2015 14:43:19 +0200
> Juan Quintela <quintela@redhat.com> wrote:
>
>> Eduardo Habkost <ehabkost@redhat.com> wrote:
>> > On Sat, Apr 25, 2015 at 07:05:55PM +0200, Andreas Färber wrote:
>> >> Am 25.04.2015 um 17:28 schrieb Eduardo Habkost:
>> >> > The QJSON code used casts to (QJSON*) directly, instead of OBJECT_CHECK.
>> >> > There were even some functions using object_dynamic_cast() calls
>> >> > followed by assert(), which is exactly what OBJECT_CHECK does (by
>> >> > calling object_dynamic_cast_assert()).
>> >> 
>> >> Suggest s/OBJECT_CHECK/OBJECT_CHECK()/g everywhere for clarity.
>> >
>> > I assume it can be fixed during commit by whoever is going to queue it.
>> >
>> >> 
>> >> > 
>> >> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
>> >> > ---
>> >> >  qjson.c | 10 +++++-----
>> >> >  1 file changed, 5 insertions(+), 5 deletions(-)
>> >> 
>> >> Reviewed-by: Andreas Färber <afaerber@suse.de>
>> >> 
>> >> Wasn't aware QJSON is using QOM - assuming this will go through some
>> >> QAPI/QMP tree.
>> >
>> > The only user of qjson.c right now is migration code. Should it go through
>> > the migration tree?
>> 
>> 
>> I will take it, but I trust your reviews-by O:-)
>
> I've already applied this one to the QMP tree.

I saw it later on the thread, I was about to say that all for you O:-)


>
>> 
>> >
>> > Also, why do we have two JSON writers in QEMU? And why do they have
>> > exactly the same name?
>> 
>> Alex?  I guess alex have this implementation when he did the code long
>> ago?
>> 
>> Later, Juan.
>> 

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2015-05-05 13:32 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-25 15:28 [Qemu-devel] [PATCH] QJSON: Use OBJECT_CHECK Eduardo Habkost
2015-04-25 17:05 ` Andreas Färber
2015-04-27 17:23   ` Eduardo Habkost
2015-04-29 12:38     ` Luiz Capitulino
2015-04-29 12:46       ` Andreas Färber
2015-04-29 12:54         ` Luiz Capitulino
2015-04-29 12:55       ` Eduardo Habkost
2015-04-29 13:00         ` Luiz Capitulino
2015-05-01 16:19         ` Michael Roth
2015-05-01 16:23           ` Michael Roth
2015-05-02 14:44             ` Alexander Graf
2015-04-29 19:18     ` Paolo Bonzini
2015-05-01 12:04       ` Eduardo Habkost
2015-05-05 12:43     ` Juan Quintela
2015-05-05 12:53       ` Luiz Capitulino
2015-05-05 13:32         ` Juan Quintela
2015-05-01 17:16 ` Luiz Capitulino

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.