qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 20/26] qapi: Make output visitor return qnull() instead of NULL
Date: Mon, 21 Sep 2015 10:03:54 +0200	[thread overview]
Message-ID: <1442822640-29912-21-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1442822640-29912-1-git-send-email-armbru@redhat.com>

Before commit 1d10b44, it crashed.  Since then, it returns NULL, with
a FIXME comment.  The FIXME is valid: code that assumes QObject *
can't be null exists.  I'm not aware of a way to feed this problematic
return value to code that actually chokes on null in the current code,
but the next few commits will create one, failing "make check".

Commit 481b002 solved a very similar problem by introducing a special
null QObject.  Using this special null QObject is clearly the right
way to resolve this FIXME, so do that, and update the test
accordingly.

However, the patch isn't quite right: it messes up the reference
counting.  After about SIZE_MAX visits, the reference counter
overflows, failing the assertion in qnull_destroy_obj().  Because
that's many orders of magnitude more visits of nulls than we expect,
we take this patch despite its flaws, to get the QMP introspection
stuff in without further delay.  We'll want to fix it for real before
the release.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <1442401589-24189-21-git-send-email-armbru@redhat.com>
---
 qapi/qmp-output-visitor.c       | 8 ++++++--
 tests/test-qmp-output-visitor.c | 3 ++-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/qapi/qmp-output-visitor.c b/qapi/qmp-output-visitor.c
index efc19d5..8dce087 100644
--- a/qapi/qmp-output-visitor.c
+++ b/qapi/qmp-output-visitor.c
@@ -66,9 +66,13 @@ static QObject *qmp_output_first(QmpOutputVisitor *qov)
 {
     QStackEntry *e = QTAILQ_LAST(&qov->stack, QStack);
 
-    /* FIXME - find a better way to deal with NULL values */
+    /*
+     * FIXME Wrong, because qmp_output_get_qobject() will increment
+     * the refcnt *again*.  We need to think through how visitors
+     * handle null.
+     */
     if (!e) {
-        return NULL;
+        return qnull();
     }
 
     return e->value;
diff --git a/tests/test-qmp-output-visitor.c b/tests/test-qmp-output-visitor.c
index 338ada0..a48ae72 100644
--- a/tests/test-qmp-output-visitor.c
+++ b/tests/test-qmp-output-visitor.c
@@ -485,7 +485,8 @@ static void test_visitor_out_empty(TestOutputVisitorData *data,
     QObject *arg;
 
     arg = qmp_output_get_qobject(data->qov);
-    g_assert(!arg);
+    g_assert(qobject_type(arg) == QTYPE_QNULL);
+    qobject_decref(arg);
 }
 
 static void init_native_list(UserDefNativeListUnion *cvalue)
-- 
2.4.3

  parent reply	other threads:[~2015-09-21  8:04 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-21  8:03 [Qemu-devel] [PULL 00/26] qapi: QMP introspection Markus Armbruster
2015-09-21  8:03 ` [Qemu-devel] [PULL 01/26] qapi: Rename class QAPISchema to QAPISchemaParser Markus Armbruster
2015-09-21  8:03 ` [Qemu-devel] [PULL 02/26] qapi: New QAPISchema intermediate reperesentation Markus Armbruster
2015-09-21  8:03 ` [Qemu-devel] [PULL 03/26] qapi: QAPISchema code generation helper methods Markus Armbruster
2015-09-21  8:03 ` [Qemu-devel] [PULL 04/26] qapi: New QAPISchemaVisitor Markus Armbruster
2015-09-21  8:03 ` [Qemu-devel] [PULL 05/26] tests/qapi-schema: Convert test harness to QAPISchemaVisitor Markus Armbruster
2015-09-21  8:03 ` [Qemu-devel] [PULL 06/26] qapi-types: Convert to QAPISchemaVisitor, fixing flat unions Markus Armbruster
2015-09-21  8:03 ` [Qemu-devel] [PULL 07/26] qapi-visit: Convert to QAPISchemaVisitor, fixing bugs Markus Armbruster
2015-09-21  8:03 ` [Qemu-devel] [PULL 08/26] qapi-commands: Convert to QAPISchemaVisitor Markus Armbruster
2015-09-21  8:03 ` [Qemu-devel] [PULL 09/26] qapi: De-duplicate enum code generation Markus Armbruster
2015-09-21  8:03 ` [Qemu-devel] [PULL 10/26] qapi-event: Eliminate global variable event_enum_value Markus Armbruster
2015-09-21  8:03 ` [Qemu-devel] [PULL 11/26] qapi-event: Convert to QAPISchemaVisitor, fixing data with base Markus Armbruster
2015-09-21  8:03 ` [Qemu-devel] [PULL 12/26] qapi: Replace dirty is_c_ptr() by method c_null() Markus Armbruster
2015-09-21  8:03 ` [Qemu-devel] [PULL 13/26] qapi: Clean up after recent conversions to QAPISchemaVisitor Markus Armbruster
2015-09-21  8:03 ` [Qemu-devel] [PULL 14/26] qapi-visit: Rearrange code a bit Markus Armbruster
2015-09-21  8:03 ` [Qemu-devel] [PULL 15/26] qapi-commands: Rearrange code Markus Armbruster
2015-09-21  8:03 ` [Qemu-devel] [PULL 16/26] qapi: Rename qmp_marshal_input_FOO() to qmp_marshal_FOO() Markus Armbruster
2015-09-21  8:03 ` [Qemu-devel] [PULL 17/26] qapi: De-duplicate parameter list generation Markus Armbruster
2015-09-21  8:03 ` [Qemu-devel] [PULL 18/26] qapi-commands: De-duplicate output marshaling functions Markus Armbruster
2015-09-21  8:03 ` [Qemu-devel] [PULL 19/26] qapi: Improve built-in type documentation Markus Armbruster
2015-09-21  8:03 ` Markus Armbruster [this message]
2015-09-21  8:03 ` [Qemu-devel] [PULL 21/26] qapi: Introduce a first class 'any' type Markus Armbruster
2015-09-21  8:03 ` [Qemu-devel] [PULL 22/26] qom: Don't use 'gen': false for qom-get, qom-set, object-add Markus Armbruster
2015-09-21  8:03 ` [Qemu-devel] [PULL 23/26] qapi-schema: Fix up misleading specification of netdev_add Markus Armbruster
2015-09-21  8:03 ` [Qemu-devel] [PULL 24/26] qapi: Pseudo-type '**' is now unused, drop it Markus Armbruster
2015-09-21  8:03 ` [Qemu-devel] [PULL 25/26] qapi: New QMP command query-qmp-schema for QMP introspection Markus Armbruster
2015-09-21  8:04 ` [Qemu-devel] [PULL 26/26] qapi-introspect: Hide type names Markus Armbruster
2015-09-21 23:36 ` [Qemu-devel] [PULL 00/26] qapi: QMP introspection Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1442822640-29912-21-git-send-email-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).