From nobody Mon Feb 9 13:39:00 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519487304795137.7420660402978; Sat, 24 Feb 2018 07:48:24 -0800 (PST) Received: from localhost ([::1]:50557 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epc3e-0005xj-WE for importer@patchew.org; Sat, 24 Feb 2018 10:48:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50550) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epbwb-0000oV-BH for qemu-devel@nongnu.org; Sat, 24 Feb 2018 10:41:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1epbwa-0005Bg-89 for qemu-devel@nongnu.org; Sat, 24 Feb 2018 10:41:01 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44066 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1epbwR-00053S-Tg; Sat, 24 Feb 2018 10:40:51 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 64F5C8185331; Sat, 24 Feb 2018 15:40:51 +0000 (UTC) Received: from localhost (ovpn-204-47.brq.redhat.com [10.40.204.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EB61F1C73B; Sat, 24 Feb 2018 15:40:50 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Sat, 24 Feb 2018 16:40:31 +0100 Message-Id: <20180224154033.29559-6-mreitz@redhat.com> In-Reply-To: <20180224154033.29559-1-mreitz@redhat.com> References: <20180224154033.29559-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Sat, 24 Feb 2018 15:40:51 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Sat, 24 Feb 2018 15:40:51 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 5/7] qapi: Make more of qobject_to() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alberto Garcia , qemu-devel@nongnu.org, Michael Roth , Markus Armbruster , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch reworks some places which use either qobject_type() checks plus qobject_to(), where the latter alone is sufficient, or NULL checks plus qobject_type() checks where we can simply do a qobject_to() !=3D NULL check. Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia Reviewed-by: Eric Blake --- qapi/qobject-input-visitor.c | 4 ++-- qobject/json-parser.c | 13 +++++++------ qobject/qdict.c | 20 +++++++++++--------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c index f0c7f3e370..a1a3f9dcd7 100644 --- a/qapi/qobject-input-visitor.c +++ b/qapi/qobject-input-visitor.c @@ -339,7 +339,7 @@ static GenericList *qobject_input_next_list(Visitor *v,= GenericList *tail, QObjectInputVisitor *qiv =3D to_qiv(v); StackObject *tos =3D QSLIST_FIRST(&qiv->stack); =20 - assert(tos && tos->obj && qobject_type(tos->obj) =3D=3D QTYPE_QLIST); + assert(tos && qobject_to(tos->obj, QList)); =20 if (!tos->entry) { return NULL; @@ -353,7 +353,7 @@ static void qobject_input_check_list(Visitor *v, Error = **errp) QObjectInputVisitor *qiv =3D to_qiv(v); StackObject *tos =3D QSLIST_FIRST(&qiv->stack); =20 - assert(tos && tos->obj && qobject_type(tos->obj) =3D=3D QTYPE_QLIST); + assert(tos && qobject_to(tos->obj, QList)); =20 if (tos->entry) { error_setg(errp, "Only %u list elements expected in %s", diff --git a/qobject/json-parser.c b/qobject/json-parser.c index 9192c7f054..6063d31427 100644 --- a/qobject/json-parser.c +++ b/qobject/json-parser.c @@ -276,7 +276,8 @@ static void parser_context_free(JSONParserContext *ctxt) */ static int parse_pair(JSONParserContext *ctxt, QDict *dict, va_list *ap) { - QObject *key =3D NULL, *value; + QObject *value; + QString *key =3D NULL; JSONToken *peek, *token; =20 peek =3D parser_context_peek_token(ctxt); @@ -285,8 +286,8 @@ static int parse_pair(JSONParserContext *ctxt, QDict *d= ict, va_list *ap) goto out; } =20 - key =3D parse_value(ctxt, ap); - if (!key || qobject_type(key) !=3D QTYPE_QSTRING) { + key =3D qobject_to(parse_value(ctxt, ap), QString); + if (!key) { parse_error(ctxt, peek, "key is not a string in object"); goto out; } @@ -308,14 +309,14 @@ static int parse_pair(JSONParserContext *ctxt, QDict = *dict, va_list *ap) goto out; } =20 - qdict_put_obj(dict, qstring_get_str(qobject_to(key, QString)), value); + qdict_put_obj(dict, qstring_get_str(key), value); =20 - qobject_decref(key); + QDECREF(key); =20 return 0; =20 out: - qobject_decref(key); + QDECREF(key); =20 return -1; } diff --git a/qobject/qdict.c b/qobject/qdict.c index 2562f7a426..ad048cba6e 100644 --- a/qobject/qdict.c +++ b/qobject/qdict.c @@ -882,18 +882,20 @@ QObject *qdict_crumple(const QDict *src, Error **errp) =20 child =3D qdict_get(two_level, prefix); if (suffix) { - if (child) { - if (qobject_type(child) !=3D QTYPE_QDICT) { + QDict *child_dict =3D qobject_to(child, QDict); + if (!child_dict) { + if (child) { error_setg(errp, "Key %s prefix is already set as a sc= alar", prefix); goto error; } - } else { - child =3D QOBJECT(qdict_new()); - qdict_put_obj(two_level, prefix, child); + + child_dict =3D qdict_new(); + qdict_put_obj(two_level, prefix, QOBJECT(child_dict)); } + qobject_incref(ent->value); - qdict_put_obj(qobject_to(child, QDict), suffix, ent->value); + qdict_put_obj(child_dict, suffix, ent->value); } else { if (child) { error_setg(errp, "Key %s prefix is already set as a dict", @@ -913,9 +915,9 @@ QObject *qdict_crumple(const QDict *src, Error **errp) multi_level =3D qdict_new(); for (ent =3D qdict_first(two_level); ent !=3D NULL; ent =3D qdict_next(two_level, ent)) { - - if (qobject_type(ent->value) =3D=3D QTYPE_QDICT) { - child =3D qdict_crumple(qobject_to(ent->value, QDict), errp); + QDict *dict =3D qobject_to(ent->value, QDict); + if (dict) { + child =3D qdict_crumple(dict, errp); if (!child) { goto error; } --=20 2.14.3