From nobody Fri May 3 20:42:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1604957397; cv=none; d=zohomail.com; s=zohoarc; b=G/sHcpQSsluvpizwwVSIniKrMkRWtv5E3bpnM006UfRfBmAS4oiX7RpZeEFDQDQuMVksmnLy4gbLOFn3ePd2jPfDpPHJlaUJ9l4Q2MgcNcs0C8Q35ggB9l6e5wAr45a9yZkr9NvuPT91Ce2uaBGJshV8Q8O9hnbloqFT2NSAzhU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604957397; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mqjSxmtyytIvtr/jbMfZrxqKMEvbF2yA6d1phOfsCeA=; b=mSifjziwL3/V/0pwrh65UIQBan7DJuHHtCZpSG25MTY2omfefrEr9OZ/bahbLfvy3788pLMDfztWFDzpGoi+xZNFbVYN2/NOt0IG2VVcqDID8uR1Y1E55Mke7SUT8zeeLFs2N49x7Sg1+prUKCsHrkeOT7rhJkfgS4H4ZNtYK+4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604957397260333.65478291237343; Mon, 9 Nov 2020 13:29:57 -0800 (PST) Received: from localhost ([::1]:60556 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcEjb-0000H4-2X for importer@patchew.org; Mon, 09 Nov 2020 16:29:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33612) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcEg0-0003tg-QG for qemu-devel@nongnu.org; Mon, 09 Nov 2020 16:26:13 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20231) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kcEfv-0005ao-R7 for qemu-devel@nongnu.org; Mon, 09 Nov 2020 16:26:12 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-359-tWM-M0sqPACrn9m18rMuEA-1; Mon, 09 Nov 2020 16:26:00 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 228BF835B8E for ; Mon, 9 Nov 2020 21:25:59 +0000 (UTC) Received: from localhost (ovpn-114-68.rdu2.redhat.com [10.10.114.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id DEA8D5D9CC; Mon, 9 Nov 2020 21:25:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604957167; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mqjSxmtyytIvtr/jbMfZrxqKMEvbF2yA6d1phOfsCeA=; b=TgsEXeM0sAf3ZTubM71WE3OWTuiu8poZEPIJgSYRmtwZXjGulh8Np3T/y9hh2ZFnvuB2dv 9Ib2WpGlSm9JNU+FKNzEhq31wqvVLJ3uzlkk3XGewgSKULef23FcDnumX26hYgZ44ZFPJy UC9pLkwjd5B24TvnL79PhC4W0Y9CgMY= X-MC-Unique: tWM-M0sqPACrn9m18rMuEA-1 From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH 1/8] qobject: Include API docs in docs/devel/qobject.html Date: Mon, 9 Nov 2020 16:25:49 -0500 Message-Id: <20201109212556.3934583-2-ehabkost@redhat.com> In-Reply-To: <20201109212556.3934583-1-ehabkost@redhat.com> References: <20201109212556.3934583-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ehabkost@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=ehabkost@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/09 00:04:29 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Render existing doc comments at docs/devel/qobject.html. Signed-off-by: Eduardo Habkost Acked-by: Paolo Bonzini --- docs/devel/index.rst | 1 + docs/devel/qobject.rst | 11 +++++++++ include/qapi/qmp/qnum.h | 4 +++- include/qapi/qmp/qobject.h | 48 +++++++++++++++++++++++++------------- qobject/qnum.c | 19 ++++++++++++--- 5 files changed, 63 insertions(+), 20 deletions(-) create mode 100644 docs/devel/qobject.rst diff --git a/docs/devel/index.rst b/docs/devel/index.rst index 77baae5c77..7f8e5e3071 100644 --- a/docs/devel/index.rst +++ b/docs/devel/index.rst @@ -34,3 +34,4 @@ Contents: clocks qom block-coroutine-wrapper + qobject diff --git a/docs/devel/qobject.rst b/docs/devel/qobject.rst new file mode 100644 index 0000000000..4f192ced7c --- /dev/null +++ b/docs/devel/qobject.rst @@ -0,0 +1,11 @@ +QObject API +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +.. kernel-doc:: include/qapi/qmp/qobject.h + +QNum module +----------- + +.. kernel-doc:: include/qapi/qmp/qnum.h + +.. kernel-doc:: qobject/qnum.c diff --git a/include/qapi/qmp/qnum.h b/include/qapi/qmp/qnum.h index bbae0a5ec8..25f4733efc 100644 --- a/include/qapi/qmp/qnum.h +++ b/include/qapi/qmp/qnum.h @@ -23,7 +23,9 @@ typedef enum { QNUM_DOUBLE } QNumKind; =20 -/* +/** + * DOC: + * * QNum encapsulates how our dialect of JSON fills in the blanks left * by the JSON specification (RFC 8259) regarding numbers. * diff --git a/include/qapi/qmp/qobject.h b/include/qapi/qmp/qobject.h index fcfd549220..bdc33bdb65 100644 --- a/include/qapi/qmp/qobject.h +++ b/include/qapi/qmp/qobject.h @@ -1,5 +1,5 @@ /* - * QEMU Object Model. + * QObject API * * Based on ideas by Avi Kivity * @@ -10,24 +10,31 @@ * * This work is licensed under the terms of the GNU LGPL, version 2.1 or l= ater. * See the COPYING.LIB file in the top-level directory. + */ + +/** + * DOC: QObject Reference Counts Terminology * - * QObject Reference Counts Terminology - * ------------------------------------ + * Returning references + * -------------------- * - * - Returning references: A function that returns an object may - * return it as either a weak or a strong reference. If the - * reference is strong, you are responsible for calling - * qobject_unref() on the reference when you are done. + * A function that returns an object may return it as either a + * weak or a strong reference. If the reference is strong, you + * are responsible for calling qobject_unref() on the reference + * when you are done. * - * If the reference is weak, the owner of the reference may free it at - * any time in the future. Before storing the reference anywhere, you - * should call qobject_ref() to make the reference strong. + * If the reference is weak, the owner of the reference may free it at + * any time in the future. Before storing the reference anywhere, you + * should call qobject_ref() to make the reference strong. * - * - Transferring ownership: when you transfer ownership of a reference - * by calling a function, you are no longer responsible for calling - * qobject_unref() when the reference is no longer needed. In other word= s, - * when the function returns you must behave as if the reference to the - * passed object was weak. + * Transferring ownership + * ---------------------- + * + * When you transfer ownership of a reference by calling a + * function, you are no longer responsible for calling + * qobject_unref() when the reference is no longer needed. In + * other words, when the function returns you must behave as if + * the reference to the passed object was weak. */ #ifndef QOBJECT_H #define QOBJECT_H @@ -81,6 +88,8 @@ static inline void qobject_ref_impl(QObject *obj) =20 /** * qobject_is_equal(): Return whether the two objects are equal. + * @x: QObject pointer + * @y: QObject pointer * * Any of the pointers may be NULL; return true if both are. Always * return false if only one is (therefore a QNull object is not @@ -90,6 +99,7 @@ bool qobject_is_equal(const QObject *x, const QObject *y); =20 /** * qobject_destroy(): Free resources used by the object + * @obj: QObject pointer */ void qobject_destroy(QObject *obj); =20 @@ -103,6 +113,7 @@ static inline void qobject_unref_impl(QObject *obj) =20 /** * qobject_ref(): Increment QObject's reference count + * @obj: QObject pointer * * Returns: the same @obj. The type of @obj will be propagated to the * return type. @@ -115,12 +126,14 @@ static inline void qobject_unref_impl(QObject *obj) =20 /** * qobject_unref(): Decrement QObject's reference count, deallocate - * when it reaches zero + * when it reaches zero + * @obj: QObject pointer */ #define qobject_unref(obj) qobject_unref_impl(QOBJECT(obj)) =20 /** * qobject_type(): Return the QObject's type + * @obj: QObject pointer */ static inline QType qobject_type(const QObject *obj) { @@ -130,6 +143,9 @@ static inline QType qobject_type(const QObject *obj) =20 /** * qobject_check_type(): Helper function for the qobject_to() macro. + * @obj: QObject pointer + * @type: Expected type of QObject + * * Return @obj, but only if @obj is not NULL and @type is equal to * @obj's type. Return NULL otherwise. */ diff --git a/qobject/qnum.c b/qobject/qnum.c index 7012fc57f2..017c8aa739 100644 --- a/qobject/qnum.c +++ b/qobject/qnum.c @@ -17,6 +17,7 @@ =20 /** * qnum_from_int(): Create a new QNum from an int64_t + * @value: int64_t value * * Return strong reference. */ @@ -33,6 +34,7 @@ QNum *qnum_from_int(int64_t value) =20 /** * qnum_from_uint(): Create a new QNum from an uint64_t + * @value: uint64_t value * * Return strong reference. */ @@ -49,6 +51,7 @@ QNum *qnum_from_uint(uint64_t value) =20 /** * qnum_from_double(): Create a new QNum from a double + * @value: double value * * Return strong reference. */ @@ -65,6 +68,8 @@ QNum *qnum_from_double(double value) =20 /** * qnum_get_try_int(): Get an integer representation of the number + * @qn: QNum object + * @val: pointer to value * * Return true on success. */ @@ -90,6 +95,7 @@ bool qnum_get_try_int(const QNum *qn, int64_t *val) =20 /** * qnum_get_int(): Get an integer representation of the number + * @qn: QNum object * * assert() on failure. */ @@ -102,7 +108,9 @@ int64_t qnum_get_int(const QNum *qn) } =20 /** - * qnum_get_uint(): Get an unsigned integer from the number + * qnum_value_get_try_uint(): Get an unsigned integer from the number + * @qn: QNum object + * @val: pointer to value * * Return true on success. */ @@ -128,6 +136,7 @@ bool qnum_get_try_uint(const QNum *qn, uint64_t *val) =20 /** * qnum_get_uint(): Get an unsigned integer from the number + * @qn: QNum object * * assert() on failure. */ @@ -141,6 +150,7 @@ uint64_t qnum_get_uint(const QNum *qn) =20 /** * qnum_get_double(): Get a float representation of the number + * @qn: QNum object * * qnum_get_double() loses precision for integers beyond 53 bits. */ @@ -200,6 +210,8 @@ char *qnum_to_string(QNum *qn) =20 /** * qnum_is_equal(): Test whether the two QNums are equal + * @x: QNum object + * @y: QNum object * * Negative integers are never considered equal to unsigned integers, * but positive integers in the range [0, INT64_MAX] are considered @@ -253,8 +265,9 @@ bool qnum_is_equal(const QObject *x, const QObject *y) } =20 /** - * qnum_destroy_obj(): Free all memory allocated by a - * QNum object + * qnum_destroy_obj(): Free all memory allocated by a QNum object + * + * @obj: QNum object to be destroyed */ void qnum_destroy_obj(QObject *obj) { --=20 2.28.0 From nobody Fri May 3 20:42:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1604957389; cv=none; d=zohomail.com; s=zohoarc; b=dz7piUdo85WDEpb/wQR7LIqWPx2RTBH1AHBbpALp8MERG+8j+em7mcCNrGqyRPJWZzzSyxY+OFKEZApCpYfyozXNFWKrMZCkP4CDBs4dOJUKRKv0Eovx7V37ioMONGyAQmapIgXpAMhW04pUOl5Uboo5q9JDuUVuHwSl/HbgdSk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604957389; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8B6xsDmwNBdWQ4Mkz4kMaIjCQe5ilmv5nv3lzRRlkNE=; b=W045v1J5MPTRUQiK5V9AgIJj0x6xeRxlhsdPvemmjMPvhy5j0tn3HkTJtIPdfWQASIMd3Iz6Pl2QM9VPQYi/UJAk/nEBSoRbGu/TwlEMaSBy5F8l2hTAVLWSF4zVmnkSsYTYdk1nX/z/KUx3TGd70wGj7qqZBRFyK/NjyVb/HSI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604957389563114.32661129782412; Mon, 9 Nov 2020 13:29:49 -0800 (PST) Received: from localhost ([::1]:60120 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcEjU-0008W0-9c for importer@patchew.org; Mon, 09 Nov 2020 16:29:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcEfw-0003sD-Lc for qemu-devel@nongnu.org; Mon, 09 Nov 2020 16:26:09 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:41106) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kcEfu-0005aa-BG for qemu-devel@nongnu.org; Mon, 09 Nov 2020 16:26:08 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-168-nvjM6dKhMXiBLGA6CNCWEg-1; Mon, 09 Nov 2020 16:26:01 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7030E10A0BB5 for ; Mon, 9 Nov 2020 21:26:00 +0000 (UTC) Received: from localhost (ovpn-114-68.rdu2.redhat.com [10.10.114.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 383BD2C605; Mon, 9 Nov 2020 21:26:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604957164; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8B6xsDmwNBdWQ4Mkz4kMaIjCQe5ilmv5nv3lzRRlkNE=; b=fBtIrCBYAhakxqsopXZrmiGd4rS3y9nxkq1R0PSMNDSSqMyX73z+LrnIUCZcHcP9ioCtc/ ZAp/Gah2uILYJaUuDf925RUGcB5kQl4kC5VG12YPEVzDHoh8IwDeH3s5haEuZfNBe1K7MU IrSXCwhyygWBF8y96+dOKHSQ49SU6jk= X-MC-Unique: nvjM6dKhMXiBLGA6CNCWEg-1 From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH 2/8] qnum: Make qnum_get_double() get const pointer Date: Mon, 9 Nov 2020 16:25:50 -0500 Message-Id: <20201109212556.3934583-3-ehabkost@redhat.com> In-Reply-To: <20201109212556.3934583-1-ehabkost@redhat.com> References: <20201109212556.3934583-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ehabkost@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=ehabkost@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/09 01:25:23 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" qnum_get_double() won't change the object, the argument can be const. Signed-off-by: Eduardo Habkost Acked-by: Paolo Bonzini --- include/qapi/qmp/qnum.h | 2 +- qobject/qnum.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/qapi/qmp/qnum.h b/include/qapi/qmp/qnum.h index 25f4733efc..55c27b1c24 100644 --- a/include/qapi/qmp/qnum.h +++ b/include/qapi/qmp/qnum.h @@ -66,7 +66,7 @@ int64_t qnum_get_int(const QNum *qn); bool qnum_get_try_uint(const QNum *qn, uint64_t *val); uint64_t qnum_get_uint(const QNum *qn); =20 -double qnum_get_double(QNum *qn); +double qnum_get_double(const QNum *qn); =20 char *qnum_to_string(QNum *qn); =20 diff --git a/qobject/qnum.c b/qobject/qnum.c index 017c8aa739..69fd9a82d9 100644 --- a/qobject/qnum.c +++ b/qobject/qnum.c @@ -154,7 +154,7 @@ uint64_t qnum_get_uint(const QNum *qn) * * qnum_get_double() loses precision for integers beyond 53 bits. */ -double qnum_get_double(QNum *qn) +double qnum_get_double(const QNum *qn) { switch (qn->kind) { case QNUM_I64: --=20 2.28.0 From nobody Fri May 3 20:42:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1604957281; cv=none; d=zohomail.com; s=zohoarc; b=K25h2PFlOwVf+FA0R1qSZ17H4BCRLhU1H05J/55bzG5JLgESn7upLM5AlOmfVTwHS3z9vu8Xj4tG00gzMnopZbLn8XUDv6y8b/OYR2JJY86CDQudHZQS+PBn5wv3Q1D65JMRmE4dKPi5Xd/i7f/w/xnsAaNoda778y61Oyhts4o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604957281; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qV9fU25bD3yUHXQJa/vamTz1JOYnMnNvXJQyfXQfB2g=; b=aDs0+qkN2A8fYpFLAb7jBXRyw2vW3ySonrfqqJ+E/eLt4ZDDu+TOiepYqrQD5j6NGHVJoL6IYAWMoXCiKbmXH2zTnAtpTYBUUVvhUIxX0e4Quh7pp7LrkAfIrQkMNBTpzVFzr3UX5MZbVdNXcWBF0CdNOiARWLTur9Cb/DuIok4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604957281212807.7051011916675; Mon, 9 Nov 2020 13:28:01 -0800 (PST) Received: from localhost ([::1]:54296 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcEhj-0005nT-Vi for importer@patchew.org; Mon, 09 Nov 2020 16:28:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33706) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcEg9-00043t-6a for qemu-devel@nongnu.org; Mon, 09 Nov 2020 16:26:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:39353) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kcEg4-0005cN-5d for qemu-devel@nongnu.org; Mon, 09 Nov 2020 16:26:20 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-564-jO1O_d05M-iw-dA2I7TB5w-1; Mon, 09 Nov 2020 16:26:05 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 350676D249 for ; Mon, 9 Nov 2020 21:26:04 +0000 (UTC) Received: from localhost (ovpn-114-68.rdu2.redhat.com [10.10.114.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4563175134; Mon, 9 Nov 2020 21:26:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604957175; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qV9fU25bD3yUHXQJa/vamTz1JOYnMnNvXJQyfXQfB2g=; b=G6D7Nwvt1SB0QxZYW8CELAOGTuzP/c+jR+L2eRAmuMBfbRyTD/wX1Y4P/3SanEry8lCo5H BI/5K63zmNYk5DUcizP5tJONJObxUAOYmQy0q2lccgKPmoBcmQLRQhSyDk35DJcLRqc4pM Yw+AuorSPRSDXCHnEGvsE30xWWFTN7I= X-MC-Unique: jO1O_d05M-iw-dA2I7TB5w-1 From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH 3/8] qnum: QNumValue type for QNum value literals Date: Mon, 9 Nov 2020 16:25:51 -0500 Message-Id: <20201109212556.3934583-4-ehabkost@redhat.com> In-Reply-To: <20201109212556.3934583-1-ehabkost@redhat.com> References: <20201109212556.3934583-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ehabkost@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=ehabkost@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/09 01:25:23 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Provide a separate QNumValue type that can be used for QNum value literals without the referencing counting and memory allocation features provided by QObject. Signed-off-by: Eduardo Habkost Acked-by: Paolo Bonzini --- include/qapi/qmp/qnum.h | 40 +++++++++++++++++++-- qobject/qnum.c | 78 ++++++++++++++++++++--------------------- 2 files changed, 77 insertions(+), 41 deletions(-) diff --git a/include/qapi/qmp/qnum.h b/include/qapi/qmp/qnum.h index 55c27b1c24..62fbdfda68 100644 --- a/include/qapi/qmp/qnum.h +++ b/include/qapi/qmp/qnum.h @@ -46,20 +46,56 @@ typedef enum { * in range: qnum_get_try_int() / qnum_get_try_uint() check range and * convert under the hood. */ -struct QNum { - struct QObjectBase_ base; + +/** + * struct QNumValue: the value of a QNum + * + * QNumValue literals can be constructed using the `QNUM_VAL_INT`, + * `QNUM_VAL_UINT`, and `QNUM_VAL_DOUBLE` macros. + */ +typedef struct QNumValue { + /* private: */ QNumKind kind; union { int64_t i64; uint64_t u64; double dbl; } u; +} QNumValue; + +#define QNUM_VAL_INT(value) \ + { .kind =3D QNUM_I64, .u.i64 =3D value } +#define QNUM_VAL_UINT(value) \ + { .kind =3D QNUM_U64, .u.u64 =3D value } +#define QNUM_VAL_DOUBLE(value) \ + { .kind =3D QNUM_DOUBLE, .u.dbl =3D value } + +struct QNum { + struct QObjectBase_ base; + QNumValue value; }; =20 +/** + * qnum_from_int(): Create a new QNum from a QNumValue + * @value: QNumValue + * + * Return strong reference. + */ +QNum *qnum_from_value(QNumValue value); + QNum *qnum_from_int(int64_t value); QNum *qnum_from_uint(uint64_t value); QNum *qnum_from_double(double value); =20 +/** + * qnum_get_value(): Get QNumValue from QNum + * @qn: QNum object + */ +static inline const QNumValue *qnum_get_value(const QNum *qn) +{ + return &qn->value; +} + bool qnum_get_try_int(const QNum *qn, int64_t *val); int64_t qnum_get_int(const QNum *qn); =20 diff --git a/qobject/qnum.c b/qobject/qnum.c index 69fd9a82d9..f80d4efd76 100644 --- a/qobject/qnum.c +++ b/qobject/qnum.c @@ -15,6 +15,15 @@ #include "qemu/osdep.h" #include "qapi/qmp/qnum.h" =20 +QNum *qnum_from_value(QNumValue value) +{ + QNum *qn =3D g_new(QNum, 1); + + qobject_init(QOBJECT(qn), QTYPE_QNUM); + qn->value =3D value; + return qn; +} + /** * qnum_from_int(): Create a new QNum from an int64_t * @value: int64_t value @@ -23,13 +32,7 @@ */ QNum *qnum_from_int(int64_t value) { - QNum *qn =3D g_new(QNum, 1); - - qobject_init(QOBJECT(qn), QTYPE_QNUM); - qn->kind =3D QNUM_I64; - qn->u.i64 =3D value; - - return qn; + return qnum_from_value((QNumValue) QNUM_VAL_INT(value)); } =20 /** @@ -40,13 +43,7 @@ QNum *qnum_from_int(int64_t value) */ QNum *qnum_from_uint(uint64_t value) { - QNum *qn =3D g_new(QNum, 1); - - qobject_init(QOBJECT(qn), QTYPE_QNUM); - qn->kind =3D QNUM_U64; - qn->u.u64 =3D value; - - return qn; + return qnum_from_value((QNumValue) QNUM_VAL_UINT(value)); } =20 /** @@ -57,13 +54,7 @@ QNum *qnum_from_uint(uint64_t value) */ QNum *qnum_from_double(double value) { - QNum *qn =3D g_new(QNum, 1); - - qobject_init(QOBJECT(qn), QTYPE_QNUM); - qn->kind =3D QNUM_DOUBLE; - qn->u.dbl =3D value; - - return qn; + return qnum_from_value((QNumValue) QNUM_VAL_DOUBLE(value)); } =20 /** @@ -75,15 +66,17 @@ QNum *qnum_from_double(double value) */ bool qnum_get_try_int(const QNum *qn, int64_t *val) { - switch (qn->kind) { + const QNumValue *qv =3D &qn->value; + + switch (qv->kind) { case QNUM_I64: - *val =3D qn->u.i64; + *val =3D qv->u.i64; return true; case QNUM_U64: - if (qn->u.u64 > INT64_MAX) { + if (qv->u.u64 > INT64_MAX) { return false; } - *val =3D qn->u.u64; + *val =3D qv->u.u64; return true; case QNUM_DOUBLE: return false; @@ -116,15 +109,17 @@ int64_t qnum_get_int(const QNum *qn) */ bool qnum_get_try_uint(const QNum *qn, uint64_t *val) { - switch (qn->kind) { + const QNumValue *qv =3D &qn->value; + + switch (qv->kind) { case QNUM_I64: - if (qn->u.i64 < 0) { + if (qv->u.i64 < 0) { return false; } - *val =3D qn->u.i64; + *val =3D qv->u.i64; return true; case QNUM_U64: - *val =3D qn->u.u64; + *val =3D qv->u.u64; return true; case QNUM_DOUBLE: return false; @@ -156,13 +151,15 @@ uint64_t qnum_get_uint(const QNum *qn) */ double qnum_get_double(const QNum *qn) { - switch (qn->kind) { + const QNumValue *qv =3D &qn->value; + + switch (qv->kind) { case QNUM_I64: - return qn->u.i64; + return qv->u.i64; case QNUM_U64: - return qn->u.u64; + return qv->u.u64; case QNUM_DOUBLE: - return qn->u.dbl; + return qv->u.dbl; } =20 assert(0); @@ -171,14 +168,15 @@ double qnum_get_double(const QNum *qn) =20 char *qnum_to_string(QNum *qn) { + const QNumValue *qv =3D &qn->value; char *buffer; int len; =20 - switch (qn->kind) { + switch (qv->kind) { case QNUM_I64: - return g_strdup_printf("%" PRId64, qn->u.i64); + return g_strdup_printf("%" PRId64, qv->u.i64); case QNUM_U64: - return g_strdup_printf("%" PRIu64, qn->u.u64); + return g_strdup_printf("%" PRIu64, qv->u.u64); case QNUM_DOUBLE: /* FIXME: snprintf() is locale dependent; but JSON requires * numbers to be formatted as if in the C locale. Dependence @@ -189,7 +187,7 @@ char *qnum_to_string(QNum *qn) * rounding errors; we should be using DBL_DECIMAL_DIG (17), * and only rounding to a shorter number if the result would * still produce the same floating point value. */ - buffer =3D g_strdup_printf("%f" , qn->u.dbl); + buffer =3D g_strdup_printf("%f" , qv->u.dbl); len =3D strlen(buffer); while (len > 0 && buffer[len - 1] =3D=3D '0') { len--; @@ -221,8 +219,10 @@ char *qnum_to_string(QNum *qn) */ 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); + const QNum *qnum_x =3D qobject_to(QNum, x); + const QNum *qnum_y =3D qobject_to(QNum, y); + const QNumValue *num_x =3D &qnum_x->value; + const QNumValue *num_y =3D &qnum_y->value; =20 switch (num_x->kind) { case QNUM_I64: --=20 2.28.0 From nobody Fri May 3 20:42:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1604957263; cv=none; d=zohomail.com; s=zohoarc; b=a08YL3JKidB1oJ7QBmuho5S8WqoO/1DIl/eTQddeGXxc3mR7Sz1Z7649n+Gyg9qjiJFhEP1D3/Lhc+smWu4uB98LC9KBtVDVq2njLIuAlKsGpBn1tfak4LpnIdceAKaliU8oRncAlX6b/+/5qn0KjYDK4raWk9wG8lGdwLW3naM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604957263; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WtYmU02TyTHMCT8p52Unsn1UtpXki2UBOqhDJEoT+Bg=; b=MmmvakQEF8589/cy0qv7NEJq4kyMNi1bc2tE0d+DtoTuNXK+QujOogP3rjkd6EPtx8Bn+B31fab6ZzbhNT1jEerhygvqbMblrwDpjPHuOzB/5uj4qct+xdrom4IMZhueH0ZoYLb9OuMm5X9vrcP2/4Pp44tZSArQJZEUVTvFi9w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604957263559926.0666325422759; Mon, 9 Nov 2020 13:27:43 -0800 (PST) Received: from localhost ([::1]:53808 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcEhS-0005Zu-9T for importer@patchew.org; Mon, 09 Nov 2020 16:27:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33630) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcEg2-0003uG-1e for qemu-devel@nongnu.org; Mon, 09 Nov 2020 16:26:14 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:20280) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kcEfz-0005bE-43 for qemu-devel@nongnu.org; Mon, 09 Nov 2020 16:26:13 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-96-HdLc6BkIOBORut_Vj2NlTQ-1; Mon, 09 Nov 2020 16:26:08 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A3AAC6D244 for ; Mon, 9 Nov 2020 21:26:06 +0000 (UTC) Received: from localhost (ovpn-114-68.rdu2.redhat.com [10.10.114.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 98B351A3D6; Mon, 9 Nov 2020 21:26:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604957170; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WtYmU02TyTHMCT8p52Unsn1UtpXki2UBOqhDJEoT+Bg=; b=SKb/KtjeX+6B2KkRM6dwD10a0lbHPLY728P0FTmxT/nntk+NmyGwv2g2JGjs1GgszSkrZp QTvvGkERGxcNJEaLMib8CxB8jR2+GO0Ecx9pjwlU0eyHxQcLaMwsqJ95dk4Ctz8dtw6HdG k+AZOqw9Ivsny+0qJlEy6Y/+0+HXd2k= X-MC-Unique: HdLc6BkIOBORut_Vj2NlTQ-1 From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH 4/8] qnum: qnum_value_is_equal() function Date: Mon, 9 Nov 2020 16:25:52 -0500 Message-Id: <20201109212556.3934583-5-ehabkost@redhat.com> In-Reply-To: <20201109212556.3934583-1-ehabkost@redhat.com> References: <20201109212556.3934583-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ehabkost@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=ehabkost@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/09 01:25:23 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Extract the QNum value comparison logic to a function that takes QNumValue* as argument. Signed-off-by: Eduardo Habkost Acked-by: Paolo Bonzini --- include/qapi/qmp/qnum.h | 1 + qobject/qnum.c | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/include/qapi/qmp/qnum.h b/include/qapi/qmp/qnum.h index 62fbdfda68..0327ecd0f0 100644 --- a/include/qapi/qmp/qnum.h +++ b/include/qapi/qmp/qnum.h @@ -106,6 +106,7 @@ double qnum_get_double(const QNum *qn); =20 char *qnum_to_string(QNum *qn); =20 +bool qnum_value_is_equal(const QNumValue *num_x, const QNumValue *num_y); bool qnum_is_equal(const QObject *x, const QObject *y); void qnum_destroy_obj(QObject *obj); =20 diff --git a/qobject/qnum.c b/qobject/qnum.c index f80d4efd76..6a0f948b16 100644 --- a/qobject/qnum.c +++ b/qobject/qnum.c @@ -207,9 +207,9 @@ char *qnum_to_string(QNum *qn) } =20 /** - * qnum_is_equal(): Test whether the two QNums are equal - * @x: QNum object - * @y: QNum object + * qnum_value_is_equal(): Test whether two QNumValues are equal + * @num_x: QNum value + * @num_y: QNum value * * Negative integers are never considered equal to unsigned integers, * but positive integers in the range [0, INT64_MAX] are considered @@ -217,13 +217,8 @@ char *qnum_to_string(QNum *qn) * * Doubles are never considered equal to integers. */ -bool qnum_is_equal(const QObject *x, const QObject *y) +bool qnum_value_is_equal(const QNumValue *num_x, const QNumValue *num_y) { - const QNum *qnum_x =3D qobject_to(QNum, x); - const QNum *qnum_y =3D qobject_to(QNum, y); - const QNumValue *num_x =3D &qnum_x->value; - const QNumValue *num_y =3D &qnum_y->value; - switch (num_x->kind) { case QNUM_I64: switch (num_y->kind) { @@ -241,7 +236,7 @@ bool qnum_is_equal(const QObject *x, const QObject *y) case QNUM_U64: switch (num_y->kind) { case QNUM_I64: - return qnum_is_equal(y, x); + return qnum_value_is_equal(num_y, num_x); case QNUM_U64: /* Comparison in native uint64_t type */ return num_x->u.u64 =3D=3D num_y->u.u64; @@ -264,6 +259,20 @@ bool qnum_is_equal(const QObject *x, const QObject *y) abort(); } =20 +/** + * qnum_is_equal(): Test whether the two QNums are equal + * @x: QNum object + * @y: QNum object + * + * See qnum_value_is_equal() for details on the comparison rules. + */ +bool qnum_is_equal(const QObject *x, const QObject *y) +{ + const QNum *qnum_x =3D qobject_to(QNum, x); + const QNum *qnum_y =3D qobject_to(QNum, y); + return qnum_value_is_equal(&qnum_x->value, &qnum_y->value); +} + /** * qnum_destroy_obj(): Free all memory allocated by a QNum object * --=20 2.28.0 From nobody Fri May 3 20:42:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1604957589; cv=none; d=zohomail.com; s=zohoarc; b=elnE/E9YNhhDZ0gtfZm/BB0HOj/zXIEDInxC7cZNiAINmGwg/xUggbVE7ejgzzTBEgZ4kAQjpli8NW6/YftRWbVSIGrJeRvQAKb7IsTu5iBW0REgV05+A5+O9crKjcYPO7i9ThP4wskfceanVQ8sielmgfQ7NCWEIn95VDjhgEI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604957589; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HrttNqAhwpG0xM9KyBcAIFaMWj5fSOHCWB5lN6j6duY=; b=KGdupE34WOLhidhecBdecQbTovXWEE/Jg/L2ZsgceYIiy1kzLxiaRdsX+1xMsJOqjB6xXp4jGYTl5riez5wxI+82Op0UdRCWjCXnDOlkQFCUNMVyllgN9PvQnO92iE3efdSen+5VwlpfkUw6hI5jgaUrFn+thfKsShW4P4QhywQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16049575890581019.0212314100796; Mon, 9 Nov 2020 13:33:09 -0800 (PST) Received: from localhost ([::1]:37570 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcEmh-0002c1-Q3 for importer@patchew.org; Mon, 09 Nov 2020 16:33:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33674) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcEg4-0003yA-Q7 for qemu-devel@nongnu.org; Mon, 09 Nov 2020 16:26:16 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:31012) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kcEg2-0005c3-Qb for qemu-devel@nongnu.org; Mon, 09 Nov 2020 16:26:16 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-540-4GgTmPKWNZK-4qRrYmS3gQ-1; Mon, 09 Nov 2020 16:26:09 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DDD47879513 for ; Mon, 9 Nov 2020 21:26:08 +0000 (UTC) Received: from localhost (ovpn-114-68.rdu2.redhat.com [10.10.114.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE1F77E72A; Mon, 9 Nov 2020 21:26:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604957173; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HrttNqAhwpG0xM9KyBcAIFaMWj5fSOHCWB5lN6j6duY=; b=UxJvguv/JqbE+XupvCqQmok0rBlMG5Nw4vSh5kb45CRj2+P+ZjKPsVcplUVEPnqyXu8/qc 2UJVhJpX1VBK/lKh1LAWmyOhDOYC+xGjcM7gdIWq8KjrIe+TGIy238h8zHhd4A+iMJyimn tiEMZRvE/ASpVMsRn7uSx69ICWsCqrM= X-MC-Unique: 4GgTmPKWNZK-4qRrYmS3gQ-1 From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH 5/8] qlit: Support all types of QNums Date: Mon, 9 Nov 2020 16:25:53 -0500 Message-Id: <20201109212556.3934583-6-ehabkost@redhat.com> In-Reply-To: <20201109212556.3934583-1-ehabkost@redhat.com> References: <20201109212556.3934583-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ehabkost@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=ehabkost@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/09 01:25:23 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Use QNumValue to represent QNums, so we can also support uint64_t and double QNum values. Add new QLIT_QNUM_(INT|UINT|DOUBLE) macros for each case. The QLIT_QNUM() macro is being kept for compatibility with existing code, but becomes just a wrapper for QLIT_QNUM_INT(). Signed-off-by: Eduardo Habkost Acked-by: Paolo Bonzini --- include/qapi/qmp/qlit.h | 11 +++++-- qobject/qlit.c | 4 +-- tests/check-qjson.c | 72 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 78 insertions(+), 9 deletions(-) diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h index c0676d5daf..f9e356d31e 100644 --- a/include/qapi/qmp/qlit.h +++ b/include/qapi/qmp/qlit.h @@ -15,6 +15,7 @@ #define QLIT_H =20 #include "qobject.h" +#include "qnum.h" =20 typedef struct QLitDictEntry QLitDictEntry; typedef struct QLitObject QLitObject; @@ -23,7 +24,7 @@ struct QLitObject { QType type; union { bool qbool; - int64_t qnum; + QNumValue qnum; const char *qstr; QLitDictEntry *qdict; QLitObject *qlist; @@ -39,8 +40,14 @@ struct QLitDictEntry { { .type =3D QTYPE_QNULL } #define QLIT_QBOOL(val) \ { .type =3D QTYPE_QBOOL, .value.qbool =3D (val) } +#define QLIT_QNUM_INT(val) \ + { .type =3D QTYPE_QNUM, .value.qnum =3D QNUM_VAL_INT(val) } +#define QLIT_QNUM_UINT(val) \ + { .type =3D QTYPE_QNUM, .value.qnum =3D QNUM_VAL_UINT(val) } +#define QLIT_QNUM_DOUBLE(val) \ + { .type =3D QTYPE_QNUM, .value.qnum =3D QNUM_VAL_DOUBLE(val) } #define QLIT_QNUM(val) \ - { .type =3D QTYPE_QNUM, .value.qnum =3D (val) } + QLIT_QNUM_INT(val) #define QLIT_QSTR(val) \ { .type =3D QTYPE_QSTRING, .value.qstr =3D (val) } #define QLIT_QDICT(val) \ diff --git a/qobject/qlit.c b/qobject/qlit.c index be8332136c..ec11a39518 100644 --- a/qobject/qlit.c +++ b/qobject/qlit.c @@ -71,7 +71,7 @@ bool qlit_equal_qobject(const QLitObject *lhs, const QObj= ect *rhs) case QTYPE_QBOOL: return lhs->value.qbool =3D=3D qbool_get_bool(qobject_to(QBool, rh= s)); case QTYPE_QNUM: - return lhs->value.qnum =3D=3D qnum_get_int(qobject_to(QNum, rhs)); + return qnum_value_is_equal(&lhs->value.qnum, qnum_get_value(qobjec= t_to(QNum, rhs))); case QTYPE_QSTRING: return (strcmp(lhs->value.qstr, qstring_get_str(qobject_to(QString, rhs))) =3D=3D 0= ); @@ -94,7 +94,7 @@ QObject *qobject_from_qlit(const QLitObject *qlit) case QTYPE_QNULL: return QOBJECT(qnull()); case QTYPE_QNUM: - return QOBJECT(qnum_from_int(qlit->value.qnum)); + return QOBJECT(qnum_from_value(qlit->value.qnum)); case QTYPE_QSTRING: return QOBJECT(qstring_from_str(qlit->value.qstr)); case QTYPE_QDICT: { diff --git a/tests/check-qjson.c b/tests/check-qjson.c index 07a773e653..711030cffd 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -796,20 +796,23 @@ static void simple_number(void) int i; struct { const char *encoded; + QLitObject qlit; int64_t decoded; int skip; } test_cases[] =3D { - { "0", 0 }, - { "1234", 1234 }, - { "1", 1 }, - { "-32", -32 }, - { "-0", 0, .skip =3D 1 }, + { "0", QLIT_QNUM(0), 0, }, + { "1234", QLIT_QNUM(1234), 1234, }, + { "1", QLIT_QNUM(1), 1, }, + { "-32", QLIT_QNUM(-32), -32, }, + { "-0", QLIT_QNUM(0), 0, .skip =3D 1 }, { }, }; =20 for (i =3D 0; test_cases[i].encoded; i++) { QNum *qnum; int64_t val; + QNum *qlit_num; + int64_t qlit_val; =20 qnum =3D qobject_to(QNum, qobject_from_json(test_cases[i].encoded, @@ -817,6 +820,7 @@ static void simple_number(void) g_assert(qnum); g_assert(qnum_get_try_int(qnum, &val)); g_assert_cmpint(val, =3D=3D, test_cases[i].decoded); + if (test_cases[i].skip =3D=3D 0) { QString *str; =20 @@ -826,9 +830,66 @@ static void simple_number(void) } =20 qobject_unref(qnum); + + qlit_num =3D qobject_to(QNum, + qobject_from_qlit(&test_cases[i].qlit)); + g_assert(qlit_num); + g_assert(qnum_get_try_int(qlit_num, &qlit_val)); + g_assert_cmpint(qlit_val, =3D=3D, test_cases[i].decoded); + + qobject_unref(qlit_num); } } =20 +static void qlit_large_number(void) +{ + QLitObject maxu64 =3D QLIT_QNUM_UINT(UINT64_MAX); + QLitObject maxi64 =3D QLIT_QNUM(INT64_MAX); + QLitObject mini64 =3D QLIT_QNUM(INT64_MIN); + QLitObject gtu64 =3D QLIT_QNUM_DOUBLE(18446744073709552e3); + QLitObject lti64 =3D QLIT_QNUM_DOUBLE(-92233720368547758e2); + QNum *qnum; + uint64_t val; + int64_t ival; + + qnum =3D qobject_to(QNum, qobject_from_qlit(&maxu64)); + g_assert(qnum); + g_assert_cmpuint(qnum_get_uint(qnum), =3D=3D, UINT64_MAX); + g_assert(!qnum_get_try_int(qnum, &ival)); + + qobject_unref(qnum); + + qnum =3D qobject_to(QNum, qobject_from_qlit(&maxi64)); + g_assert(qnum); + g_assert_cmpuint(qnum_get_uint(qnum), =3D=3D, INT64_MAX); + g_assert_cmpint(qnum_get_int(qnum), =3D=3D, INT64_MAX); + + qobject_unref(qnum); + + qnum =3D qobject_to(QNum, qobject_from_qlit(&mini64)); + g_assert(qnum); + g_assert(!qnum_get_try_uint(qnum, &val)); + g_assert_cmpuint(qnum_get_int(qnum), =3D=3D, INT64_MIN); + + qobject_unref(qnum); + + qnum =3D qobject_to(QNum, qobject_from_qlit(>u64)); + g_assert(qnum); + g_assert_cmpfloat(qnum_get_double(qnum), =3D=3D, 18446744073709552e3); + g_assert(!qnum_get_try_uint(qnum, &val)); + g_assert(!qnum_get_try_int(qnum, &ival)); + + qobject_unref(qnum); + + qnum =3D qobject_to(QNum, qobject_from_qlit(<i64)); + g_assert(qnum); + g_assert_cmpfloat(qnum_get_double(qnum), =3D=3D, -92233720368547758e2); + g_assert(!qnum_get_try_uint(qnum, &val)); + g_assert(!qnum_get_try_int(qnum, &ival)); + + qobject_unref(qnum); +} + static void large_number(void) { const char *maxu64 =3D "18446744073709551615"; /* 2^64-1 */ @@ -1472,6 +1533,7 @@ int main(int argc, char **argv) g_test_add_func("/literals/string/utf8", utf8_string); =20 g_test_add_func("/literals/number/simple", simple_number); + g_test_add_func("/literals/number/qlit_large", qlit_large_number); g_test_add_func("/literals/number/large", large_number); g_test_add_func("/literals/number/float", float_number); =20 --=20 2.28.0 From nobody Fri May 3 20:42:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1604957510; cv=none; d=zohomail.com; s=zohoarc; b=a6HOQMPm78ZlCCiZQZoMlvvqnSONmF53iNO781fzgDMQQHwLpVbUky3zyzxywMKqGclRIswpuvXBYKp5FstOG7wKFmgtFAQGlV9L+Exti1fi9DV4gUtWXUDmh9hwtgzrDF4AMMlTz6pHoywB1eRjnjUB3uGQQ2VvrYc9R+lsuPQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604957510; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=xofk8m98sNE1h54NPYXIudAMYeqC9+/+um6ge21shC0=; b=Hh/T1ONjCCl3JNYZ8b91bJgRqopHocc/5g0iuOW79jDkmEt+cuqsYXVhOH6K6+pu35BZg0TjhbX9rS/2CTg4JGFoZXDSP/9myOaHVZ/Q3/vgtZn6f7jFykLG5gwuae/gG5qw0RZZoYWzKtJvWBxmgk2kNg7XzWcu1YWrhBM4FH8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604957510031928.9941624249527; Mon, 9 Nov 2020 13:31:50 -0800 (PST) Received: from localhost ([::1]:36470 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcElR-00028n-0X for importer@patchew.org; Mon, 09 Nov 2020 16:31:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33692) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcEg5-0003za-Ji for qemu-devel@nongnu.org; Mon, 09 Nov 2020 16:26:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:44346) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kcEg3-0005c7-8g for qemu-devel@nongnu.org; Mon, 09 Nov 2020 16:26:17 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-60-NgY7TepPO4q4pL26BmJE1g-1; Mon, 09 Nov 2020 16:26:10 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0E1338030BC for ; Mon, 9 Nov 2020 21:26:10 +0000 (UTC) Received: from localhost (ovpn-114-68.rdu2.redhat.com [10.10.114.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id C52BF6EF70; Mon, 9 Nov 2020 21:26:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604957174; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xofk8m98sNE1h54NPYXIudAMYeqC9+/+um6ge21shC0=; b=cGI/RXePRSDKYdRs5dX4FcENy/fSJtujpz81a5jQPGzl/rciXHhhYAOafBzRGYBh9ksiXp Zo0chv/gEITXoAKM+61FrSZ4L0ZOPvH6weHfVzhDaF/RxpdE9qEa2/08ZwKLMrrqAnduUt 2ca6aD498VZEqqtndWMSNA7+TDCeMYE= X-MC-Unique: NgY7TepPO4q4pL26BmJE1g-1 From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH 6/8] qlit: qlit_type() function Date: Mon, 9 Nov 2020 16:25:54 -0500 Message-Id: <20201109212556.3934583-7-ehabkost@redhat.com> In-Reply-To: <20201109212556.3934583-1-ehabkost@redhat.com> References: <20201109212556.3934583-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ehabkost@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=ehabkost@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/09 01:25:23 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Useful function where we need to check for the qlit type before converting it to an actual QObject. Signed-off-by: Eduardo Habkost Acked-by: Paolo Bonzini --- include/qapi/qmp/qlit.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h index f9e356d31e..acddb80831 100644 --- a/include/qapi/qmp/qlit.h +++ b/include/qapi/qmp/qlit.h @@ -59,4 +59,9 @@ bool qlit_equal_qobject(const QLitObject *lhs, const QObj= ect *rhs); =20 QObject *qobject_from_qlit(const QLitObject *qlit); =20 +static inline QType qlit_type(const QLitObject *qlit) +{ + return qlit->type; +} + #endif /* QLIT_H */ --=20 2.28.0 From nobody Fri May 3 20:42:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1604957723; cv=none; d=zohomail.com; s=zohoarc; b=B3StykvsUUWD58mvCsdkeXXzrvUjL9/9pAAb07duqAoiDmQ7slt13JDWJmye6x40MK6dtK0YALSrkxqk0Cjgir2bsZm08IhU7ASWxswo2alDNH/BWH7bbUnkE8FKloINoCDXg1WoDQEfRirAjDmEbNikcCbN9Fu5yJChXiGpASY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604957723; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=R8K+X+Bhbl48vXNduSDuwR4SqZX1cMu+hzqYgTV7pDc=; b=iqo7Q3VXDckqRDfHXfOy4Ul29m1L4SsZF3qtLrDlbNRVDOLhdRv9WsF77DdYXGvMO5hxsn3iFlC22EtXztN4UMzisTPERonFuH3IGE85TuWhgWajvhu4lyaI7NH75IdQ3YbSnpSXuK/7OjHxPTn0iLyIrx8WOh/v1Xx4qF2WNpo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 160495772317745.42353704200855; Mon, 9 Nov 2020 13:35:23 -0800 (PST) Received: from localhost ([::1]:41578 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcEos-0004OB-3A for importer@patchew.org; Mon, 09 Nov 2020 16:35:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33718) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcEgD-00049B-AY for qemu-devel@nongnu.org; Mon, 09 Nov 2020 16:26:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:41435) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kcEgA-0005d6-M1 for qemu-devel@nongnu.org; Mon, 09 Nov 2020 16:26:24 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-28-HM_aGxYsPV6QNELoi_6leA-1; Mon, 09 Nov 2020 16:26:12 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4AC858030CE for ; Mon, 9 Nov 2020 21:26:11 +0000 (UTC) Received: from localhost (ovpn-114-68.rdu2.redhat.com [10.10.114.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0BD3B5C639; Mon, 9 Nov 2020 21:26:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604957181; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R8K+X+Bhbl48vXNduSDuwR4SqZX1cMu+hzqYgTV7pDc=; b=d4lHxRbejLs2lbeg5nN4GinYLDeX4MMDgP0DYC4ZFkIyZyfNnuq7aGDnGdWkl6xeR5kAnc 6gVNT82WuKX90YVWx70+HixoeEji4iixICwXVPK8S5ll4fzLTDCHaUq1H6vqToTFPFD6Ju J0JGz1R2+z8XQMLsw4h0lBcYi/metL4= X-MC-Unique: HM_aGxYsPV6QNELoi_6leA-1 From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH 7/8] qom: Make object_property_set_default() public Date: Mon, 9 Nov 2020 16:25:55 -0500 Message-Id: <20201109212556.3934583-8-ehabkost@redhat.com> In-Reply-To: <20201109212556.3934583-1-ehabkost@redhat.com> References: <20201109212556.3934583-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ehabkost@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=ehabkost@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/09 01:25:23 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The function will be used outside qom/object.c, to simplify the field property code that sets the property default value. Signed-off-by: Eduardo Habkost Acked-by: Paolo Bonzini --- include/qom/object.h | 11 +++++++++++ qom/object.c | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/qom/object.h b/include/qom/object.h index 2ab124b8f0..4234cc9b66 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1090,6 +1090,17 @@ ObjectProperty *object_class_property_add(ObjectClas= s *klass, const char *name, ObjectPropertyRelease *release, void *opaque); =20 +/** + * object_property_set_default: + * @prop: the property to set + * @value: the value to be written to the property + * + * Set the property default value. + * + * Ownership of @value is transferred to the property. + */ +void object_property_set_default(ObjectProperty *prop, QObject *value); + /** * object_property_set_default_bool: * @prop: the property to set diff --git a/qom/object.c b/qom/object.c index 7c11bcd3b1..6b0d9d8c79 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1547,7 +1547,7 @@ static void object_property_init_defval(Object *obj, = ObjectProperty *prop) visit_free(v); } =20 -static void object_property_set_default(ObjectProperty *prop, QObject *def= val) +void object_property_set_default(ObjectProperty *prop, QObject *defval) { assert(!prop->defval); assert(!prop->init); --=20 2.28.0 From nobody Fri May 3 20:42:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1604957708; cv=none; d=zohomail.com; s=zohoarc; b=L7aeuj8TPNSmRFHcGXz3rmMf02BcOWVytnLS3C75ugNx0mCqq0B8O/V/lBoEKgTVOXxs6EmIm1STgoF2RysSx6Or2UwmlTrryp+ghdn35jiK1TlIn0X8R5NwOl1CEFra3qnrICaAZFkZmgZqcOVOUdZIjp9rMtOc0rYMxJfynCc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604957708; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HNZ23P3owjXbOa0F7aY0nEo1VFpb+WZS7l4fYOJpfss=; b=GAA6qFIqr9zM49yLmU1QysnM2yO4/16N/Sh3fAuuMIu99Im4Dpm/T3BpL0Gh4tgS82fxgv1LkY93qJuZtlL4l5oOsysJZc/L6YN1n2QDG3HTI0lbI6L9gkHuSUh/EPtGWwqs4mwIPXFt50skRRHy+Iq3xyB3N8zrTJ8jC8MakQE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604957708616464.391367248257; Mon, 9 Nov 2020 13:35:08 -0800 (PST) Received: from localhost ([::1]:40564 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcEod-0003wj-5f for importer@patchew.org; Mon, 09 Nov 2020 16:35:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33704) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcEg7-00041t-Oy for qemu-devel@nongnu.org; Mon, 09 Nov 2020 16:26:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:22699) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kcEg5-0005cl-1e for qemu-devel@nongnu.org; Mon, 09 Nov 2020 16:26:19 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-152-l2vnL5qpMxaYh-KnK_MLPQ-1; Mon, 09 Nov 2020 16:26:13 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C1913879517 for ; Mon, 9 Nov 2020 21:26:12 +0000 (UTC) Received: from localhost (ovpn-114-68.rdu2.redhat.com [10.10.114.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E13060BF1; Mon, 9 Nov 2020 21:26:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604957176; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HNZ23P3owjXbOa0F7aY0nEo1VFpb+WZS7l4fYOJpfss=; b=gcd9trn+DL2TsdLGMjpCikyZk8LdmLb4LdRfWJRcATgahLvjLeUAF8IUZG5F+rU3ZHMzEs f4GEw7N+8wlwkknWcp5Xz+KdUdsBy/enMjNya5Ms9M/o+uU9CzozzUuV9pYE8P86I1BTWb fjwysqJmd5W27YmMMr0C7AkXQo1sDrI= X-MC-Unique: l2vnL5qpMxaYh-KnK_MLPQ-1 From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH 8/8] qom: Use qlit to represent property defaults Date: Mon, 9 Nov 2020 16:25:56 -0500 Message-Id: <20201109212556.3934583-9-ehabkost@redhat.com> In-Reply-To: <20201109212556.3934583-1-ehabkost@redhat.com> References: <20201109212556.3934583-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ehabkost@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=ehabkost@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/09 01:25:23 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Using QLitObject lets us get rid of most of the .set_default_value functions, and just use object_property_set_default() directly. Signed-off-by: Eduardo Habkost Acked-by: Paolo Bonzini --- include/hw/qdev-properties-system.h | 2 +- include/qom/field-property-internal.h | 4 --- include/qom/field-property.h | 26 ++++++++----------- include/qom/property-types.h | 21 +++++++--------- hw/core/qdev-properties-system.c | 8 ------ qom/field-property.c | 27 ++++++++++++++------ qom/property-types.c | 36 ++++----------------------- 7 files changed, 44 insertions(+), 80 deletions(-) diff --git a/include/hw/qdev-properties-system.h b/include/hw/qdev-properti= es-system.h index 0ac327ae60..a586424a33 100644 --- a/include/hw/qdev-properties-system.h +++ b/include/hw/qdev-properties-system.h @@ -65,7 +65,7 @@ extern const PropertyInfo qdev_prop_pcie_link_width; =20 #define DEFINE_PROP_UUID(_name, _state, _field) \ DEFINE_PROP(_name, _state, _field, qdev_prop_uuid, QemuUUID, \ - .set_default =3D true) + .defval =3D QLIT_QSTR("auto")) =20 #define DEFINE_PROP_AUDIODEV(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_audiodev, QEMUSoundCard) diff --git a/include/qom/field-property-internal.h b/include/qom/field-prop= erty-internal.h index 7aa27ce836..09877d9d6f 100644 --- a/include/qom/field-property-internal.h +++ b/include/qom/field-property-internal.h @@ -15,10 +15,6 @@ void field_prop_set_enum(Object *obj, Visitor *v, const = char *name, =20 void field_prop_set_default_value_enum(ObjectProperty *op, const Property *prop); -void field_prop_set_default_value_int(ObjectProperty *op, - const Property *prop); -void field_prop_set_default_value_uint(ObjectProperty *op, - const Property *prop); =20 void field_prop_get_int32(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp); diff --git a/include/qom/field-property.h b/include/qom/field-property.h index bc866e1c93..b83b424a5e 100644 --- a/include/qom/field-property.h +++ b/include/qom/field-property.h @@ -6,6 +6,7 @@ =20 #include "qom/object.h" #include "qapi/util.h" +#include "qapi/qmp/qlit.h" =20 /** * struct Property: definition of a field property @@ -29,21 +30,8 @@ struct Property { const PropertyInfo *info; ptrdiff_t offset; uint8_t bitnr; - /** - * @set_default: true if the default value should be set from @defval, - * in which case @info->set_default_value must not be NULL - * (if false then no default value is set by the property system - * and the field retains whatever value it was given by instance_i= nit). - */ - bool set_default; - /** - * @defval: default value for the property. This is used only if @set_= default - * is true. - */ - union { - int64_t i; - uint64_t u; - } defval; + /** @defval: If not QNull, the default value for the property */ + QLitObject defval; /* private: */ int arrayoffset; const PropertyInfo *arrayinfo; @@ -63,7 +51,13 @@ struct PropertyInfo { const QEnumLookup *enum_table; /** @print: String formatting function, for the human monitor */ int (*print)(Object *obj, Property *prop, char *dest, size_t len); - /** @set_default_value: Callback for initializing the default value */ + /** + * @set_default_value: Optional callback for initializing the default = value + * + * Most property types don't need to set this, as by default + * object_property_set_default() is called with the value at + * Property.defval. + */ void (*set_default_value)(ObjectProperty *op, const Property *prop); /** @create: Optional callback for creation of property */ ObjectProperty *(*create)(ObjectClass *oc, const char *name, diff --git a/include/qom/property-types.h b/include/qom/property-types.h index 3a36e1fec5..36ca6f9e55 100644 --- a/include/qom/property-types.h +++ b/include/qom/property-types.h @@ -5,6 +5,7 @@ #define QOM_PROPERTY_TYPES_H =20 #include "qom/field-property.h" +#include "qapi/qmp/qlit.h" =20 extern const PropertyInfo prop_info_bit; extern const PropertyInfo prop_info_bit64; @@ -28,13 +29,14 @@ extern const PropertyInfo prop_info_link; .info =3D &(_prop), \ .offset =3D offsetof(_state, _field) \ + type_check(_type, typeof_field(_state, _field)), \ + .defval =3D QLIT_QNULL, \ + /* Note that __VA_ARGS__ can still override .defval */ \ __VA_ARGS__ \ } =20 #define DEFINE_PROP_SIGNED(_name, _state, _field, _defval, _prop, _type) \ DEFINE_PROP(_name, _state, _field, _prop, _type, \ - .set_default =3D true, = \ - .defval.i =3D (_type)_defval) + .defval =3D QLIT_QNUM_INT(_defval)) =20 #define DEFINE_PROP_SIGNED_NODEFAULT(_name, _state, _field, _prop, _type) \ DEFINE_PROP(_name, _state, _field, _prop, _type) @@ -50,13 +52,11 @@ extern const PropertyInfo prop_info_link; #define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) \ DEFINE_PROP(_name, _state, _field, prop_info_bit, uint32_t, \ .bitnr =3D (_bit), \ - .set_default =3D true, \ - .defval.u =3D (bool)_defval) + .defval =3D QLIT_QBOOL(_defval)) =20 #define DEFINE_PROP_UNSIGNED(_name, _state, _field, _defval, _prop, _type)= \ DEFINE_PROP(_name, _state, _field, _prop, _type, = \ - .set_default =3D true, = \ - .defval.u =3D (_type)_defval) + .defval =3D QLIT_QNUM_UINT(_defval)) =20 #define DEFINE_PROP_UNSIGNED_NODEFAULT(_name, _state, _field, _prop, _type= ) \ DEFINE_PROP(_name, _state, _field, _prop, _type) @@ -72,8 +72,7 @@ extern const PropertyInfo prop_info_link; #define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval) \ DEFINE_PROP(_name, _state, _field, prop_info_bit64, uint64_t, \ .bitnr =3D (_bit), \ - .set_default =3D true, \ - .defval.u =3D (bool)_defval) + .defval =3D QLIT_QBOOL(_defval)) =20 /** * DEFINE_PROP_BOOL: @@ -84,8 +83,7 @@ extern const PropertyInfo prop_info_link; */ #define DEFINE_PROP_BOOL(_name, _state, _field, _defval) \ DEFINE_PROP(_name, _state, _field, prop_info_bool, bool, \ - .set_default =3D true, \ - .defval.u =3D (bool)_defval) + .defval =3D QLIT_QBOOL(_defval)) =20 #define PROP_ARRAY_LEN_PREFIX "len-" =20 @@ -118,8 +116,7 @@ extern const PropertyInfo prop_info_link; _arrayfield, _arrayprop, _arraytype) \ DEFINE_PROP((PROP_ARRAY_LEN_PREFIX _name), \ _state, _field, prop_info_arraylen, uint32_t, \ - .set_default =3D true, \ - .defval.u =3D 0, \ + .defval =3D QLIT_QNUM_UINT(0), \ .arrayinfo =3D &(_arrayprop), \ .arrayfieldsize =3D sizeof(_arraytype), \ .arrayoffset =3D offsetof(_state, _arrayfield)) diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-sys= tem.c index 8da68f076c..d9be5372f6 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -570,7 +570,6 @@ const PropertyInfo qdev_prop_blocksize =3D { " and " MAX_BLOCK_SIZE_STR, .get =3D field_prop_get_size32, .set =3D set_blocksize, - .set_default_value =3D field_prop_set_default_value_uint, }; =20 /* --- Block device error handling policy --- */ @@ -768,7 +767,6 @@ const PropertyInfo qdev_prop_pci_devfn =3D { .print =3D print_pci_devfn, .get =3D field_prop_get_int32, .set =3D set_pci_devfn, - .set_default_value =3D field_prop_set_default_value_int, }; =20 /* --- pci host address --- */ @@ -1080,16 +1078,10 @@ static void set_uuid(Object *obj, Visitor *v, const= char *name, void *opaque, g_free(str); } =20 -static void set_default_uuid_auto(ObjectProperty *op, const Property *prop) -{ - object_property_set_default_str(op, UUID_VALUE_AUTO); -} - const PropertyInfo qdev_prop_uuid =3D { .name =3D "str", .description =3D "UUID (aka GUID) or \"" UUID_VALUE_AUTO "\" for random value (default)", .get =3D get_uuid, .set =3D set_uuid, - .set_default_value =3D set_default_uuid_auto, }; diff --git a/qom/field-property.c b/qom/field-property.c index 25a818bb69..727d7199ae 100644 --- a/qom/field-property.c +++ b/qom/field-property.c @@ -47,6 +47,20 @@ static ObjectPropertyAccessor *field_prop_setter(const P= ropertyInfo *info) return info->set ? field_prop_set : NULL; } =20 +static void field_prop_set_default_value(ObjectProperty *op, + Property *prop) +{ + if (qlit_type(&prop->defval) =3D=3D QTYPE_QNULL) { + return; + } + + if (prop->info->set_default_value) { + prop->info->set_default_value(op, prop); + } else { + object_property_set_default(op, qobject_from_qlit(&prop->defval)); + } +} + ObjectProperty * object_property_add_field(Object *obj, const char *name, Property *prop, ObjectPropertyAllowSet allow_set) @@ -65,11 +79,9 @@ object_property_add_field(Object *obj, const char *name,= Property *prop, object_property_set_description(obj, name, prop->info->description); =20 - if (prop->set_default) { - prop->info->set_default_value(op, prop); - if (op->init) { - op->init(obj, op); - } + field_prop_set_default_value(op, prop); + if (op->init) { + op->init(obj, op); } =20 op->allow_set =3D allow_set; @@ -95,9 +107,8 @@ object_class_property_add_field(ObjectClass *oc, const c= har *name, prop->info->release, prop); } - if (prop->set_default) { - prop->info->set_default_value(op, prop); - } + + field_prop_set_default_value(op, prop); if (prop->info->description) { object_class_property_set_description(oc, name, prop->info->description); diff --git a/qom/property-types.c b/qom/property-types.c index f566c05ec2..8bed83c712 100644 --- a/qom/property-types.c +++ b/qom/property-types.c @@ -28,8 +28,11 @@ void field_prop_set_enum(Object *obj, Visitor *v, const = char *name, void field_prop_set_default_value_enum(ObjectProperty *op, const Property *prop) { - object_property_set_default_str(op, - qapi_enum_lookup(prop->info->enum_table, prop->defval.i)); + QObject *defval =3D qobject_from_qlit(&prop->defval); + const char *str =3D qapi_enum_lookup(prop->info->enum_table, + qnum_get_int(qobject_to(QNum, defva= l))); + object_property_set_default_str(op, str); + qobject_unref(defval); } =20 const PropertyInfo prop_info_enum =3D { @@ -80,17 +83,11 @@ static void prop_set_bit(Object *obj, Visitor *v, const= char *name, bit_prop_set(obj, prop, value); } =20 -static void set_default_value_bool(ObjectProperty *op, const Property *pro= p) -{ - object_property_set_default_bool(op, prop->defval.u); -} - const PropertyInfo prop_info_bit =3D { .name =3D "bool", .description =3D "on/off", .get =3D prop_get_bit, .set =3D prop_set_bit, - .set_default_value =3D set_default_value_bool, }; =20 /* Bit64 */ @@ -139,7 +136,6 @@ const PropertyInfo prop_info_bit64 =3D { .description =3D "on/off", .get =3D prop_get_bit64, .set =3D prop_set_bit64, - .set_default_value =3D set_default_value_bool, }; =20 /* --- bool --- */ @@ -166,7 +162,6 @@ const PropertyInfo prop_info_bool =3D { .name =3D "bool", .get =3D get_bool, .set =3D set_bool, - .set_default_value =3D set_default_value_bool, }; =20 /* --- 8bit integer --- */ @@ -189,23 +184,10 @@ static void set_uint8(Object *obj, Visitor *v, const = char *name, void *opaque, visit_type_uint8(v, name, ptr, errp); } =20 -void field_prop_set_default_value_int(ObjectProperty *op, - const Property *prop) -{ - object_property_set_default_int(op, prop->defval.i); -} - -void field_prop_set_default_value_uint(ObjectProperty *op, - const Property *prop) -{ - object_property_set_default_uint(op, prop->defval.u); -} - const PropertyInfo prop_info_uint8 =3D { .name =3D "uint8", .get =3D get_uint8, .set =3D set_uint8, - .set_default_value =3D field_prop_set_default_value_uint, }; =20 /* --- 16bit integer --- */ @@ -232,7 +214,6 @@ const PropertyInfo prop_info_uint16 =3D { .name =3D "uint16", .get =3D get_uint16, .set =3D set_uint16, - .set_default_value =3D field_prop_set_default_value_uint, }; =20 /* --- 32bit integer --- */ @@ -277,14 +258,12 @@ const PropertyInfo prop_info_uint32 =3D { .name =3D "uint32", .get =3D get_uint32, .set =3D set_uint32, - .set_default_value =3D field_prop_set_default_value_uint, }; =20 const PropertyInfo prop_info_int32 =3D { .name =3D "int32", .get =3D field_prop_get_int32, .set =3D set_int32, - .set_default_value =3D field_prop_set_default_value_int, }; =20 /* --- 64bit integer --- */ @@ -329,14 +308,12 @@ const PropertyInfo prop_info_uint64 =3D { .name =3D "uint64", .get =3D get_uint64, .set =3D set_uint64, - .set_default_value =3D field_prop_set_default_value_uint, }; =20 const PropertyInfo prop_info_int64 =3D { .name =3D "int64", .get =3D get_int64, .set =3D set_int64, - .set_default_value =3D field_prop_set_default_value_int, }; =20 /* --- string --- */ @@ -431,7 +408,6 @@ const PropertyInfo prop_info_size32 =3D { .name =3D "size", .get =3D field_prop_get_size32, .set =3D set_size32, - .set_default_value =3D field_prop_set_default_value_uint, }; =20 /* --- support for array properties --- */ @@ -494,7 +470,6 @@ const PropertyInfo prop_info_arraylen =3D { .name =3D "uint32", .get =3D get_uint32, .set =3D set_prop_arraylen, - .set_default_value =3D field_prop_set_default_value_uint, }; =20 /* --- 64bit unsigned int 'size' type --- */ @@ -521,7 +496,6 @@ const PropertyInfo prop_info_size =3D { .name =3D "size", .get =3D get_size, .set =3D set_size, - .set_default_value =3D field_prop_set_default_value_uint, }; =20 /* --- object link property --- */ --=20 2.28.0