From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55912) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zdw59-0002xx-Gz for qemu-devel@nongnu.org; Mon, 21 Sep 2015 04:04:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zdw55-00050y-PL for qemu-devel@nongnu.org; Mon, 21 Sep 2015 04:04:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39236) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zdw55-000506-HL for qemu-devel@nongnu.org; Mon, 21 Sep 2015 04:04:11 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 283E4DAD33 for ; Mon, 21 Sep 2015 08:04:11 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-38.ams2.redhat.com [10.36.116.38]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t8L848HJ012515 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Mon, 21 Sep 2015 04:04:10 -0400 From: Markus Armbruster Date: Mon, 21 Sep 2015 10:03:54 +0200 Message-Id: <1442822640-29912-21-git-send-email-armbru@redhat.com> In-Reply-To: <1442822640-29912-1-git-send-email-armbru@redhat.com> References: <1442822640-29912-1-git-send-email-armbru@redhat.com> Subject: [Qemu-devel] [PULL 20/26] qapi: Make output visitor return qnull() instead of NULL List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 Reviewed-by: Eric Blake Reviewed-by: Daniel P. Berrange 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