Skip to contentSkip to conversation

QJSON: Use OBJECT_CHECK

PATCH Applied Eduardo Habkost 7 participants 17 messages Apr 25, 2015 – May 5, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 QJSON: Use OBJECT_CHECK

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()).

---
 qjson.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
qjson.c +5 -5
index 0cda269..e478802 100644
@@ -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));
 }
 
Signature · 1 line
2.1.0
Reviewed-by on v1 1/1
#1 lore raw

Am 25.04.2015 um 17:28 schrieb Eduardo Habkost:

Quoted 4 lines

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.

Quoted 5 lines
---
 qjson.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

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

Regards,
Andreas

Signature · 3 lines
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)
#2 lore raw
Quoted 7 lines · Andreas Färber

Am 25.04.2015 um 17:28 schrieb Eduardo Habkost:

Quoted 4 lines

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.

Quoted 11 lines
Quoted 6 lines
---
 qjson.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

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?

Signature · 1 line
Eduardo
#3 lore raw
Quoted 8 lines · On Mon, 27 Apr 2015 14:23:20 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 7 lines · Andreas Färber

Am 25.04.2015 um 17:28 schrieb Eduardo Habkost:

Quoted 4 lines

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.

Quoted 9 lines

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

Quoted 7 lines
Quoted 6 lines
---
 qjson.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Quoted 7 lines
Quoted 4 lines

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.

Quoted 2 lines

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?

#4 lore raw

Am 29.04.2015 um 14:38 schrieb Luiz Capitulino:

Quoted 5 lines
Quoted 2 lines · On Mon, 27 Apr 2015 14:23:20 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 1 line · Andreas Färber

Am 25.04.2015 um 17:28 schrieb Eduardo Habkost:

Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

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

Quoted 27 lines

In this case someone has to
post a different patch.

Quoted 9 lines

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

Quoted 7 lines
Quoted 6 lines
---
 qjson.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Quoted 7 lines
Quoted 4 lines

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.

Quoted 2 lines

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?

Signature · 3 lines
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)
#5 lore raw
Quoted 11 lines · On Wed, 29 Apr 2015 14:46:38 +0200 Andreas Färber <[email protected]> wrote:

Am 29.04.2015 um 14:38 schrieb Luiz Capitulino:

Quoted 10 lines
Quoted 7 lines · On Mon, 27 Apr 2015 14:23:20 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 6 lines · Andreas Färber

Am 25.04.2015 um 17:28 schrieb Eduardo Habkost:

Quoted 4 lines

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()).

Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line

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...

Quoted 32 lines

Andreas

Quoted 27 lines

In this case someone has to
post a different patch.

Quoted 9 lines

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

Quoted 7 lines
Quoted 6 lines
---
 qjson.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Quoted 7 lines
Quoted 4 lines

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.

Quoted 2 lines

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?

#6 lore raw
In reply to Luiz Capitulino
Quoted 10 lines · Luiz Capitulino
Quoted 7 lines · On Mon, 27 Apr 2015 14:23:20 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 6 lines · Andreas Färber

Am 25.04.2015 um 17:28 schrieb Eduardo Habkost:

Quoted 4 lines

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()).

Quoted 4 lines
Quoted 1 line
Quoted 1 line

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.

Quoted 12 lines
Quoted 12 lines

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

Quoted 9 lines
Quoted 6 lines
---
 qjson.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

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!

Quoted 5 lines
Quoted 3 lines

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().

Signature · 1 line
Eduardo
#7 lore raw
Quoted 6 lines · On Wed, 29 Apr 2015 09:55:48 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 4 lines
Quoted 2 lines

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.

#8 lore raw
In reply to Eduardo Habkost

Quoting Eduardo Habkost (2015-04-29 07:55:48)

Quoted 41 lines · Luiz Capitulino
Quoted 10 lines
Quoted 7 lines · On Mon, 27 Apr 2015 14:23:20 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 6 lines · Andreas Färber

Am 25.04.2015 um 17:28 schrieb Eduardo Habkost:

Quoted 4 lines

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()).

