From nobody Thu May 16 14:11:12 2024 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 151948696993753.11372257346386; Sat, 24 Feb 2018 07:42:49 -0800 (PST) Received: from localhost ([::1]:50525 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epbyI-0001ld-J4 for importer@patchew.org; Sat, 24 Feb 2018 10:42:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50451) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epbwS-0000dH-K0 for qemu-devel@nongnu.org; Sat, 24 Feb 2018 10:40:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1epbwR-00053k-NQ for qemu-devel@nongnu.org; Sat, 24 Feb 2018 10:40:52 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44048 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 1epbwM-0004yY-0O; Sat, 24 Feb 2018 10:40:46 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ED7688011454; Sat, 24 Feb 2018 15:40:41 +0000 (UTC) Received: from localhost (ovpn-204-47.brq.redhat.com [10.40.204.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 84D8D215671B; Sat, 24 Feb 2018 15:40:41 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Sat, 24 Feb 2018 16:40:27 +0100 Message-Id: <20180224154033.29559-2-mreitz@redhat.com> In-Reply-To: <20180224154033.29559-1-mreitz@redhat.com> References: <20180224154033.29559-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Sat, 24 Feb 2018 15:40:42 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 1/7] compiler: Add QEMU_BUILD_BUG_MSG() macro 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" _Static_assert() allows us to specify messages, and that may come in handy. Even without _Static_assert(), encouraging developers to put a helpful message next to the QEMU_BUILD_BUG_* may make debugging easier whenever it breaks. Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia Reviewed-by: Eric Blake --- include/qemu/compiler.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h index 2cbe6a4f16..9f762695d1 100644 --- a/include/qemu/compiler.h +++ b/include/qemu/compiler.h @@ -82,15 +82,21 @@ int:(x) ? -1 : 1; \ } =20 +/* QEMU_BUILD_BUG_MSG() emits the message given if _Static_assert is + * supported; otherwise, it will be omitted from the compiler error + * message (but as it remains present in the source code, it can still + * be useful when debugging). */ #if defined(CONFIG_STATIC_ASSERT) -#define QEMU_BUILD_BUG_ON(x) _Static_assert(!(x), "not expecting: " #x) +#define QEMU_BUILD_BUG_MSG(x, msg) _Static_assert(!(x), msg) #elif defined(__COUNTER__) -#define QEMU_BUILD_BUG_ON(x) typedef QEMU_BUILD_BUG_ON_STRUCT(x) \ +#define QEMU_BUILD_BUG_MSG(x, msg) typedef QEMU_BUILD_BUG_ON_STRUCT(x) \ glue(qemu_build_bug_on__, __COUNTER__) __attribute__((unused)) #else -#define QEMU_BUILD_BUG_ON(x) +#define QEMU_BUILD_BUG_MSG(x, msg) #endif =20 +#define QEMU_BUILD_BUG_ON(x) QEMU_BUILD_BUG_MSG(x, "not expecting: " #x) + #define QEMU_BUILD_BUG_ON_ZERO(x) (sizeof(QEMU_BUILD_BUG_ON_STRUCT(x)) - \ sizeof(QEMU_BUILD_BUG_ON_STRUCT(x))) =20 --=20 2.14.3 From nobody Thu May 16 14:11:12 2024 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519487105599566.5392806049684; Sat, 24 Feb 2018 07:45:05 -0800 (PST) Received: from localhost ([::1]:50537 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epc0W-0003hA-IR for importer@patchew.org; Sat, 24 Feb 2018 10:45:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50455) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epbwS-0000dI-NL for qemu-devel@nongnu.org; Sat, 24 Feb 2018 10:40:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1epbwR-00053c-MT for qemu-devel@nongnu.org; Sat, 24 Feb 2018 10:40:52 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44056 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 1epbwL-0004yd-6y; Sat, 24 Feb 2018 10:40:45 -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 392378163C60; Sat, 24 Feb 2018 15:40:44 +0000 (UTC) Received: from localhost (ovpn-204-47.brq.redhat.com [10.40.204.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C249D1C72E; Sat, 24 Feb 2018 15:40:43 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Sat, 24 Feb 2018 16:40:28 +0100 Message-Id: <20180224154033.29559-3-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:44 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Sat, 24 Feb 2018 15:40:44 +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 2/7] qapi: Add 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 is a dynamic casting macro that, given a QObject type, returns an object as that type or NULL if the object is of a different type (or NULL itself). The macro uses lower-case letters because: 1. There does not seem to be a hard rule on whether qemu macros have to be upper-cased, 2. The current situation in qapi/qmp is inconsistent (compare e.g. QINCREF() vs. qdict_put()), 3. qobject_to() will evaluate its @obj parameter only once, thus it is generally not important to the caller whether it is a macro or not, 4. I prefer it aesthetically. Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia Reviewed-by: Eric Blake --- include/qapi/qmp/qobject.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/include/qapi/qmp/qobject.h b/include/qapi/qmp/qobject.h index 38ac68845c..a448576b46 100644 --- a/include/qapi/qmp/qobject.h +++ b/include/qapi/qmp/qobject.h @@ -50,6 +50,22 @@ struct QObject { #define QDECREF(obj) \ qobject_decref(obj ? QOBJECT(obj) : NULL) =20 +/* Required for qobject_to() */ +#define QTYPE_CAST_TO_QNull QTYPE_QNULL +#define QTYPE_CAST_TO_QNum QTYPE_QNUM +#define QTYPE_CAST_TO_QString QTYPE_QSTRING +#define QTYPE_CAST_TO_QDict QTYPE_QDICT +#define QTYPE_CAST_TO_QList QTYPE_QLIST +#define QTYPE_CAST_TO_QBool QTYPE_QBOOL + +QEMU_BUILD_BUG_MSG(QTYPE__MAX !=3D 7, + "The QTYPE_CAST_TO_* list needs to be extended"); + +#define qobject_to(obj, type) \ + container_of(qobject_check_type(obj, glue(QTYPE_CAST_TO_, type)) ?: \ + QOBJECT((type *)NULL), \ + type, base) + /* Initialize an object to default values */ static inline void qobject_init(QObject *obj, QType type) { @@ -102,4 +118,18 @@ static inline QType qobject_type(const QObject *obj) return obj->type; } =20 +/** + * qobject_check_type(): Helper function for the qobject_to() macro. + * Return @obj, but only if @obj is not NULL and @type is equal to + * @obj's type. Return NULL otherwise. + */ +static inline QObject *qobject_check_type(const QObject *obj, QType type) +{ + if (obj && qobject_type(obj) =3D=3D type) { + return (QObject *)obj; + } else { + return NULL; + } +} + #endif /* QOBJECT_H */ --=20 2.14.3 From nobody Thu May 16 14:11:12 2024 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519487382437751.4816972382522; Sat, 24 Feb 2018 07:49:42 -0800 (PST) Received: from localhost ([::1]:50560 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epc4z-0006hp-GV for importer@patchew.org; Sat, 24 Feb 2018 10:49:41 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50587) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epbwg-0000u1-Qa for qemu-devel@nongnu.org; Sat, 24 Feb 2018 10:41:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1epbwa-0005DR-VO for qemu-devel@nongnu.org; Sat, 24 Feb 2018 10:41:06 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44060 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 1epbwN-000515-Be; Sat, 24 Feb 2018 10:40:47 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DE56B814DF58; Sat, 24 Feb 2018 15:40:46 +0000 (UTC) Received: from localhost (ovpn-204-47.brq.redhat.com [10.40.204.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B7F6D2024CA9; Sat, 24 Feb 2018 15:40:45 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Sat, 24 Feb 2018 16:40:29 +0100 Message-Id: <20180224154033.29559-4-mreitz@redhat.com> In-Reply-To: <20180224154033.29559-1-mreitz@redhat.com> References: <20180224154033.29559-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 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:46 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Sat, 24 Feb 2018 15:40:46 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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 3/7] qapi: Replace qobject_to_X(o) by qobject_to(o, X) 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 was generated using the following Coccinelle script: @@ expression Obj; @@ ( - qobject_to_qnum(Obj) + qobject_to(Obj, QNum) | - qobject_to_qstring(Obj) + qobject_to(Obj, QString) | - qobject_to_qdict(Obj) + qobject_to(Obj, QDict) | - qobject_to_qlist(Obj) + qobject_to(Obj, QList) | - qobject_to_qbool(Obj) + qobject_to(Obj, QBool) ) and a bit of manual fix-up for overly long lines and three places in tests/check-qjson.c that Coccinelle did not find. Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia Reviewed-by: Eric Blake --- block.c | 2 +- block/qapi.c | 12 ++++----- block/rbd.c | 8 +++--- blockdev.c | 7 ++--- hw/i386/acpi-build.c | 14 +++++----- monitor.c | 8 +++--- qapi/qmp-dispatch.c | 2 +- qapi/qobject-input-visitor.c | 20 +++++++------- qapi/qobject-output-visitor.c | 4 +-- qga/main.c | 2 +- qmp.c | 2 +- qobject/json-parser.c | 2 +- qobject/qbool.c | 4 +-- qobject/qdict.c | 38 +++++++++++++------------- qobject/qjson.c | 10 +++---- qobject/qlist.c | 6 ++--- qobject/qlit.c | 10 +++---- qobject/qnum.c | 6 ++--- qobject/qstring.c | 6 ++--- qom/object.c | 8 +++--- target/i386/cpu.c | 2 +- target/s390x/cpu_models.c | 2 +- tests/check-qdict.c | 20 +++++++------- tests/check-qjson.c | 41 ++++++++++++++-------------- tests/check-qlist.c | 4 +-- tests/check-qlit.c | 2 +- tests/check-qnum.c | 4 +-- tests/check-qobject.c | 2 +- tests/check-qstring.c | 2 +- tests/device-introspect-test.c | 14 +++++----- tests/libqtest.c | 6 ++--- tests/numa-test.c | 8 +++--- tests/qom-test.c | 4 +-- tests/test-char.c | 2 +- tests/test-keyval.c | 8 +++--- tests/test-qga.c | 19 ++++++------- tests/test-qmp-commands.c | 12 ++++----- tests/test-qmp-event.c | 16 +++++------ tests/test-qobject-input-visitor.c | 10 +++---- tests/test-qobject-output-visitor.c | 54 ++++++++++++++++++---------------= ---- tests/test-x86-cpuid-compat.c | 17 ++++++------ util/keyval.c | 4 +-- util/qemu-config.c | 2 +- util/qemu-option.c | 6 ++--- 44 files changed, 218 insertions(+), 214 deletions(-) diff --git a/block.c b/block.c index 814e5a02da..cb69fd7ae4 100644 --- a/block.c +++ b/block.c @@ -1457,7 +1457,7 @@ static QDict *parse_json_filename(const char *filenam= e, Error **errp) return NULL; } =20 - options =3D qobject_to_qdict(options_obj); + options =3D qobject_to(options_obj, QDict); if (!options) { qobject_decref(options_obj); error_setg(errp, "Invalid JSON object given"); diff --git a/block/qapi.c b/block/qapi.c index 1fdeb1ef2f..0a3d4261df 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -647,29 +647,29 @@ static void dump_qobject(fprintf_function func_fprint= f, void *f, { switch (qobject_type(obj)) { case QTYPE_QNUM: { - QNum *value =3D qobject_to_qnum(obj); + QNum *value =3D qobject_to(obj, QNum); char *tmp =3D qnum_to_string(value); func_fprintf(f, "%s", tmp); g_free(tmp); break; } case QTYPE_QSTRING: { - QString *value =3D qobject_to_qstring(obj); + QString *value =3D qobject_to(obj, QString); func_fprintf(f, "%s", qstring_get_str(value)); break; } case QTYPE_QDICT: { - QDict *value =3D qobject_to_qdict(obj); + QDict *value =3D qobject_to(obj, QDict); dump_qdict(func_fprintf, f, comp_indent, value); break; } case QTYPE_QLIST: { - QList *value =3D qobject_to_qlist(obj); + QList *value =3D qobject_to(obj, QList); dump_qlist(func_fprintf, f, comp_indent, value); break; } case QTYPE_QBOOL: { - QBool *value =3D qobject_to_qbool(obj); + QBool *value =3D qobject_to(obj, QBool); func_fprintf(f, "%s", qbool_get_bool(value) ? "true" : "false"= ); break; } @@ -730,7 +730,7 @@ void bdrv_image_info_specific_dump(fprintf_function fun= c_fprintf, void *f, =20 visit_type_ImageInfoSpecific(v, NULL, &info_spec, &error_abort); visit_complete(v, &obj); - data =3D qdict_get(qobject_to_qdict(obj), "data"); + data =3D qdict_get(qobject_to(obj, QDict), "data"); dump_qobject(func_fprintf, f, 1, data); qobject_decref(obj); visit_free(v); diff --git a/block/rbd.c b/block/rbd.c index 8474b0ba11..178c3b5732 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -256,14 +256,14 @@ static int qemu_rbd_set_keypairs(rados_t cluster, con= st char *keypairs_json, if (!keypairs_json) { return ret; } - keypairs =3D qobject_to_qlist(qobject_from_json(keypairs_json, - &error_abort)); + keypairs =3D qobject_to(qobject_from_json(keypairs_json, &error_abort), + QList); remaining =3D qlist_size(keypairs) / 2; assert(remaining); =20 while (remaining--) { - name =3D qobject_to_qstring(qlist_pop(keypairs)); - value =3D qobject_to_qstring(qlist_pop(keypairs)); + name =3D qobject_to(qlist_pop(keypairs), QString); + value =3D qobject_to(qlist_pop(keypairs), QString); assert(name && value); key =3D qstring_get_str(name); =20 diff --git a/blockdev.c b/blockdev.c index 3fb1ca803c..edc699ae15 100644 --- a/blockdev.c +++ b/blockdev.c @@ -333,7 +333,8 @@ static bool parse_stats_intervals(BlockAcctStats *stats= , QList *intervals, =20 case QTYPE_QSTRING: { unsigned long long length; - const char *str =3D qstring_get_str(qobject_to_qstring(entry->= value)); + const char *str =3D + qstring_get_str(qobject_to(entry->value, QString)); if (parse_uint_full(str, &length, 10) =3D=3D 0 && length > 0 && length <=3D UINT_MAX) { block_acct_add_interval(stats, (unsigned) length); @@ -345,7 +346,7 @@ static bool parse_stats_intervals(BlockAcctStats *stats= , QList *intervals, } =20 case QTYPE_QNUM: { - int64_t length =3D qnum_get_int(qobject_to_qnum(entry->value)); + int64_t length =3D qnum_get_int(qobject_to(entry->value, QNum)= ); =20 if (length > 0 && length <=3D UINT_MAX) { block_acct_add_interval(stats, (unsigned) length); @@ -3981,7 +3982,7 @@ void qmp_blockdev_add(BlockdevOptions *options, Error= **errp) } =20 visit_complete(v, &obj); - qdict =3D qobject_to_qdict(obj); + qdict =3D qobject_to(obj, QDict); =20 qdict_flatten(qdict); =20 diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index deb440f286..78f04e37d9 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -154,21 +154,21 @@ static void acpi_get_pm_info(AcpiPmInfo *pm) /* Fill in optional s3/s4 related properties */ o =3D object_property_get_qobject(obj, ACPI_PM_PROP_S3_DISABLED, NULL); if (o) { - pm->s3_disabled =3D qnum_get_uint(qobject_to_qnum(o)); + pm->s3_disabled =3D qnum_get_uint(qobject_to(o, QNum)); } else { pm->s3_disabled =3D false; } qobject_decref(o); o =3D object_property_get_qobject(obj, ACPI_PM_PROP_S4_DISABLED, NULL); if (o) { - pm->s4_disabled =3D qnum_get_uint(qobject_to_qnum(o)); + pm->s4_disabled =3D qnum_get_uint(qobject_to(o, QNum)); } else { pm->s4_disabled =3D false; } qobject_decref(o); o =3D object_property_get_qobject(obj, ACPI_PM_PROP_S4_VAL, NULL); if (o) { - pm->s4_val =3D qnum_get_uint(qobject_to_qnum(o)); + pm->s4_val =3D qnum_get_uint(qobject_to(o, QNum)); } else { pm->s4_val =3D false; } @@ -514,7 +514,7 @@ static void build_append_pci_bus_devices(Aml *parent_sc= ope, PCIBus *bus, =20 bsel =3D object_property_get_qobject(OBJECT(bus), ACPI_PCIHP_PROP_BSEL= , NULL); if (bsel) { - uint64_t bsel_val =3D qnum_get_uint(qobject_to_qnum(bsel)); + uint64_t bsel_val =3D qnum_get_uint(qobject_to(bsel, QNum)); =20 aml_append(parent_scope, aml_name_decl("BSEL", aml_int(bsel_val))); notify_method =3D aml_method("DVNT", 2, AML_NOTSERIALIZED); @@ -624,7 +624,7 @@ static void build_append_pci_bus_devices(Aml *parent_sc= ope, PCIBus *bus, =20 /* If bus supports hotplug select it and notify about local events */ if (bsel) { - uint64_t bsel_val =3D qnum_get_uint(qobject_to_qnum(bsel)); + uint64_t bsel_val =3D qnum_get_uint(qobject_to(bsel, QNum)); =20 aml_append(method, aml_store(aml_int(bsel_val), aml_name("BNUM"))); aml_append(method, @@ -2638,12 +2638,12 @@ static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg) if (!o) { return false; } - mcfg->mcfg_base =3D qnum_get_uint(qobject_to_qnum(o)); + mcfg->mcfg_base =3D qnum_get_uint(qobject_to(o, QNum)); qobject_decref(o); =20 o =3D object_property_get_qobject(pci_host, PCIE_HOST_MCFG_SIZE, NULL); assert(o); - mcfg->mcfg_size =3D qnum_get_uint(qobject_to_qnum(o)); + mcfg->mcfg_size =3D qnum_get_uint(qobject_to(o, QNum)); qobject_decref(o); return true; } diff --git a/monitor.c b/monitor.c index 373bb8d1c3..5341dba950 100644 --- a/monitor.c +++ b/monitor.c @@ -447,7 +447,7 @@ monitor_qapi_event_queue(QAPIEvent event, QDict *qdict,= Error **errp) /* Unthrottled event */ monitor_qapi_event_emit(event, qdict); } else { - QDict *data =3D qobject_to_qdict(qdict_get(qdict, "data")); + QDict *data =3D qobject_to(qdict_get(qdict, "data"), QDict); MonitorQAPIEventState key =3D { .event =3D event, .data =3D data }; =20 evstate =3D g_hash_table_lookup(monitor_qapi_event_state, &key); @@ -3828,7 +3828,7 @@ static void handle_qmp_command(JSONMessageParser *par= ser, GQueue *tokens) goto err_out; } =20 - qdict =3D qobject_to_qdict(req); + qdict =3D qobject_to(req, QDict); if (qdict) { id =3D qdict_get(qdict, "id"); qobject_incref(id); @@ -3844,7 +3844,7 @@ static void handle_qmp_command(JSONMessageParser *par= ser, GQueue *tokens) rsp =3D qmp_dispatch(cur_mon->qmp.commands, req); =20 if (mon->qmp.commands =3D=3D &qmp_cap_negotiation_commands) { - qdict =3D qdict_get_qdict(qobject_to_qdict(rsp), "error"); + qdict =3D qdict_get_qdict(qobject_to(rsp, QDict), "error"); if (qdict && !g_strcmp0(qdict_get_try_str(qdict, "class"), QapiErrorClass_str(ERROR_CLASS_COMMAND_NOT_FOUND))) { @@ -3865,7 +3865,7 @@ err_out: =20 if (rsp) { if (id) { - qdict_put_obj(qobject_to_qdict(rsp), "id", id); + qdict_put_obj(qobject_to(rsp, QDict), "id", id); id =3D NULL; } =20 diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index e31ac4be1f..5480b1f135 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -26,7 +26,7 @@ static QDict *qmp_dispatch_check_obj(const QObject *reque= st, Error **errp) bool has_exec_key =3D false; QDict *dict =3D NULL; =20 - dict =3D qobject_to_qdict(request); + dict =3D qobject_to(request, QDict); if (!dict) { error_setg(errp, "QMP input must be a JSON object"); return NULL; diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c index 023317b05f..f0c7f3e370 100644 --- a/qapi/qobject-input-visitor.c +++ b/qapi/qobject-input-visitor.c @@ -137,7 +137,7 @@ static QObject *qobject_input_try_get_object(QObjectInp= utVisitor *qiv, =20 if (qobject_type(qobj) =3D=3D QTYPE_QDICT) { assert(name); - ret =3D qdict_get(qobject_to_qdict(qobj), name); + ret =3D qdict_get(qobject_to(qobj, QDict), name); if (tos->h && consume && ret) { bool removed =3D g_hash_table_remove(tos->h, name); assert(removed); @@ -185,7 +185,7 @@ static const char *qobject_input_get_keyval(QObjectInpu= tVisitor *qiv, return NULL; } =20 - qstr =3D qobject_to_qstring(qobj); + qstr =3D qobject_to(qobj, QString); if (!qstr) { switch (qobject_type(qobj)) { case QTYPE_QDICT: @@ -224,11 +224,11 @@ static const QListEntry *qobject_input_push(QObjectIn= putVisitor *qiv, =20 if (qobject_type(obj) =3D=3D QTYPE_QDICT) { h =3D g_hash_table_new(g_str_hash, g_str_equal); - qdict_iter(qobject_to_qdict(obj), qdict_add_key, h); + qdict_iter(qobject_to(obj, QDict), qdict_add_key, h); tos->h =3D h; } else { assert(qobject_type(obj) =3D=3D QTYPE_QLIST); - tos->entry =3D qlist_first(qobject_to_qlist(obj)); + tos->entry =3D qlist_first(qobject_to(obj, QList)); tos->index =3D -1; } =20 @@ -395,7 +395,7 @@ static void qobject_input_type_int64(Visitor *v, const = char *name, int64_t *obj, if (!qobj) { return; } - qnum =3D qobject_to_qnum(qobj); + qnum =3D qobject_to(qobj, QNum); if (!qnum || !qnum_get_try_int(qnum, obj)) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, full_name(qiv, name), "integer"); @@ -430,7 +430,7 @@ static void qobject_input_type_uint64(Visitor *v, const= char *name, if (!qobj) { return; } - qnum =3D qobject_to_qnum(qobj); + qnum =3D qobject_to(qobj, QNum); if (!qnum) { goto err; } @@ -477,7 +477,7 @@ static void qobject_input_type_bool(Visitor *v, const c= har *name, bool *obj, if (!qobj) { return; } - qbool =3D qobject_to_qbool(qobj); + qbool =3D qobject_to(qobj, QBool); if (!qbool) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, full_name(qiv, name), "boolean"); @@ -518,7 +518,7 @@ static void qobject_input_type_str(Visitor *v, const ch= ar *name, char **obj, if (!qobj) { return; } - qstr =3D qobject_to_qstring(qobj); + qstr =3D qobject_to(qobj, QString); if (!qstr) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, full_name(qiv, name), "string"); @@ -547,7 +547,7 @@ static void qobject_input_type_number(Visitor *v, const= char *name, double *obj, if (!qobj) { return; } - qnum =3D qobject_to_qnum(qobj); + qnum =3D qobject_to(qobj, QNum); if (!qnum) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, full_name(qiv, name), "number"); @@ -734,7 +734,7 @@ Visitor *qobject_input_visitor_new_str(const char *str, } return NULL; } - args =3D qobject_to_qdict(obj); + args =3D qobject_to(obj, QDict); assert(args); v =3D qobject_input_visitor_new(QOBJECT(args)); } else { diff --git a/qapi/qobject-output-visitor.c b/qapi/qobject-output-visitor.c index 7c3b42cfe2..190b4ac710 100644 --- a/qapi/qobject-output-visitor.c +++ b/qapi/qobject-output-visitor.c @@ -92,11 +92,11 @@ static void qobject_output_add_obj(QObjectOutputVisitor= *qov, const char *name, switch (qobject_type(cur)) { case QTYPE_QDICT: assert(name); - qdict_put_obj(qobject_to_qdict(cur), name, value); + qdict_put_obj(qobject_to(cur, QDict), name, value); break; case QTYPE_QLIST: assert(!name); - qlist_append_obj(qobject_to_qlist(cur), value); + qlist_append_obj(qobject_to(cur, QList), value); break; default: g_assert_not_reached(); diff --git a/qga/main.c b/qga/main.c index cb434d8c46..12b0fac1a5 100644 --- a/qga/main.c +++ b/qga/main.c @@ -607,7 +607,7 @@ static void process_event(JSONMessageParser *parser, GQ= ueue *tokens) g_assert(s && parser); =20 g_debug("process_event: called"); - qdict =3D qobject_to_qdict(json_parser_parse_err(tokens, NULL, &err)); + qdict =3D qobject_to(json_parser_parse_err(tokens, NULL, &err), QDict); if (err || !qdict) { QDECREF(qdict); qdict =3D qdict_new(); diff --git a/qmp.c b/qmp.c index 793f6f3323..f9daa6f670 100644 --- a/qmp.c +++ b/qmp.c @@ -654,7 +654,7 @@ void qmp_object_add(const char *type, const char *id, Object *obj; =20 if (props) { - pdict =3D qobject_to_qdict(props); + pdict =3D qobject_to(props, QDict); if (!pdict) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict"); return; diff --git a/qobject/json-parser.c b/qobject/json-parser.c index b724562415..9192c7f054 100644 --- a/qobject/json-parser.c +++ b/qobject/json-parser.c @@ -308,7 +308,7 @@ static int parse_pair(JSONParserContext *ctxt, QDict *d= ict, va_list *ap) goto out; } =20 - qdict_put_obj(dict, qstring_get_str(qobject_to_qstring(key)), value); + qdict_put_obj(dict, qstring_get_str(qobject_to(key, QString)), value); =20 qobject_decref(key); =20 diff --git a/qobject/qbool.c b/qobject/qbool.c index e5a7a53879..14d57c03fd 100644 --- a/qobject/qbool.c +++ b/qobject/qbool.c @@ -55,7 +55,7 @@ QBool *qobject_to_qbool(const QObject *obj) */ bool qbool_is_equal(const QObject *x, const QObject *y) { - return qobject_to_qbool(x)->value =3D=3D qobject_to_qbool(y)->value; + return qobject_to(x, QBool)->value =3D=3D qobject_to(y, QBool)->value; } =20 /** @@ -65,5 +65,5 @@ bool qbool_is_equal(const QObject *x, const QObject *y) void qbool_destroy_obj(QObject *obj) { assert(obj !=3D NULL); - g_free(qobject_to_qbool(obj)); + g_free(qobject_to(obj, QBool)); } diff --git a/qobject/qdict.c b/qobject/qdict.c index 23df84f9cd..b85c37cd1d 100644 --- a/qobject/qdict.c +++ b/qobject/qdict.c @@ -206,7 +206,7 @@ size_t qdict_size(const QDict *qdict) */ double qdict_get_double(const QDict *qdict, const char *key) { - return qnum_get_double(qobject_to_qnum(qdict_get(qdict, key))); + return qnum_get_double(qobject_to(qdict_get(qdict, key), QNum)); } =20 /** @@ -219,7 +219,7 @@ double qdict_get_double(const QDict *qdict, const char = *key) */ int64_t qdict_get_int(const QDict *qdict, const char *key) { - return qnum_get_int(qobject_to_qnum(qdict_get(qdict, key))); + return qnum_get_int(qobject_to(qdict_get(qdict, key), QNum)); } =20 /** @@ -232,7 +232,7 @@ int64_t qdict_get_int(const QDict *qdict, const char *k= ey) */ bool qdict_get_bool(const QDict *qdict, const char *key) { - return qbool_get_bool(qobject_to_qbool(qdict_get(qdict, key))); + return qbool_get_bool(qobject_to(qdict_get(qdict, key), QBool)); } =20 /** @@ -240,7 +240,7 @@ bool qdict_get_bool(const QDict *qdict, const char *key) */ QList *qdict_get_qlist(const QDict *qdict, const char *key) { - return qobject_to_qlist(qdict_get(qdict, key)); + return qobject_to(qdict_get(qdict, key), QList); } =20 /** @@ -248,7 +248,7 @@ QList *qdict_get_qlist(const QDict *qdict, const char *= key) */ QDict *qdict_get_qdict(const QDict *qdict, const char *key) { - return qobject_to_qdict(qdict_get(qdict, key)); + return qobject_to(qdict_get(qdict, key), QDict); } =20 /** @@ -262,7 +262,7 @@ QDict *qdict_get_qdict(const QDict *qdict, const char *= key) */ const char *qdict_get_str(const QDict *qdict, const char *key) { - return qstring_get_str(qobject_to_qstring(qdict_get(qdict, key))); + return qstring_get_str(qobject_to(qdict_get(qdict, key), QString)); } =20 /** @@ -275,7 +275,7 @@ const char *qdict_get_str(const QDict *qdict, const cha= r *key) int64_t qdict_get_try_int(const QDict *qdict, const char *key, int64_t def_value) { - QNum *qnum =3D qobject_to_qnum(qdict_get(qdict, key)); + QNum *qnum =3D qobject_to(qdict_get(qdict, key), QNum); int64_t val; =20 if (!qnum || !qnum_get_try_int(qnum, &val)) { @@ -294,7 +294,7 @@ int64_t qdict_get_try_int(const QDict *qdict, const cha= r *key, */ bool qdict_get_try_bool(const QDict *qdict, const char *key, bool def_valu= e) { - QBool *qbool =3D qobject_to_qbool(qdict_get(qdict, key)); + QBool *qbool =3D qobject_to(qdict_get(qdict, key), QBool); =20 return qbool ? qbool_get_bool(qbool) : def_value; } @@ -309,7 +309,7 @@ bool qdict_get_try_bool(const QDict *qdict, const char = *key, bool def_value) */ const char *qdict_get_try_str(const QDict *qdict, const char *key) { - QString *qstr =3D qobject_to_qstring(qdict_get(qdict, key)); + QString *qstr =3D qobject_to(qdict_get(qdict, key), QString); =20 return qstr ? qstring_get_str(qstr) : NULL; } @@ -432,8 +432,8 @@ void qdict_del(QDict *qdict, const char *key) */ bool qdict_is_equal(const QObject *x, const QObject *y) { - const QDict *dict_x =3D qobject_to_qdict(x); - const QDict *dict_y =3D qobject_to_qdict(y); + const QDict *dict_x =3D qobject_to(x, QDict); + const QDict *dict_y =3D qobject_to(y, QDict); const QDictEntry *e; =20 if (qdict_size(dict_x) !=3D qdict_size(dict_y)) { @@ -461,7 +461,7 @@ void qdict_destroy_obj(QObject *obj) QDict *qdict; =20 assert(obj !=3D NULL); - qdict =3D qobject_to_qdict(obj); + qdict =3D qobject_to(obj, QDict); =20 for (i =3D 0; i < QDICT_BUCKET_MAX; i++) { QDictEntry *entry =3D QLIST_FIRST(&qdict->table[i]); @@ -532,9 +532,9 @@ static void qdict_flatten_qlist(QList *qlist, QDict *ta= rget, const char *prefix) new_key =3D g_strdup_printf("%s.%i", prefix, i); =20 if (qobject_type(value) =3D=3D QTYPE_QDICT) { - qdict_flatten_qdict(qobject_to_qdict(value), target, new_key); + qdict_flatten_qdict(qobject_to(value, QDict), target, new_key); } else if (qobject_type(value) =3D=3D QTYPE_QLIST) { - qdict_flatten_qlist(qobject_to_qlist(value), target, new_key); + qdict_flatten_qlist(qobject_to(value, QList), target, new_key); } else { /* All other types are moved to the target unchanged. */ qobject_incref(value); @@ -568,11 +568,11 @@ static void qdict_flatten_qdict(QDict *qdict, QDict *= target, const char *prefix) if (qobject_type(value) =3D=3D QTYPE_QDICT) { /* Entries of QDicts are processed recursively, the QDict obje= ct * itself disappears. */ - qdict_flatten_qdict(qobject_to_qdict(value), target, + qdict_flatten_qdict(qobject_to(value, QDict), target, new_key ? new_key : entry->key); delete =3D true; } else if (qobject_type(value) =3D=3D QTYPE_QLIST) { - qdict_flatten_qlist(qobject_to_qlist(value), target, + qdict_flatten_qlist(qobject_to(value, QList), target, new_key ? new_key : entry->key); delete =3D true; } else if (prefix) { @@ -904,7 +904,7 @@ QObject *qdict_crumple(const QDict *src, Error **errp) qdict_put_obj(two_level, prefix, child); } qobject_incref(ent->value); - qdict_put_obj(qobject_to_qdict(child), suffix, ent->value); + qdict_put_obj(qobject_to(child, QDict), suffix, ent->value); } else { if (child) { error_setg(errp, "Key %s prefix is already set as a dict", @@ -926,7 +926,7 @@ QObject *qdict_crumple(const QDict *src, Error **errp) ent =3D qdict_next(two_level, ent)) { =20 if (qobject_type(ent->value) =3D=3D QTYPE_QDICT) { - child =3D qdict_crumple(qobject_to_qdict(ent->value), errp); + child =3D qdict_crumple(qobject_to(ent->value, QDict), errp); if (!child) { goto error; } @@ -961,7 +961,7 @@ QObject *qdict_crumple(const QDict *src, Error **errp) } =20 qobject_incref(child); - qlist_append_obj(qobject_to_qlist(dst), child); + qlist_append_obj(qobject_to(dst, QList), child); } QDECREF(multi_level); multi_level =3D NULL; diff --git a/qobject/qjson.c b/qobject/qjson.c index e1ce75651c..945a9a4b82 100644 --- a/qobject/qjson.c +++ b/qobject/qjson.c @@ -137,14 +137,14 @@ static void to_json(const QObject *obj, QString *str,= int pretty, int indent) qstring_append(str, "null"); break; case QTYPE_QNUM: { - QNum *val =3D qobject_to_qnum(obj); + QNum *val =3D qobject_to(obj, QNum); char *buffer =3D qnum_to_string(val); qstring_append(str, buffer); g_free(buffer); break; } case QTYPE_QSTRING: { - QString *val =3D qobject_to_qstring(obj); + QString *val =3D qobject_to(obj, QString); const char *ptr; int cp; char buf[16]; @@ -201,7 +201,7 @@ static void to_json(const QObject *obj, QString *str, i= nt pretty, int indent) } case QTYPE_QDICT: { ToJsonIterState s; - QDict *val =3D qobject_to_qdict(obj); + QDict *val =3D qobject_to(obj, QDict); =20 s.count =3D 0; s.str =3D str; @@ -220,7 +220,7 @@ static void to_json(const QObject *obj, QString *str, i= nt pretty, int indent) } case QTYPE_QLIST: { ToJsonIterState s; - QList *val =3D qobject_to_qlist(obj); + QList *val =3D qobject_to(obj, QList); =20 s.count =3D 0; s.str =3D str; @@ -238,7 +238,7 @@ static void to_json(const QObject *obj, QString *str, i= nt pretty, int indent) break; } case QTYPE_QBOOL: { - QBool *val =3D qobject_to_qbool(obj); + QBool *val =3D qobject_to(obj, QBool); =20 if (qbool_get_bool(val)) { qstring_append(str, "true"); diff --git a/qobject/qlist.c b/qobject/qlist.c index 613a95c12b..9deb66fd5c 100644 --- a/qobject/qlist.c +++ b/qobject/qlist.c @@ -173,8 +173,8 @@ QList *qobject_to_qlist(const QObject *obj) */ bool qlist_is_equal(const QObject *x, const QObject *y) { - const QList *list_x =3D qobject_to_qlist(x); - const QList *list_y =3D qobject_to_qlist(y); + const QList *list_x =3D qobject_to(x, QList); + const QList *list_y =3D qobject_to(y, QList); const QListEntry *entry_x, *entry_y; =20 entry_x =3D qlist_first(list_x); @@ -203,7 +203,7 @@ void qlist_destroy_obj(QObject *obj) QListEntry *entry, *next_entry; =20 assert(obj !=3D NULL); - qlist =3D qobject_to_qlist(obj); + qlist =3D qobject_to(obj, QList); =20 QTAILQ_FOREACH_SAFE(entry, &qlist->head, next, next_entry) { QTAILQ_REMOVE(&qlist->head, entry, next); diff --git a/qobject/qlit.c b/qobject/qlit.c index 948e0b860c..8d36387747 100644 --- a/qobject/qlit.c +++ b/qobject/qlit.c @@ -68,16 +68,16 @@ bool qlit_equal_qobject(const QLitObject *lhs, const QO= bject *rhs) =20 switch (lhs->type) { case QTYPE_QBOOL: - return lhs->value.qbool =3D=3D qbool_get_bool(qobject_to_qbool(rhs= )); + return lhs->value.qbool =3D=3D qbool_get_bool(qobject_to(rhs, QBoo= l)); case QTYPE_QNUM: - return lhs->value.qnum =3D=3D qnum_get_int(qobject_to_qnum(rhs)); + return lhs->value.qnum =3D=3D qnum_get_int(qobject_to(rhs, QNum)); case QTYPE_QSTRING: return (strcmp(lhs->value.qstr, - qstring_get_str(qobject_to_qstring(rhs))) =3D=3D 0); + qstring_get_str(qobject_to(rhs, QString))) =3D=3D 0= ); case QTYPE_QDICT: - return qlit_equal_qdict(lhs, qobject_to_qdict(rhs)); + return qlit_equal_qdict(lhs, qobject_to(rhs, QDict)); case QTYPE_QLIST: - return qlit_equal_qlist(lhs, qobject_to_qlist(rhs)); + return qlit_equal_qlist(lhs, qobject_to(rhs, QList)); case QTYPE_QNULL: return true; default: diff --git a/qobject/qnum.c b/qobject/qnum.c index 60c395c1bc..a6444d7c7f 100644 --- a/qobject/qnum.c +++ b/qobject/qnum.c @@ -221,8 +221,8 @@ QNum *qobject_to_qnum(const QObject *obj) */ bool qnum_is_equal(const QObject *x, const QObject *y) { - QNum *num_x =3D qobject_to_qnum(x); - QNum *num_y =3D qobject_to_qnum(y); + QNum *num_x =3D qobject_to(x, QNum); + QNum *num_y =3D qobject_to(y, QNum); =20 switch (num_x->kind) { case QNUM_I64: @@ -271,5 +271,5 @@ bool qnum_is_equal(const QObject *x, const QObject *y) void qnum_destroy_obj(QObject *obj) { assert(obj !=3D NULL); - g_free(qobject_to_qnum(obj)); + g_free(qobject_to(obj, QNum)); } diff --git a/qobject/qstring.c b/qobject/qstring.c index 05b4bbc2d6..741a3c54ad 100644 --- a/qobject/qstring.c +++ b/qobject/qstring.c @@ -132,8 +132,8 @@ const char *qstring_get_str(const QString *qstring) */ bool qstring_is_equal(const QObject *x, const QObject *y) { - return !strcmp(qobject_to_qstring(x)->string, - qobject_to_qstring(y)->string); + return !strcmp(qobject_to(x, QString)->string, + qobject_to(y, QString)->string); } =20 /** @@ -145,7 +145,7 @@ void qstring_destroy_obj(QObject *obj) QString *qs; =20 assert(obj !=3D NULL); - qs =3D qobject_to_qstring(obj); + qs =3D qobject_to(obj, QString); g_free(qs->string); g_free(qs); } diff --git a/qom/object.c b/qom/object.c index 5dcee4683c..60cb5eb790 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1122,7 +1122,7 @@ char *object_property_get_str(Object *obj, const char= *name, if (!ret) { return NULL; } - qstring =3D qobject_to_qstring(ret); + qstring =3D qobject_to(ret, QString); if (!qstring) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name, "string"); retval =3D NULL; @@ -1183,7 +1183,7 @@ bool object_property_get_bool(Object *obj, const char= *name, if (!ret) { return false; } - qbool =3D qobject_to_qbool(ret); + qbool =3D qobject_to(ret, QBool); if (!qbool) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name, "boolean"); retval =3D false; @@ -1215,7 +1215,7 @@ int64_t object_property_get_int(Object *obj, const ch= ar *name, return -1; } =20 - qnum =3D qobject_to_qnum(ret); + qnum =3D qobject_to(ret, QNum); if (!qnum || !qnum_get_try_int(qnum, &retval)) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name, "int"); retval =3D -1; @@ -1244,7 +1244,7 @@ uint64_t object_property_get_uint(Object *obj, const = char *name, if (!ret) { return 0; } - qnum =3D qobject_to_qnum(ret); + qnum =3D qobject_to(ret, QNum); if (!qnum || !qnum_get_try_uint(qnum, &retval)) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name, "uint"); retval =3D 0; diff --git a/target/i386/cpu.c b/target/i386/cpu.c index b5e431e769..e5e3fc3380 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -3101,7 +3101,7 @@ arch_query_cpu_model_expansion(CpuModelExpansionType = type, =20 xc =3D x86_cpu_from_model(model->name, model->has_props ? - qobject_to_qdict(model->props) : + qobject_to(model->props, QDict) : NULL, &err); if (err) { goto out; diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c index 1d5f0da4fe..330b47bb4e 100644 --- a/target/s390x/cpu_models.c +++ b/target/s390x/cpu_models.c @@ -453,7 +453,7 @@ static void cpu_model_from_info(S390CPUModel *model, co= nst CpuModelInfo *info, Object *obj; =20 if (info->props) { - qdict =3D qobject_to_qdict(info->props); + qdict =3D qobject_to(info->props, QDict); if (!qdict) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict"); return; diff --git a/tests/check-qdict.c b/tests/check-qdict.c index ec628f3453..2c24287cd0 100644 --- a/tests/check-qdict.c +++ b/tests/check-qdict.c @@ -51,7 +51,7 @@ static void qdict_put_obj_test(void) =20 g_assert(qdict_size(qdict) =3D=3D 1); ent =3D QLIST_FIRST(&qdict->table[12345 % QDICT_BUCKET_MAX]); - qn =3D qobject_to_qnum(ent->value); + qn =3D qobject_to(ent->value, QNum); g_assert_cmpint(qnum_get_int(qn), =3D=3D, num); =20 QDECREF(qdict); @@ -81,7 +81,7 @@ static void qdict_get_test(void) obj =3D qdict_get(tests_dict, key); g_assert(obj !=3D NULL); =20 - qn =3D qobject_to_qnum(obj); + qn =3D qobject_to(obj, QNum); g_assert_cmpint(qnum_get_int(qn), =3D=3D, value); =20 QDECREF(tests_dict); @@ -216,7 +216,7 @@ static void qdict_del_test(void) static void qobject_to_qdict_test(void) { QDict *tests_dict =3D qdict_new(); - g_assert(qobject_to_qdict(QOBJECT(tests_dict)) =3D=3D tests_dict); + g_assert(qobject_to(QOBJECT(tests_dict), QDict) =3D=3D tests_dict); =20 QDECREF(tests_dict); } @@ -381,9 +381,9 @@ static void qdict_array_split_test(void) =20 qdict_array_split(test_dict, &test_list); =20 - dict1 =3D qobject_to_qdict(qlist_pop(test_list)); - dict2 =3D qobject_to_qdict(qlist_pop(test_list)); - int1 =3D qobject_to_qnum(qlist_pop(test_list)); + dict1 =3D qobject_to(qlist_pop(test_list), QDict); + dict2 =3D qobject_to(qlist_pop(test_list), QDict); + int1 =3D qobject_to(qlist_pop(test_list), QNum); =20 g_assert(dict1); g_assert(dict2); @@ -450,7 +450,7 @@ static void qdict_array_split_test(void) =20 qdict_array_split(test_dict, &test_list); =20 - int1 =3D qobject_to_qnum(qlist_pop(test_list)); + int1 =3D qobject_to(qlist_pop(test_list), QNum); =20 g_assert(int1); g_assert(qlist_empty(test_list)); @@ -607,7 +607,7 @@ static void qdict_crumple_test_recursive(void) qdict_put_str(src, "vnc.acl..name", "acl0"); qdict_put_str(src, "vnc.acl.rule..name", "acl0"); =20 - dst =3D qobject_to_qdict(qdict_crumple(src, &error_abort)); + dst =3D qobject_to(qdict_crumple(src, &error_abort), QDict); g_assert(dst); g_assert_cmpint(qdict_size(dst), =3D=3D, 1); =20 @@ -629,14 +629,14 @@ static void qdict_crumple_test_recursive(void) g_assert(rules); g_assert_cmpint(qlist_size(rules), =3D=3D, 2); =20 - rule =3D qobject_to_qdict(qlist_pop(rules)); + rule =3D qobject_to(qlist_pop(rules), QDict); g_assert(rule); g_assert_cmpint(qdict_size(rule), =3D=3D, 2); g_assert_cmpstr("fred", =3D=3D, qdict_get_str(rule, "match")); g_assert_cmpstr("allow", =3D=3D, qdict_get_str(rule, "policy")); QDECREF(rule); =20 - rule =3D qobject_to_qdict(qlist_pop(rules)); + rule =3D qobject_to(qlist_pop(rules), QDict); g_assert(rule); g_assert_cmpint(qdict_size(rule), =3D=3D, 2); g_assert_cmpstr("bob", =3D=3D, qdict_get_str(rule, "match")); diff --git a/tests/check-qjson.c b/tests/check-qjson.c index a18ea47cb7..bfcbfc480e 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -60,7 +60,7 @@ static void escaped_string(void) QString *str; =20 obj =3D qobject_from_json(test_cases[i].encoded, &error_abort); - str =3D qobject_to_qstring(obj); + str =3D qobject_to(obj, QString); g_assert(str); g_assert_cmpstr(qstring_get_str(str), =3D=3D, test_cases[i].decode= d); =20 @@ -92,7 +92,7 @@ static void simple_string(void) QString *str; =20 obj =3D qobject_from_json(test_cases[i].encoded, &error_abort); - str =3D qobject_to_qstring(obj); + str =3D qobject_to(obj, QString); g_assert(str); g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) =3D= =3D 0); =20 @@ -123,7 +123,7 @@ static void single_quote_string(void) QString *str; =20 obj =3D qobject_from_json(test_cases[i].encoded, &error_abort); - str =3D qobject_to_qstring(obj); + str =3D qobject_to(obj, QString); g_assert(str); g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) =3D= =3D 0); =20 @@ -817,7 +817,7 @@ static void utf8_string(void) =20 obj =3D qobject_from_json(json_in, utf8_out ? &error_abort : NULL); if (utf8_out) { - str =3D qobject_to_qstring(obj); + str =3D qobject_to(obj, QString); g_assert(str); g_assert_cmpstr(qstring_get_str(str), =3D=3D, utf8_out); } else { @@ -843,7 +843,7 @@ static void utf8_string(void) */ if (0 && json_out !=3D json_in) { obj =3D qobject_from_json(json_out, &error_abort); - str =3D qobject_to_qstring(obj); + str =3D qobject_to(obj, QString); g_assert(str); g_assert_cmpstr(qstring_get_str(str), =3D=3D, utf8_out); } @@ -864,8 +864,8 @@ static void vararg_string(void) for (i =3D 0; test_cases[i].decoded; i++) { QString *str; =20 - str =3D qobject_to_qstring(qobject_from_jsonf("%s", - test_cases[i].decoded)= ); + str =3D qobject_to(qobject_from_jsonf("%s", test_cases[i].decoded), + QString); g_assert(str); g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) =3D= =3D 0); =20 @@ -893,8 +893,9 @@ static void simple_number(void) QNum *qnum; int64_t val; =20 - qnum =3D qobject_to_qnum(qobject_from_json(test_cases[i].encoded, - &error_abort)); + qnum =3D qobject_to(qobject_from_json(test_cases[i].encoded, + &error_abort), + QNum); g_assert(qnum); g_assert(qnum_get_try_int(qnum, &val)); g_assert_cmpint(val, =3D=3D, test_cases[i].decoded); @@ -920,7 +921,7 @@ static void large_number(void) uint64_t val; int64_t ival; =20 - qnum =3D qobject_to_qnum(qobject_from_json(maxu64, &error_abort)); + qnum =3D qobject_to(qobject_from_json(maxu64, &error_abort), QNum); g_assert(qnum); g_assert_cmpuint(qnum_get_uint(qnum), =3D=3D, 18446744073709551615U); g_assert(!qnum_get_try_int(qnum, &ival)); @@ -930,7 +931,7 @@ static void large_number(void) QDECREF(str); QDECREF(qnum); =20 - qnum =3D qobject_to_qnum(qobject_from_json(gtu64, &error_abort)); + qnum =3D qobject_to(qobject_from_json(gtu64, &error_abort), QNum); g_assert(qnum); g_assert_cmpfloat(qnum_get_double(qnum), =3D=3D, 18446744073709552e3); g_assert(!qnum_get_try_uint(qnum, &val)); @@ -941,7 +942,7 @@ static void large_number(void) QDECREF(str); QDECREF(qnum); =20 - qnum =3D qobject_to_qnum(qobject_from_json(lti64, &error_abort)); + qnum =3D qobject_to(qobject_from_json(lti64, &error_abort), QNum); g_assert(qnum); g_assert_cmpfloat(qnum_get_double(qnum), =3D=3D, -92233720368547758e2); g_assert(!qnum_get_try_uint(qnum, &val)); @@ -973,7 +974,7 @@ static void float_number(void) QNum *qnum; =20 obj =3D qobject_from_json(test_cases[i].encoded, &error_abort); - qnum =3D qobject_to_qnum(obj); + qnum =3D qobject_to(obj, QNum); g_assert(qnum); g_assert(qnum_get_double(qnum) =3D=3D test_cases[i].decoded); =20 @@ -997,17 +998,17 @@ static void vararg_number(void) double valuef =3D 2.323423423; int64_t val; =20 - qnum =3D qobject_to_qnum(qobject_from_jsonf("%d", value)); + qnum =3D qobject_to(qobject_from_jsonf("%d", value), QNum); g_assert(qnum_get_try_int(qnum, &val)); g_assert_cmpint(val, =3D=3D, value); QDECREF(qnum); =20 - qnum =3D qobject_to_qnum(qobject_from_jsonf("%lld", value_ll)); + qnum =3D qobject_to(qobject_from_jsonf("%lld", value_ll), QNum); g_assert(qnum_get_try_int(qnum, &val)); g_assert_cmpint(val, =3D=3D, value_ll); QDECREF(qnum); =20 - qnum =3D qobject_to_qnum(qobject_from_jsonf("%f", valuef)); + qnum =3D qobject_to(qobject_from_jsonf("%f", valuef), QNum); g_assert(qnum_get_double(qnum) =3D=3D valuef); QDECREF(qnum); } @@ -1020,7 +1021,7 @@ static void keyword_literal(void) QString *str; =20 obj =3D qobject_from_json("true", &error_abort); - qbool =3D qobject_to_qbool(obj); + qbool =3D qobject_to(obj, QBool); g_assert(qbool); g_assert(qbool_get_bool(qbool) =3D=3D true); =20 @@ -1031,7 +1032,7 @@ static void keyword_literal(void) QDECREF(qbool); =20 obj =3D qobject_from_json("false", &error_abort); - qbool =3D qobject_to_qbool(obj); + qbool =3D qobject_to(obj, QBool); g_assert(qbool); g_assert(qbool_get_bool(qbool) =3D=3D false); =20 @@ -1041,13 +1042,13 @@ static void keyword_literal(void) =20 QDECREF(qbool); =20 - qbool =3D qobject_to_qbool(qobject_from_jsonf("%i", false)); + qbool =3D qobject_to(qobject_from_jsonf("%i", false), QBool); g_assert(qbool); g_assert(qbool_get_bool(qbool) =3D=3D false); QDECREF(qbool); =20 /* Test that non-zero values other than 1 get collapsed to true */ - qbool =3D qobject_to_qbool(qobject_from_jsonf("%i", 2)); + qbool =3D qobject_to(qobject_from_jsonf("%i", 2), QBool); g_assert(qbool); g_assert(qbool_get_bool(qbool) =3D=3D true); QDECREF(qbool); diff --git a/tests/check-qlist.c b/tests/check-qlist.c index 259980d523..6e22d64db4 100644 --- a/tests/check-qlist.c +++ b/tests/check-qlist.c @@ -56,7 +56,7 @@ static void qobject_to_qlist_test(void) =20 qlist =3D qlist_new(); =20 - g_assert(qobject_to_qlist(QOBJECT(qlist)) =3D=3D qlist); + g_assert(qobject_to(QOBJECT(qlist), QList) =3D=3D qlist); =20 QDECREF(qlist); } @@ -71,7 +71,7 @@ static void iter_func(QObject *obj, void *opaque) =20 g_assert(opaque =3D=3D NULL); =20 - qi =3D qobject_to_qnum(obj); + qi =3D qobject_to(obj, QNum); g_assert(qi !=3D NULL); =20 g_assert(qnum_get_try_int(qi, &val)); diff --git a/tests/check-qlit.c b/tests/check-qlit.c index 5d0f65b9c7..16d97f9696 100644 --- a/tests/check-qlit.c +++ b/tests/check-qlit.c @@ -57,7 +57,7 @@ static void qlit_equal_qobject_test(void) =20 g_assert(!qlit_equal_qobject(&qlit_foo, qobj)); =20 - qdict_put(qobject_to_qdict(qobj), "bee", qlist_new()); + qdict_put(qobject_to(qobj, QDict), "bee", qlist_new()); g_assert(!qlit_equal_qobject(&qlit, qobj)); =20 qobject_decref(qobj); diff --git a/tests/check-qnum.c b/tests/check-qnum.c index 2b667f7ad7..b1f3216bb0 100644 --- a/tests/check-qnum.c +++ b/tests/check-qnum.c @@ -126,11 +126,11 @@ static void qobject_to_qnum_test(void) QNum *qn; =20 qn =3D qnum_from_int(0); - g_assert(qobject_to_qnum(QOBJECT(qn)) =3D=3D qn); + g_assert(qobject_to(QOBJECT(qn), QNum) =3D=3D qn); QDECREF(qn); =20 qn =3D qnum_from_double(0); - g_assert(qobject_to_qnum(QOBJECT(qn)) =3D=3D qn); + g_assert(qobject_to(QOBJECT(qn), QNum) =3D=3D qn); QDECREF(qn); } =20 diff --git a/tests/check-qobject.c b/tests/check-qobject.c index 7a3670643c..ab80ac2d68 100644 --- a/tests/check-qobject.c +++ b/tests/check-qobject.c @@ -275,7 +275,7 @@ static void qobject_is_equal_dict_test(void) dict_different_null_key, dict_longer, dict_shorter, dict_nested); =20 - dict_crumpled =3D qobject_to_qdict(qdict_crumple(dict_1, &local_err)); + dict_crumpled =3D qobject_to(qdict_crumple(dict_1, &local_err), QDict); g_assert(!local_err); check_equal(dict_crumpled, dict_nested); =20 diff --git a/tests/check-qstring.c b/tests/check-qstring.c index 112ec08967..1118b8db5a 100644 --- a/tests/check-qstring.c +++ b/tests/check-qstring.c @@ -79,7 +79,7 @@ static void qobject_to_qstring_test(void) QString *qstring; =20 qstring =3D qstring_from_str("foo"); - g_assert(qobject_to_qstring(QOBJECT(qstring)) =3D=3D qstring); + g_assert(qobject_to(QOBJECT(qstring), QString) =3D=3D qstring); =20 QDECREF(qstring); } diff --git a/tests/device-introspect-test.c b/tests/device-introspect-test.c index b80058fe98..c4aad2dd06 100644 --- a/tests/device-introspect-test.c +++ b/tests/device-introspect-test.c @@ -52,7 +52,7 @@ static QDict *qom_type_index(QList *types) QListEntry *e; =20 QLIST_FOREACH_ENTRY(types, e) { - QDict *d =3D qobject_to_qdict(qlist_entry_obj(e)); + QDict *d =3D qobject_to(qlist_entry_obj(e), QDict); const char *name =3D qdict_get_str(d, "name"); QINCREF(d); qdict_put(index, name, d); @@ -85,7 +85,7 @@ static QDict *type_list_find(QList *types, const char *na= me) QListEntry *e; =20 QLIST_FOREACH_ENTRY(types, e) { - QDict *d =3D qobject_to_qdict(qlist_entry_obj(e)); + QDict *d =3D qobject_to(qlist_entry_obj(e), QDict); const char *ename =3D qdict_get_str(d, "name"); if (!strcmp(ename, name)) { return d; @@ -151,7 +151,7 @@ static void test_qom_list_parents(const char *parent) index =3D qom_type_index(types); =20 QLIST_FOREACH_ENTRY(types, e) { - QDict *d =3D qobject_to_qdict(qlist_entry_obj(e)); + QDict *d =3D qobject_to(qlist_entry_obj(e), QDict); const char *name =3D qdict_get_str(d, "name"); =20 g_assert(qom_has_parent(index, name, parent)); @@ -173,7 +173,7 @@ static void test_qom_list_fields(void) non_abstract =3D qom_list_types(NULL, false); =20 QLIST_FOREACH_ENTRY(all_types, e) { - QDict *d =3D qobject_to_qdict(qlist_entry_obj(e)); + QDict *d =3D qobject_to(qlist_entry_obj(e), QDict); const char *name =3D qdict_get_str(d, "name"); bool abstract =3D qdict_haskey(d, "abstract") ? qdict_get_bool(d, "abstract") : @@ -216,8 +216,8 @@ static void test_device_intro_concrete(void) types =3D device_type_list(false); =20 QLIST_FOREACH_ENTRY(types, entry) { - type =3D qdict_get_try_str(qobject_to_qdict(qlist_entry_obj(entry)= ), - "name"); + type =3D qdict_get_try_str(qobject_to(qlist_entry_obj(entry), QDic= t), + "name"); g_assert(type); test_one_device(type); } @@ -238,7 +238,7 @@ static void test_abstract_interfaces(void) index =3D qom_type_index(all_types); =20 QLIST_FOREACH_ENTRY(all_types, e) { - QDict *d =3D qobject_to_qdict(qlist_entry_obj(e)); + QDict *d =3D qobject_to(qlist_entry_obj(e), QDict); const char *name =3D qdict_get_str(d, "name"); =20 /* diff --git a/tests/libqtest.c b/tests/libqtest.c index 13c910069b..2829da9aa0 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -430,7 +430,7 @@ static void qmp_response(JSONMessageParser *parser, GQu= eue *tokens) } =20 g_assert(!qmp->response); - qmp->response =3D qobject_to_qdict(obj); + qmp->response =3D qobject_to(obj, QDict); g_assert(qmp->response); } =20 @@ -1008,11 +1008,11 @@ void qtest_cb_for_every_machine(void (*cb)(const ch= ar *machine)) g_assert(list); =20 for (p =3D qlist_first(list); p; p =3D qlist_next(p)) { - minfo =3D qobject_to_qdict(qlist_entry_obj(p)); + minfo =3D qobject_to(qlist_entry_obj(p), QDict); g_assert(minfo); qobj =3D qdict_get(minfo, "name"); g_assert(qobj); - qstr =3D qobject_to_qstring(qobj); + qstr =3D qobject_to(qobj, QString); g_assert(qstr); mname =3D qstring_get_str(qstr); cb(mname); diff --git a/tests/numa-test.c b/tests/numa-test.c index 68aca9cb38..0e0f04abb4 100644 --- a/tests/numa-test.c +++ b/tests/numa-test.c @@ -98,7 +98,7 @@ static void test_query_cpus(const void *data) QDict *cpu, *props; int64_t cpu_idx, node; =20 - cpu =3D qobject_to_qdict(e); + cpu =3D qobject_to(e, QDict); g_assert(qdict_haskey(cpu, "CPU")); g_assert(qdict_haskey(cpu, "props")); =20 @@ -140,7 +140,7 @@ static void pc_numa_cpu(const void *data) QDict *cpu, *props; int64_t socket, core, thread, node; =20 - cpu =3D qobject_to_qdict(e); + cpu =3D qobject_to(e, QDict); g_assert(qdict_haskey(cpu, "props")); props =3D qdict_get_qdict(cpu, "props"); =20 @@ -193,7 +193,7 @@ static void spapr_numa_cpu(const void *data) QDict *cpu, *props; int64_t core, node; =20 - cpu =3D qobject_to_qdict(e); + cpu =3D qobject_to(e, QDict); g_assert(qdict_haskey(cpu, "props")); props =3D qdict_get_qdict(cpu, "props"); =20 @@ -236,7 +236,7 @@ static void aarch64_numa_cpu(const void *data) QDict *cpu, *props; int64_t thread, node; =20 - cpu =3D qobject_to_qdict(e); + cpu =3D qobject_to(e, QDict); g_assert(qdict_haskey(cpu, "props")); props =3D qdict_get_qdict(cpu, "props"); =20 diff --git a/tests/qom-test.c b/tests/qom-test.c index 9dab7ac61e..4c9ee9951a 100644 --- a/tests/qom-test.c +++ b/tests/qom-test.c @@ -62,9 +62,9 @@ static void test_properties(const char *path, bool recurs= e) } =20 g_assert(qdict_haskey(response, "return")); - list =3D qobject_to_qlist(qdict_get(response, "return")); + list =3D qobject_to(qdict_get(response, "return"), QList); QLIST_FOREACH_ENTRY(list, entry) { - tuple =3D qobject_to_qdict(qlist_entry_obj(entry)); + tuple =3D qobject_to(qlist_entry_obj(entry), QDict); bool is_child =3D strstart(qdict_get_str(tuple, "type"), "child<",= NULL); bool is_link =3D strstart(qdict_get_str(tuple, "type"), "link<", N= ULL); =20 diff --git a/tests/test-char.c b/tests/test-char.c index b358620911..050ec0dc9e 100644 --- a/tests/test-char.c +++ b/tests/test-char.c @@ -321,7 +321,7 @@ static void char_socket_test(void) g_assert(!object_property_get_bool(OBJECT(chr), "connected", &error_ab= ort)); =20 addr =3D object_property_get_qobject(OBJECT(chr), "addr", &error_abort= ); - qdict =3D qobject_to_qdict(addr); + qdict =3D qobject_to(addr, QDict); port =3D qdict_get_str(qdict, "port"); tmp =3D g_strdup_printf("tcp:127.0.0.1:%s", port); QDECREF(qdict); diff --git a/tests/test-keyval.c b/tests/test-keyval.c index 94eb4df28d..5d68fd200f 100644 --- a/tests/test-keyval.c +++ b/tests/test-keyval.c @@ -195,7 +195,7 @@ static void check_list012(QList *qlist) =20 g_assert(qlist); for (i =3D 0; i < ARRAY_SIZE(expected); i++) { - qstr =3D qobject_to_qstring(qlist_pop(qlist)); + qstr =3D qobject_to(qlist_pop(qlist), QString); g_assert(qstr); g_assert_cmpstr(qstring_get_str(qstr), =3D=3D, expected[i]); QDECREF(qstr); @@ -654,12 +654,12 @@ static void test_keyval_visit_any(void) QDECREF(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); visit_type_any(v, "a", &any, &error_abort); - qlist =3D qobject_to_qlist(any); + qlist =3D qobject_to(any, QList); g_assert(qlist); - qstr =3D qobject_to_qstring(qlist_pop(qlist)); + qstr =3D qobject_to(qlist_pop(qlist), QString); g_assert_cmpstr(qstring_get_str(qstr), =3D=3D, "null"); QDECREF(qstr); - qstr =3D qobject_to_qstring(qlist_pop(qlist)); + qstr =3D qobject_to(qlist_pop(qlist), QString); g_assert_cmpstr(qstring_get_str(qstr), =3D=3D, "1"); g_assert(qlist_empty(qlist)); QDECREF(qstr); diff --git a/tests/test-qga.c b/tests/test-qga.c index 5c5b661f8a..e8fd748ffe 100644 --- a/tests/test-qga.c +++ b/tests/test-qga.c @@ -297,8 +297,8 @@ static void test_qga_get_vcpus(gconstpointer fix) /* check there is at least a cpu */ list =3D qdict_get_qlist(ret, "return"); entry =3D qlist_first(list); - g_assert(qdict_haskey(qobject_to_qdict(entry->value), "online")); - g_assert(qdict_haskey(qobject_to_qdict(entry->value), "logical-id")); + g_assert(qdict_haskey(qobject_to(entry->value, QDict), "online")); + g_assert(qdict_haskey(qobject_to(entry->value, QDict), "logical-id")); =20 QDECREF(ret); } @@ -318,10 +318,10 @@ static void test_qga_get_fsinfo(gconstpointer fix) list =3D qdict_get_qlist(ret, "return"); entry =3D qlist_first(list); if (entry) { - g_assert(qdict_haskey(qobject_to_qdict(entry->value), "name")); - g_assert(qdict_haskey(qobject_to_qdict(entry->value), "mountpoint"= )); - g_assert(qdict_haskey(qobject_to_qdict(entry->value), "type")); - g_assert(qdict_haskey(qobject_to_qdict(entry->value), "disk")); + g_assert(qdict_haskey(qobject_to(entry->value, QDict), "name")); + g_assert(qdict_haskey(qobject_to(entry->value, QDict), "mountpoint= ")); + g_assert(qdict_haskey(qobject_to(entry->value, QDict), "type")); + g_assert(qdict_haskey(qobject_to(entry->value, QDict), "disk")); } =20 QDECREF(ret); @@ -363,8 +363,9 @@ static void test_qga_get_memory_blocks(gconstpointer fi= x) entry =3D qlist_first(list); /* newer versions of qga may return empty list without error */ if (entry) { - g_assert(qdict_haskey(qobject_to_qdict(entry->value), "phys-in= dex")); - g_assert(qdict_haskey(qobject_to_qdict(entry->value), "online"= )); + g_assert(qdict_haskey(qobject_to(entry->value, QDict), + "phys-index")); + g_assert(qdict_haskey(qobject_to(entry->value, QDict), "online= ")); } } =20 @@ -385,7 +386,7 @@ static void test_qga_network_get_interfaces(gconstpoint= er fix) /* check there is at least an interface */ list =3D qdict_get_qlist(ret, "return"); entry =3D qlist_first(list); - g_assert(qdict_haskey(qobject_to_qdict(entry->value), "name")); + g_assert(qdict_haskey(qobject_to(entry->value, QDict), "name")); =20 QDECREF(ret); } diff --git a/tests/test-qmp-commands.c b/tests/test-qmp-commands.c index 24660d0868..de0d30b1b5 100644 --- a/tests/test-qmp-commands.c +++ b/tests/test-qmp-commands.c @@ -100,7 +100,7 @@ static void test_dispatch_cmd(void) =20 resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req)); assert(resp !=3D NULL); - assert(!qdict_haskey(qobject_to_qdict(resp), "error")); + assert(!qdict_haskey(qobject_to(resp, QDict), "error")); =20 qobject_decref(resp); QDECREF(req); @@ -117,7 +117,7 @@ static void test_dispatch_cmd_failure(void) =20 resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req)); assert(resp !=3D NULL); - assert(qdict_haskey(qobject_to_qdict(resp), "error")); + assert(qdict_haskey(qobject_to(resp, QDict), "error")); =20 qobject_decref(resp); QDECREF(req); @@ -131,7 +131,7 @@ static void test_dispatch_cmd_failure(void) =20 resp =3D qmp_dispatch(&qmp_commands, QOBJECT(req)); assert(resp !=3D NULL); - assert(qdict_haskey(qobject_to_qdict(resp), "error")); + assert(qdict_haskey(qobject_to(resp, QDict), "error")); =20 qobject_decref(resp); QDECREF(req); @@ -145,7 +145,7 @@ static QObject *test_qmp_dispatch(QDict *req) =20 resp_obj =3D qmp_dispatch(&qmp_commands, QOBJECT(req)); assert(resp_obj); - resp =3D qobject_to_qdict(resp_obj); + resp =3D qobject_to(resp_obj, QDict); assert(resp && !qdict_haskey(resp, "error")); ret =3D qdict_get(resp, "return"); assert(ret); @@ -176,7 +176,7 @@ static void test_dispatch_cmd_io(void) qdict_put(req, "arguments", args); qdict_put_str(req, "execute", "user_def_cmd2"); =20 - ret =3D qobject_to_qdict(test_qmp_dispatch(req)); + ret =3D qobject_to(test_qmp_dispatch(req), QDict); =20 assert(!strcmp(qdict_get_str(ret, "string0"), "blah1")); ret_dict =3D qdict_get_qdict(ret, "dict1"); @@ -197,7 +197,7 @@ static void test_dispatch_cmd_io(void) qdict_put(req, "arguments", args3); qdict_put_str(req, "execute", "guest-get-time"); =20 - ret3 =3D qobject_to_qnum(test_qmp_dispatch(req)); + ret3 =3D qobject_to(test_qmp_dispatch(req), QNum); g_assert(qnum_get_try_int(ret3, &val)); g_assert_cmpint(val, =3D=3D, 66); QDECREF(ret3); diff --git a/tests/test-qmp-event.c b/tests/test-qmp-event.c index 8012341343..05d3289186 100644 --- a/tests/test-qmp-event.c +++ b/tests/test-qmp-event.c @@ -61,22 +61,22 @@ void qdict_cmp_do_simple(const char *key, QObject *obj1= , void *opaque) =20 switch (qobject_type(obj1)) { case QTYPE_QBOOL: - d->result =3D (qbool_get_bool(qobject_to_qbool(obj1)) =3D=3D - qbool_get_bool(qobject_to_qbool(obj2))); + d->result =3D (qbool_get_bool(qobject_to(obj1, QBool)) =3D=3D + qbool_get_bool(qobject_to(obj2, QBool))); return; case QTYPE_QNUM: - g_assert(qnum_get_try_int(qobject_to_qnum(obj1), &val1)); - g_assert(qnum_get_try_int(qobject_to_qnum(obj2), &val2)); + g_assert(qnum_get_try_int(qobject_to(obj1, QNum), &val1)); + g_assert(qnum_get_try_int(qobject_to(obj2, QNum), &val2)); d->result =3D val1 =3D=3D val2; return; case QTYPE_QSTRING: - d->result =3D g_strcmp0(qstring_get_str(qobject_to_qstring(obj1)), - qstring_get_str(qobject_to_qstring(obj2))) = =3D=3D 0; + d->result =3D g_strcmp0(qstring_get_str(qobject_to(obj1, QString)), + qstring_get_str(qobject_to(obj2, QString))) = =3D=3D 0; return; case QTYPE_QDICT: - d_new.expect =3D qobject_to_qdict(obj2); + d_new.expect =3D qobject_to(obj2, QDict); d_new.result =3D true; - qdict_iter(qobject_to_qdict(obj1), qdict_cmp_do_simple, &d_new); + qdict_iter(qobject_to(obj1, QDict), qdict_cmp_do_simple, &d_new); d->result =3D d_new.result; return; default: diff --git a/tests/test-qobject-input-visitor.c b/tests/test-qobject-input-= visitor.c index 3900be2610..9e593d525e 100644 --- a/tests/test-qobject-input-visitor.c +++ b/tests/test-qobject-input-visitor.c @@ -479,7 +479,7 @@ static void test_visitor_in_any(TestInputVisitorData *d= ata, =20 v =3D visitor_input_test_init(data, "-42"); visit_type_any(v, NULL, &res, &error_abort); - qnum =3D qobject_to_qnum(res); + qnum =3D qobject_to(res, QNum); g_assert(qnum); g_assert(qnum_get_try_int(qnum, &val)); g_assert_cmpint(val, =3D=3D, -42); @@ -487,22 +487,22 @@ static void test_visitor_in_any(TestInputVisitorData = *data, =20 v =3D visitor_input_test_init(data, "{ 'integer': -42, 'boolean': true= , 'string': 'foo' }"); visit_type_any(v, NULL, &res, &error_abort); - qdict =3D qobject_to_qdict(res); + qdict =3D qobject_to(res, QDict); g_assert(qdict && qdict_size(qdict) =3D=3D 3); qobj =3D qdict_get(qdict, "integer"); g_assert(qobj); - qnum =3D qobject_to_qnum(qobj); + qnum =3D qobject_to(qobj, QNum); g_assert(qnum); g_assert(qnum_get_try_int(qnum, &val)); g_assert_cmpint(val, =3D=3D, -42); qobj =3D qdict_get(qdict, "boolean"); g_assert(qobj); - qbool =3D qobject_to_qbool(qobj); + qbool =3D qobject_to(qobj, QBool); g_assert(qbool); g_assert(qbool_get_bool(qbool) =3D=3D true); qobj =3D qdict_get(qdict, "string"); g_assert(qobj); - qstring =3D qobject_to_qstring(qobj); + qstring =3D qobject_to(qobj, QString); g_assert(qstring); g_assert_cmpstr(qstring_get_str(qstring), =3D=3D, "foo"); qobject_decref(res); diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-outpu= t-visitor.c index 11e8c5aa40..a24bce3a41 100644 --- a/tests/test-qobject-output-visitor.c +++ b/tests/test-qobject-output-visitor.c @@ -66,7 +66,7 @@ static void test_visitor_out_int(TestOutputVisitorData *d= ata, =20 visit_type_int(data->ov, NULL, &value, &error_abort); =20 - qnum =3D qobject_to_qnum(visitor_get(data)); + qnum =3D qobject_to(visitor_get(data), QNum); g_assert(qnum); g_assert(qnum_get_try_int(qnum, &val)); g_assert_cmpint(val, =3D=3D, value); @@ -80,7 +80,7 @@ static void test_visitor_out_bool(TestOutputVisitorData *= data, =20 visit_type_bool(data->ov, NULL, &value, &error_abort); =20 - qbool =3D qobject_to_qbool(visitor_get(data)); + qbool =3D qobject_to(visitor_get(data), QBool); g_assert(qbool); g_assert(qbool_get_bool(qbool) =3D=3D value); } @@ -93,7 +93,7 @@ static void test_visitor_out_number(TestOutputVisitorData= *data, =20 visit_type_number(data->ov, NULL, &value, &error_abort); =20 - qnum =3D qobject_to_qnum(visitor_get(data)); + qnum =3D qobject_to(visitor_get(data), QNum); g_assert(qnum); g_assert(qnum_get_double(qnum) =3D=3D value); } @@ -106,7 +106,7 @@ static void test_visitor_out_string(TestOutputVisitorDa= ta *data, =20 visit_type_str(data->ov, NULL, &string, &error_abort); =20 - qstr =3D qobject_to_qstring(visitor_get(data)); + qstr =3D qobject_to(visitor_get(data), QString); g_assert(qstr); g_assert_cmpstr(qstring_get_str(qstr), =3D=3D, string); } @@ -120,7 +120,7 @@ static void test_visitor_out_no_string(TestOutputVisito= rData *data, /* A null string should return "" */ visit_type_str(data->ov, NULL, &string, &error_abort); =20 - qstr =3D qobject_to_qstring(visitor_get(data)); + qstr =3D qobject_to(visitor_get(data), QString); g_assert(qstr); g_assert_cmpstr(qstring_get_str(qstr), =3D=3D, ""); } @@ -134,7 +134,7 @@ static void test_visitor_out_enum(TestOutputVisitorData= *data, for (i =3D 0; i < ENUM_ONE__MAX; i++) { visit_type_EnumOne(data->ov, "unused", &i, &error_abort); =20 - qstr =3D qobject_to_qstring(visitor_get(data)); + qstr =3D qobject_to(visitor_get(data), QString); g_assert(qstr); g_assert_cmpstr(qstring_get_str(qstr), =3D=3D, EnumOne_str(i)); visitor_reset(data); @@ -167,7 +167,7 @@ static void test_visitor_out_struct(TestOutputVisitorDa= ta *data, =20 visit_type_TestStruct(data->ov, NULL, &p, &error_abort); =20 - qdict =3D qobject_to_qdict(visitor_get(data)); + qdict =3D qobject_to(visitor_get(data), QDict); g_assert(qdict); g_assert_cmpint(qdict_size(qdict), =3D=3D, 3); g_assert_cmpint(qdict_get_int(qdict, "integer"), =3D=3D, 42); @@ -206,7 +206,7 @@ static void test_visitor_out_struct_nested(TestOutputVi= sitorData *data, =20 visit_type_UserDefTwo(data->ov, "unused", &ud2, &error_abort); =20 - qdict =3D qobject_to_qdict(visitor_get(data)); + qdict =3D qobject_to(visitor_get(data), QDict); g_assert(qdict); g_assert_cmpint(qdict_size(qdict), =3D=3D, 2); g_assert_cmpstr(qdict_get_str(qdict, "string0"), =3D=3D, strings[0]); @@ -280,7 +280,7 @@ static void test_visitor_out_list(TestOutputVisitorData= *data, =20 visit_type_TestStructList(data->ov, NULL, &head, &error_abort); =20 - qlist =3D qobject_to_qlist(visitor_get(data)); + qlist =3D qobject_to(visitor_get(data), QList); g_assert(qlist); g_assert(!qlist_empty(qlist)); =20 @@ -289,7 +289,7 @@ static void test_visitor_out_list(TestOutputVisitorData= *data, QLIST_FOREACH_ENTRY(qlist, entry) { QDict *qdict; =20 - qdict =3D qobject_to_qdict(entry->value); + qdict =3D qobject_to(entry->value, QDict); g_assert(qdict); g_assert_cmpint(qdict_size(qdict), =3D=3D, 3); g_assert_cmpint(qdict_get_int(qdict, "integer"), =3D=3D, value_int= + i); @@ -342,7 +342,7 @@ static void test_visitor_out_any(TestOutputVisitorData = *data, =20 qobj =3D QOBJECT(qnum_from_int(-42)); visit_type_any(data->ov, NULL, &qobj, &error_abort); - qnum =3D qobject_to_qnum(visitor_get(data)); + qnum =3D qobject_to(visitor_get(data), QNum); g_assert(qnum); g_assert(qnum_get_try_int(qnum, &val)); g_assert_cmpint(val, =3D=3D, -42); @@ -356,16 +356,16 @@ static void test_visitor_out_any(TestOutputVisitorDat= a *data, qobj =3D QOBJECT(qdict); visit_type_any(data->ov, NULL, &qobj, &error_abort); qobject_decref(qobj); - qdict =3D qobject_to_qdict(visitor_get(data)); + qdict =3D qobject_to(visitor_get(data), QDict); g_assert(qdict); - qnum =3D qobject_to_qnum(qdict_get(qdict, "integer")); + qnum =3D qobject_to(qdict_get(qdict, "integer"), QNum); g_assert(qnum); g_assert(qnum_get_try_int(qnum, &val)); g_assert_cmpint(val, =3D=3D, -42); - qbool =3D qobject_to_qbool(qdict_get(qdict, "boolean")); + qbool =3D qobject_to(qdict_get(qdict, "boolean"), QBool); g_assert(qbool); g_assert(qbool_get_bool(qbool) =3D=3D true); - qstring =3D qobject_to_qstring(qdict_get(qdict, "string")); + qstring =3D qobject_to(qdict_get(qdict, "string"), QString); g_assert(qstring); g_assert_cmpstr(qstring_get_str(qstring), =3D=3D, "foo"); } @@ -382,7 +382,7 @@ static void test_visitor_out_union_flat(TestOutputVisit= orData *data, tmp->u.value1.boolean =3D true; =20 visit_type_UserDefFlatUnion(data->ov, NULL, &tmp, &error_abort); - qdict =3D qobject_to_qdict(visitor_get(data)); + qdict =3D qobject_to(visitor_get(data), QDict); g_assert(qdict); g_assert_cmpstr(qdict_get_str(qdict, "enum1"), =3D=3D, "value1"); g_assert_cmpstr(qdict_get_str(qdict, "string"), =3D=3D, "str"); @@ -406,7 +406,7 @@ static void test_visitor_out_alternate(TestOutputVisito= rData *data, tmp->u.i =3D 42; =20 visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort); - qnum =3D qobject_to_qnum(visitor_get(data)); + qnum =3D qobject_to(visitor_get(data), QNum); g_assert(qnum); g_assert(qnum_get_try_int(qnum, &val)); g_assert_cmpint(val, =3D=3D, 42); @@ -419,7 +419,7 @@ static void test_visitor_out_alternate(TestOutputVisito= rData *data, tmp->u.e =3D ENUM_ONE_VALUE1; =20 visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort); - qstr =3D qobject_to_qstring(visitor_get(data)); + qstr =3D qobject_to(visitor_get(data), QString); g_assert(qstr); g_assert_cmpstr(qstring_get_str(qstr), =3D=3D, "value1"); =20 @@ -444,7 +444,7 @@ static void test_visitor_out_alternate(TestOutputVisito= rData *data, tmp->u.udfu.u.value1.boolean =3D true; =20 visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort); - qdict =3D qobject_to_qdict(visitor_get(data)); + qdict =3D qobject_to(visitor_get(data), QDict); g_assert(qdict); g_assert_cmpint(qdict_size(qdict), =3D=3D, 4); g_assert_cmpint(qdict_get_int(qdict, "integer"), =3D=3D, 1); @@ -466,7 +466,7 @@ static void test_visitor_out_null(TestOutputVisitorData= *data, visit_type_null(data->ov, "a", &null, &error_abort); visit_check_struct(data->ov, &error_abort); visit_end_struct(data->ov, NULL); - qdict =3D qobject_to_qdict(visitor_get(data)); + qdict =3D qobject_to(visitor_get(data), QDict); g_assert(qdict); g_assert_cmpint(qdict_size(qdict), =3D=3D, 1); nil =3D qdict_get(qdict, "a"); @@ -610,10 +610,10 @@ static void check_native_list(QObject *qobj, QList *qlist; int i; =20 - qdict =3D qobject_to_qdict(qobj); + qdict =3D qobject_to(qobj, QDict); g_assert(qdict); g_assert(qdict_haskey(qdict, "data")); - qlist =3D qlist_copy(qobject_to_qlist(qdict_get(qdict, "data"))); + qlist =3D qlist_copy(qobject_to(qdict_get(qdict, "data"), QList)); =20 switch (kind) { case USER_DEF_NATIVE_LIST_UNION_KIND_U8: @@ -627,7 +627,7 @@ static void check_native_list(QObject *qobj, =20 tmp =3D qlist_peek(qlist); g_assert(tmp); - qvalue =3D qobject_to_qnum(tmp); + qvalue =3D qobject_to(tmp, QNum); g_assert(qnum_get_try_uint(qvalue, &val)); g_assert_cmpint(val, =3D=3D, i); qobject_decref(qlist_pop(qlist)); @@ -651,7 +651,7 @@ static void check_native_list(QObject *qobj, =20 tmp =3D qlist_peek(qlist); g_assert(tmp); - qvalue =3D qobject_to_qnum(tmp); + qvalue =3D qobject_to(tmp, QNum); g_assert(qnum_get_try_int(qvalue, &val)); g_assert_cmpint(val, =3D=3D, i); qobject_decref(qlist_pop(qlist)); @@ -663,7 +663,7 @@ static void check_native_list(QObject *qobj, QBool *qvalue; tmp =3D qlist_peek(qlist); g_assert(tmp); - qvalue =3D qobject_to_qbool(tmp); + qvalue =3D qobject_to(tmp, QBool); g_assert_cmpint(qbool_get_bool(qvalue), =3D=3D, i % 3 =3D=3D 0= ); qobject_decref(qlist_pop(qlist)); } @@ -675,7 +675,7 @@ static void check_native_list(QObject *qobj, gchar str[8]; tmp =3D qlist_peek(qlist); g_assert(tmp); - qvalue =3D qobject_to_qstring(tmp); + qvalue =3D qobject_to(tmp, QString); sprintf(str, "%d", i); g_assert_cmpstr(qstring_get_str(qvalue), =3D=3D, str); qobject_decref(qlist_pop(qlist)); @@ -690,7 +690,7 @@ static void check_native_list(QObject *qobj, =20 tmp =3D qlist_peek(qlist); g_assert(tmp); - qvalue =3D qobject_to_qnum(tmp); + qvalue =3D qobject_to(tmp, QNum); g_string_printf(double_expected, "%.6f", (double)i / 3); g_string_printf(double_actual, "%.6f", qnum_get_double(qvalue)= ); g_assert_cmpstr(double_actual->str, =3D=3D, double_expected->s= tr); diff --git a/tests/test-x86-cpuid-compat.c b/tests/test-x86-cpuid-compat.c index 495dd1e7ef..9e166980f6 100644 --- a/tests/test-x86-cpuid-compat.c +++ b/tests/test-x86-cpuid-compat.c @@ -17,7 +17,7 @@ static char *get_cpu0_qom_path(void) g_assert(qdict_haskey(resp, "return")); ret =3D qdict_get_qlist(resp, "return"); =20 - cpu0 =3D qobject_to_qdict(qlist_peek(ret)); + cpu0 =3D qobject_to(qlist_peek(ret), QDict); path =3D g_strdup(qdict_get_str(cpu0, "qom_path")); QDECREF(resp); return path; @@ -38,7 +38,7 @@ static QObject *qom_get(const char *path, const char *pro= p) #ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS static bool qom_get_bool(const char *path, const char *prop) { - QBool *value =3D qobject_to_qbool(qom_get(path, prop)); + QBool *value =3D qobject_to(qom_get(path, prop), QBool); bool b =3D qbool_get_bool(value); =20 QDECREF(value); @@ -61,7 +61,7 @@ static void test_cpuid_prop(const void *data) =20 qtest_start(args->cmdline); path =3D get_cpu0_qom_path(); - value =3D qobject_to_qnum(qom_get(path, args->property)); + value =3D qobject_to(qom_get(path, args->property), QNum); g_assert(qnum_get_try_int(value, &val)); g_assert_cmpint(val, =3D=3D, args->expected_value); qtest_end(); @@ -105,7 +105,7 @@ static uint32_t get_feature_word(QList *features, uint3= 2_t eax, uint32_t ecx, const QListEntry *e; =20 for (e =3D qlist_first(features); e; e =3D qlist_next(e)) { - QDict *w =3D qobject_to_qdict(qlist_entry_obj(e)); + QDict *w =3D qobject_to(qlist_entry_obj(e), QDict); const char *rreg =3D qdict_get_str(w, "cpuid-register"); uint32_t reax =3D qdict_get_int(w, "cpuid-input-eax"); bool has_ecx =3D qdict_haskey(w, "cpuid-input-ecx"); @@ -116,8 +116,9 @@ static uint32_t get_feature_word(QList *features, uint3= 2_t eax, uint32_t ecx, recx =3D qdict_get_int(w, "cpuid-input-ecx"); } if (eax =3D=3D reax && (!has_ecx || ecx =3D=3D recx) && !strcmp(rr= eg, reg)) { - g_assert(qnum_get_try_int(qobject_to_qnum(qdict_get(w, "featur= es")), - &val)); + g_assert(qnum_get_try_int(qobject_to(qdict_get(w, "features"), + QNum), + &val)); return val; } } @@ -133,8 +134,8 @@ static void test_feature_flag(const void *data) =20 qtest_start(args->cmdline); path =3D get_cpu0_qom_path(); - present =3D qobject_to_qlist(qom_get(path, "feature-words")); - filtered =3D qobject_to_qlist(qom_get(path, "filtered-features")); + present =3D qobject_to(qom_get(path, "feature-words"), QList); + filtered =3D qobject_to(qom_get(path, "filtered-features"), QList); value =3D get_feature_word(present, args->in_eax, args->in_ecx, args->= reg); value |=3D get_feature_word(filtered, args->in_eax, args->in_ecx, args= ->reg); qtest_end(); diff --git a/util/keyval.c b/util/keyval.c index 212ae90d00..46b3aa5734 100644 --- a/util/keyval.c +++ b/util/keyval.c @@ -221,7 +221,7 @@ static const char *keyval_parse_one(QDict *qdict, const= char *params, if (!next) { return NULL; } - cur =3D qobject_to_qdict(next); + cur =3D qobject_to(next, QDict); assert(cur); } =20 @@ -314,7 +314,7 @@ static QObject *keyval_listify(QDict *cur, GSList *key_= of_cur, Error **errp) has_member =3D true; } =20 - qdict =3D qobject_to_qdict(ent->value); + qdict =3D qobject_to(ent->value, QDict); if (!qdict) { continue; } diff --git a/util/qemu-config.c b/util/qemu-config.c index 10cae120cc..7e2c6017f7 100644 --- a/util/qemu-config.c +++ b/util/qemu-config.c @@ -528,7 +528,7 @@ static void config_parse_qdict_section(QDict *options, = QemuOptsList *opts, } =20 QLIST_FOREACH_ENTRY(list, list_entry) { - QDict *section =3D qobject_to_qdict(qlist_entry_obj(list_entry= )); + QDict *section =3D qobject_to(qlist_entry_obj(list_entry), QDi= ct); char *opt_name; =20 if (!section) { diff --git a/util/qemu-option.c b/util/qemu-option.c index a401e936da..20b975ca23 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -919,15 +919,15 @@ static void qemu_opts_from_qdict_1(const char *key, Q= Object *obj, void *opaque) =20 switch (qobject_type(obj)) { case QTYPE_QSTRING: - value =3D qstring_get_str(qobject_to_qstring(obj)); + value =3D qstring_get_str(qobject_to(obj, QString)); break; case QTYPE_QNUM: - tmp =3D qnum_to_string(qobject_to_qnum(obj)); + tmp =3D qnum_to_string(qobject_to(obj, QNum)); value =3D tmp; break; case QTYPE_QBOOL: pstrcpy(buf, sizeof(buf), - qbool_get_bool(qobject_to_qbool(obj)) ? "on" : "off"); + qbool_get_bool(qobject_to(obj, QBool)) ? "on" : "off"); value =3D buf; break; default: --=20 2.14.3 From nobody Thu May 16 14:11:12 2024 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519487216937319.1996541789316; Sat, 24 Feb 2018 07:46:56 -0800 (PST) Received: from localhost ([::1]:50552 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epc2K-0005EC-5m for importer@patchew.org; Sat, 24 Feb 2018 10:46:56 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50467) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epbwT-0000dq-9N for qemu-devel@nongnu.org; Sat, 24 Feb 2018 10:40:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1epbwS-00054L-1z for qemu-devel@nongnu.org; Sat, 24 Feb 2018 10:40:53 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39212 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 1epbwP-00051u-EC; Sat, 24 Feb 2018 10:40:49 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F0BDE4022909; Sat, 24 Feb 2018 15:40:48 +0000 (UTC) Received: from localhost (ovpn-204-47.brq.redhat.com [10.40.204.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 94A3D10B0F27; Sat, 24 Feb 2018 15:40:48 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Sat, 24 Feb 2018 16:40:30 +0100 Message-Id: <20180224154033.29559-5-mreitz@redhat.com> In-Reply-To: <20180224154033.29559-1-mreitz@redhat.com> References: <20180224154033.29559-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Sat, 24 Feb 2018 15:40:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Sat, 24 Feb 2018 15:40:49 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 4/7] qapi: Remove qobject_to_X() functions 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" They are no longer needed now. Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia Reviewed-by: Eric Blake --- include/qapi/qmp/qbool.h | 1 - include/qapi/qmp/qdict.h | 1 - include/qapi/qmp/qlist.h | 1 - include/qapi/qmp/qnum.h | 1 - include/qapi/qmp/qstring.h | 1 - qobject/qbool.c | 11 ----------- qobject/qdict.c | 11 ----------- qobject/qlist.c | 11 ----------- qobject/qnum.c | 11 ----------- qobject/qstring.c | 11 ----------- 10 files changed, 60 deletions(-) diff --git a/include/qapi/qmp/qbool.h b/include/qapi/qmp/qbool.h index 629c508d34..b9a44a1bfe 100644 --- a/include/qapi/qmp/qbool.h +++ b/include/qapi/qmp/qbool.h @@ -23,7 +23,6 @@ struct QBool { =20 QBool *qbool_from_bool(bool value); bool qbool_get_bool(const QBool *qb); -QBool *qobject_to_qbool(const QObject *obj); bool qbool_is_equal(const QObject *x, const QObject *y); void qbool_destroy_obj(QObject *obj); =20 diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h index ff6f7842c3..c19b7aa2c4 100644 --- a/include/qapi/qmp/qdict.h +++ b/include/qapi/qmp/qdict.h @@ -39,7 +39,6 @@ void qdict_put_obj(QDict *qdict, const char *key, QObject= *value); void qdict_del(QDict *qdict, const char *key); int qdict_haskey(const QDict *qdict, const char *key); QObject *qdict_get(const QDict *qdict, const char *key); -QDict *qobject_to_qdict(const QObject *obj); bool qdict_is_equal(const QObject *x, const QObject *y); void qdict_iter(const QDict *qdict, void (*iter)(const char *key, QObject *obj, void *opaque), diff --git a/include/qapi/qmp/qlist.h b/include/qapi/qmp/qlist.h index 5fd976a398..5c673acb06 100644 --- a/include/qapi/qmp/qlist.h +++ b/include/qapi/qmp/qlist.h @@ -53,7 +53,6 @@ QObject *qlist_pop(QList *qlist); QObject *qlist_peek(QList *qlist); int qlist_empty(const QList *qlist); size_t qlist_size(const QList *qlist); -QList *qobject_to_qlist(const QObject *obj); bool qlist_is_equal(const QObject *x, const QObject *y); void qlist_destroy_obj(QObject *obj); =20 diff --git a/include/qapi/qmp/qnum.h b/include/qapi/qmp/qnum.h index 15e3971c7f..3e47475b2c 100644 --- a/include/qapi/qmp/qnum.h +++ b/include/qapi/qmp/qnum.h @@ -68,7 +68,6 @@ double qnum_get_double(QNum *qn); =20 char *qnum_to_string(QNum *qn); =20 -QNum *qobject_to_qnum(const QObject *obj); bool qnum_is_equal(const QObject *x, const QObject *y); void qnum_destroy_obj(QObject *obj); =20 diff --git a/include/qapi/qmp/qstring.h b/include/qapi/qmp/qstring.h index 98070ef3d6..b72843fc1b 100644 --- a/include/qapi/qmp/qstring.h +++ b/include/qapi/qmp/qstring.h @@ -30,7 +30,6 @@ const char *qstring_get_str(const QString *qstring); void qstring_append_int(QString *qstring, int64_t value); void qstring_append(QString *qstring, const char *str); void qstring_append_chr(QString *qstring, int c); -QString *qobject_to_qstring(const QObject *obj); bool qstring_is_equal(const QObject *x, const QObject *y); void qstring_destroy_obj(QObject *obj); =20 diff --git a/qobject/qbool.c b/qobject/qbool.c index 14d57c03fd..c45cbc1d3a 100644 --- a/qobject/qbool.c +++ b/qobject/qbool.c @@ -39,17 +39,6 @@ bool qbool_get_bool(const QBool *qb) return qb->value; } =20 -/** - * qobject_to_qbool(): Convert a QObject into a QBool - */ -QBool *qobject_to_qbool(const QObject *obj) -{ - if (!obj || qobject_type(obj) !=3D QTYPE_QBOOL) { - return NULL; - } - return container_of(obj, QBool, base); -} - /** * qbool_is_equal(): Test whether the two QBools are equal */ diff --git a/qobject/qdict.c b/qobject/qdict.c index b85c37cd1d..2562f7a426 100644 --- a/qobject/qdict.c +++ b/qobject/qdict.c @@ -37,17 +37,6 @@ QDict *qdict_new(void) return qdict; } =20 -/** - * qobject_to_qdict(): Convert a QObject into a QDict - */ -QDict *qobject_to_qdict(const QObject *obj) -{ - if (!obj || qobject_type(obj) !=3D QTYPE_QDICT) { - return NULL; - } - return container_of(obj, QDict, base); -} - /** * tdb_hash(): based on the hash agorithm from gdbm, via tdb * (from module-init-tools) diff --git a/qobject/qlist.c b/qobject/qlist.c index 9deb66fd5c..782df470cf 100644 --- a/qobject/qlist.c +++ b/qobject/qlist.c @@ -151,17 +151,6 @@ size_t qlist_size(const QList *qlist) return count; } =20 -/** - * qobject_to_qlist(): Convert a QObject into a QList - */ -QList *qobject_to_qlist(const QObject *obj) -{ - if (!obj || qobject_type(obj) !=3D QTYPE_QLIST) { - return NULL; - } - return container_of(obj, QList, base); -} - /** * qlist_is_equal(): Test whether the two QLists are equal * diff --git a/qobject/qnum.c b/qobject/qnum.c index a6444d7c7f..986bf325a5 100644 --- a/qobject/qnum.c +++ b/qobject/qnum.c @@ -199,17 +199,6 @@ char *qnum_to_string(QNum *qn) return NULL; } =20 -/** - * qobject_to_qnum(): Convert a QObject into a QNum - */ -QNum *qobject_to_qnum(const QObject *obj) -{ - if (!obj || qobject_type(obj) !=3D QTYPE_QNUM) { - return NULL; - } - return container_of(obj, QNum, base); -} - /** * qnum_is_equal(): Test whether the two QNums are equal * diff --git a/qobject/qstring.c b/qobject/qstring.c index 741a3c54ad..dcec5de9f2 100644 --- a/qobject/qstring.c +++ b/qobject/qstring.c @@ -105,17 +105,6 @@ void qstring_append_chr(QString *qstring, int c) qstring->string[qstring->length] =3D 0; } =20 -/** - * qobject_to_qstring(): Convert a QObject to a QString - */ -QString *qobject_to_qstring(const QObject *obj) -{ - if (!obj || qobject_type(obj) !=3D QTYPE_QSTRING) { - return NULL; - } - return container_of(obj, QString, base); -} - /** * qstring_get_str(): Return a pointer to the stored string * --=20 2.14.3 From nobody Thu May 16 14:11:12 2024 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 From nobody Thu May 16 14:11:12 2024 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 151948697970076.57910845244942; Sat, 24 Feb 2018 07:42:59 -0800 (PST) Received: from localhost ([::1]:50526 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epbyS-0001um-Og for importer@patchew.org; Sat, 24 Feb 2018 10:42:56 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50528) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epbwa-0000lC-4f for qemu-devel@nongnu.org; Sat, 24 Feb 2018 10:41:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1epbwZ-0005A9-5P for qemu-devel@nongnu.org; Sat, 24 Feb 2018 10:41:00 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50024 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 1epbwU-000560-Ay; Sat, 24 Feb 2018 10:40:54 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D454840796A2; Sat, 24 Feb 2018 15:40:53 +0000 (UTC) Received: from localhost (ovpn-204-47.brq.redhat.com [10.40.204.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 66E2C215671B; Sat, 24 Feb 2018 15:40:53 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Sat, 24 Feb 2018 16:40:32 +0100 Message-Id: <20180224154033.29559-7-mreitz@redhat.com> In-Reply-To: <20180224154033.29559-1-mreitz@redhat.com> References: <20180224154033.29559-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sat, 24 Feb 2018 15:40:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sat, 24 Feb 2018 15:40:53 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 6/7] block: Handle null backing link 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" Instead of converting all "backing": null instances into "backing": "", handle a null value directly in bdrv_open_inherit(). This enables explicitly null backing links for json:{} filenames. Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia Reviewed-by: Eric Blake --- block.c | 4 +++- blockdev.c | 14 -------------- tests/qemu-iotests/089 | 20 ++++++++++++++++++++ tests/qemu-iotests/089.out | 8 ++++++++ 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/block.c b/block.c index cb69fd7ae4..b86614d8ad 100644 --- a/block.c +++ b/block.c @@ -2600,7 +2600,9 @@ static BlockDriverState *bdrv_open_inherit(const char= *filename, =20 /* See cautionary note on accessing @options above */ backing =3D qdict_get_try_str(options, "backing"); - if (backing && *backing =3D=3D '\0') { + if (qobject_to(qdict_get(options, "backing"), QNull) !=3D NULL || + (backing && *backing =3D=3D '\0')) + { flags |=3D BDRV_O_NO_BACKING; qdict_del(options, "backing"); } diff --git a/blockdev.c b/blockdev.c index edc699ae15..003245c6cb 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3972,7 +3972,6 @@ void qmp_blockdev_add(BlockdevOptions *options, Error= **errp) QObject *obj; Visitor *v =3D qobject_output_visitor_new(&obj); QDict *qdict; - const QDictEntry *ent; Error *local_err =3D NULL; =20 visit_type_BlockdevOptions(v, NULL, &options, &local_err); @@ -3986,19 +3985,6 @@ void qmp_blockdev_add(BlockdevOptions *options, Erro= r **errp) =20 qdict_flatten(qdict); =20 - /* - * Rewrite "backing": null to "backing": "" - * TODO Rewrite "" to null instead, and perhaps not even here - */ - for (ent =3D qdict_first(qdict); ent; ent =3D qdict_next(qdict, ent)) { - char *dot =3D strrchr(ent->key, '.'); - - if (!strcmp(dot ? dot + 1 : ent->key, "backing") - && qobject_type(ent->value) =3D=3D QTYPE_QNULL) { - qdict_put(qdict, ent->key, qstring_new()); - } - } - if (!qdict_get_try_str(qdict, "node-name")) { error_setg(errp, "'node-name' must be specified for the root node"= ); goto fail; diff --git a/tests/qemu-iotests/089 b/tests/qemu-iotests/089 index 0b059aba90..aa1ba4a98e 100755 --- a/tests/qemu-iotests/089 +++ b/tests/qemu-iotests/089 @@ -82,6 +82,26 @@ $QEMU_IO_PROG --cache $CACHEMODE \ $QEMU_IO -c 'read -P 42 0 512' "$TEST_IMG" | _filter_qemu_io =20 =20 +echo +echo "=3D=3D=3D Testing correct handling of 'backing':null =3D=3D=3D" +echo + +_make_test_img -b "$TEST_IMG.base" $IMG_SIZE + +# This should read 42 +$QEMU_IO -c 'read -P 42 0 512' "$TEST_IMG" | _filter_qemu_io + +# This should read 0 +$QEMU_IO -c 'read -P 0 0 512' "json:{\ + 'driver': '$IMGFMT', + 'file': { + 'driver': 'file', + 'filename': '$TEST_IMG' + }, + 'backing': null +}" | _filter_qemu_io + + # Taken from test 071 echo echo "=3D=3D=3D Testing blkdebug =3D=3D=3D" diff --git a/tests/qemu-iotests/089.out b/tests/qemu-iotests/089.out index 0bf5a13ec1..89e3e4340a 100644 --- a/tests/qemu-iotests/089.out +++ b/tests/qemu-iotests/089.out @@ -19,6 +19,14 @@ Pattern verification failed at offset 0, 512 bytes read 512/512 bytes at offset 0 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 +=3D=3D=3D Testing correct handling of 'backing':null =3D=3D=3D + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 backing_file= =3DTEST_DIR/t.IMGFMT.base +read 512/512 bytes at offset 0 +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 512/512 bytes at offset 0 +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + =3D=3D=3D Testing blkdebug =3D=3D=3D =20 Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 --=20 2.14.3 From nobody Thu May 16 14:11:12 2024 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 151948712034844.781789193353234; Sat, 24 Feb 2018 07:45:20 -0800 (PST) Received: from localhost ([::1]:50539 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epc0k-0003qQ-9x for importer@patchew.org; Sat, 24 Feb 2018 10:45:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50548) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epbwb-0000oL-8L 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-0005BZ-6o for qemu-devel@nongnu.org; Sat, 24 Feb 2018 10:41:01 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44072 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 1epbwW-00057Y-PE; Sat, 24 Feb 2018 10:40:56 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4E2AB818535B; Sat, 24 Feb 2018 15:40:56 +0000 (UTC) Received: from localhost (ovpn-204-47.brq.redhat.com [10.40.204.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D691610B0F27; Sat, 24 Feb 2018 15:40:55 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Sat, 24 Feb 2018 16:40:33 +0100 Message-Id: <20180224154033.29559-8-mreitz@redhat.com> In-Reply-To: <20180224154033.29559-1-mreitz@redhat.com> References: <20180224154033.29559-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 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:56 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Sat, 24 Feb 2018 15:40:56 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 7/7] block: Deprecate "backing": "" 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" We have a clear replacement, so let's deprecate it. Signed-off-by: Max Reitz Reviewed-by: Eric Blake Reviewed-by: Alberto Garcia --- qapi/block-core.json | 4 ++-- block.c | 4 ++++ qemu-doc.texi | 7 +++++++ qemu-options.hx | 4 ++-- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 5c5921bfb7..6cf695dfc5 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1090,7 +1090,7 @@ # @overlay: reference to the existing block device that will become # the overlay of @node, as part of creating the snapshot. # It must not have a current backing file (this can be -# achieved by passing "backing": "" to blockdev-add). +# achieved by passing "backing": null to blockdev-add). # # Since: 2.5 ## @@ -1238,7 +1238,7 @@ # "node-name": "node1534", # "file": { "driver": "file", # "filename": "hd1.qcow2" }, -# "backing": "" } } +# "backing": null } } # # <- { "return": {} } # diff --git a/block.c b/block.c index b86614d8ad..797706199d 100644 --- a/block.c +++ b/block.c @@ -2603,6 +2603,10 @@ static BlockDriverState *bdrv_open_inherit(const cha= r *filename, if (qobject_to(qdict_get(options, "backing"), QNull) !=3D NULL || (backing && *backing =3D=3D '\0')) { + if (backing) { + warn_report("Use of \"backing\": \"\" is deprecated; " + "use \"backing\": null instead"); + } flags |=3D BDRV_O_NO_BACKING; qdict_del(options, "backing"); } diff --git a/qemu-doc.texi b/qemu-doc.texi index 8e3556976b..1b537f3e00 100644 --- a/qemu-doc.texi +++ b/qemu-doc.texi @@ -2792,6 +2792,13 @@ support page sizes < 4096 any longer. The ``xlnx-ep108'' machine has been replaced by the ``xlnx-zcu102'' machin= e. The ``xlnx-zcu102'' machine has the same features and capabilites in QEMU. =20 +@section Block device options + +@subsection "backing": "" (since 2.12.0) + +In order to prevent QEMU from automatically opening an image's backing +chain, use ``"backing": null'' instead. + @node License @appendix License =20 diff --git a/qemu-options.hx b/qemu-options.hx index 8ccd5dcaa6..ff84563206 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -743,8 +743,8 @@ Reference to or definition of the data source block dri= ver node =20 @item backing Reference to or definition of the backing file block device (default is ta= ken -from the image file). It is allowed to pass an empty string here in order = to -disable the default backing file. +from the image file). It is allowed to pass @code{null} here in order to d= isable +the default backing file. =20 @item lazy-refcounts Whether to enable the lazy refcounts feature (on/off; default is taken fro= m the --=20 2.14.3