Quoted 4 lines
Quoted 1 line
Quoted 1 line

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.

Quoted 12 lines
Quoted 12 lines

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

Quoted 9 lines
Quoted 6 lines
---
 qjson.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

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!

Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

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.

Quoted 4 lines
Signature · 2 lines
-- 
Eduardo
#9 lore raw

Quoting Michael Roth (2015-05-01 11:19:05)

Quoted 49 lines

Quoting Eduardo Habkost (2015-04-29 07:55:48)

Quoted 41 lines · Luiz Capitulino
Quoted 10 lines
Quoted 7 lines · On Mon, 27 Apr 2015 14:23:20 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 6 lines · Andreas Färber

Am 25.04.2015 um 17:28 schrieb Eduardo Habkost:

Quoted 4 lines

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()).

Quoted 4 lines
Quoted 1 line
Quoted 1 line

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.

Quoted 12 lines
Quoted 12 lines

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

Quoted 9 lines
Quoted 6 lines
---
 qjson.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

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!

Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

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().

Quoted 7 lines

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.

Quoted 5 lines
Quoted 5 lines
Signature · 2 lines
-- 
Eduardo
#10 lore raw
Quoted 54 lines · Michael Roth

Quoting Michael Roth (2015-05-01 11:19:05)

Quoted 53 lines

Quoting Eduardo Habkost (2015-04-29 07:55:48)

Quoted 41 lines · Luiz Capitulino
Quoted 10 lines
Quoted 7 lines · On Mon, 27 Apr 2015 14:23:20 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 6 lines · Andreas Färber

Am 25.04.2015 um 17:28 schrieb Eduardo Habkost:

Quoted 4 lines

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()).

Quoted 4 lines
Quoted 1 line
Quoted 1 line

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.

Quoted 12 lines
Quoted 12 lines

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

Quoted 9 lines
Quoted 6 lines
---
 qjson.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

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!

Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

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.

Quoted 7 lines
Quoted 3 lines

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

#11 lore raw
In reply to Eduardo Habkost
Quoted 2 lines · Eduardo Habkost

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

#12 lore raw
Quoted 7 lines · Paolo Bonzini
Quoted 2 lines · Eduardo Habkost

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.

Signature · 1 line
Eduardo
#13 lore raw
In reply to Eduardo Habkost
Quoted 18 lines · Eduardo Habkost
Quoted 7 lines · Andreas Färber

Am 25.04.2015 um 17:28 schrieb Eduardo Habkost:

Quoted 4 lines

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.

Quoted 7 lines
Quoted 6 lines
---
 qjson.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Quoted 7 lines
Quoted 4 lines

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:-)

Quoted 3 lines

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.

#14 lore raw
Quoted 21 lines · On Tue, 05 May 2015 14:43:19 +0200 Juan Quintela <[email protected]> wrote:
Quoted 20 lines · Eduardo Habkost
Quoted 7 lines · Andreas Färber

Am 25.04.2015 um 17:28 schrieb Eduardo Habkost:

Quoted 4 lines

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.

Quoted 9 lines
Quoted 6 lines
---
 qjson.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

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.

Quoted 10 lines
Quoted 4 lines

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.

#15 lore raw
Quoted 27 lines · Luiz Capitulino
Quoted 24 lines · On Tue, 05 May 2015 14:43:19 +0200 Juan Quintela <[email protected]> wrote:
Quoted 23 lines · Eduardo Habkost
Quoted 7 lines · Andreas Färber

Am 25.04.2015 um 17:28 schrieb Eduardo Habkost:

Quoted 4 lines

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.

Quoted 11 lines
Quoted 6 lines
---
 qjson.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

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

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

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:-)

Quoted 11 lines
Quoted 11 lines
Quoted 5 lines

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.

#16 lore raw
In reply to Eduardo Habkost
Quoted 6 lines · On Sat, 25 Apr 2015 12:28:06 -0300 Eduardo Habkost <[email protected]> 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()).

Applied to the qmp branch, thanks.

Quoted 47 lines
---
 qjson.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
qjson.c +5 -5
index 0cda269..e478802 100644
@@ -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));
 }