From patchwork Mon Nov 16 22:41:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 11910977 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E3A266C1 for ; Mon, 16 Nov 2020 22:43:09 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 636FC22453 for ; Mon, 16 Nov 2020 22:43:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gx6rPNVY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 636FC22453 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:33134 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kenDH-0005gI-V5 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 16 Nov 2020 17:43:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43392) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kenC5-00040T-IN for qemu-devel@nongnu.org; Mon, 16 Nov 2020 17:41:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:59794) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kenC2-0000FX-Qj for qemu-devel@nongnu.org; Mon, 16 Nov 2020 17:41:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605566509; 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=wsiGzDYBj2i0KulZ0Jy/OhKdvQbURjbNu9rOWZ7s3OM=; b=gx6rPNVYErKwXjeabhMqaH24Srpxh80ZwbXHzXdlk/z0kn3SGGPQ8wII15Imod2S8Wkc2Z Zrb/Kab+LExNURWSYlrG8uRxfDxnk6BLbDt6AZ8TIysn5dD50FiB2PxVH9ZYRSoWN1alKq j94hyEpEUo1ZpT2nXZOL8PKIXdlQQSE= 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-518-3n7DIbidPmuxt7mqF6-XFQ-1; Mon, 16 Nov 2020 17:41:47 -0500 X-MC-Unique: 3n7DIbidPmuxt7mqF6-XFQ-1 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 B7E9D1015EA2 for ; Mon, 16 Nov 2020 22:41:46 +0000 (UTC) Received: from localhost (ovpn-115-101.rdu2.redhat.com [10.10.115.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id 63D4E5D707; Mon, 16 Nov 2020 22:41:46 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH v2 1/8] qobject: Include API docs in docs/devel/qobject.html Date: Mon, 16 Nov 2020 17:41:36 -0500 Message-Id: <20201116224143.1284278-2-ehabkost@redhat.com> In-Reply-To: <20201116224143.1284278-1-ehabkost@redhat.com> References: <20201116224143.1284278-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 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/16 04:46:27 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_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Markus Armbruster Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Render existing doc comments at docs/devel/qobject.html. Signed-off-by: Eduardo Habkost Reviewed-by: Marc-André Lureau --- 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 f10ed77e4c..1cb39a9384 100644 --- a/docs/devel/index.rst +++ b/docs/devel/index.rst @@ -35,3 +35,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 +=========== + +.. 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; -/* +/** + * 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 later. * 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 words, - * 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) /** * 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); /** * qobject_destroy(): Free resources used by the object + * @obj: QObject pointer */ void qobject_destroy(QObject *obj); @@ -103,6 +113,7 @@ static inline void qobject_unref_impl(QObject *obj) /** * 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) /** * 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)) /** * 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) /** * 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 @@ /** * 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) /** * 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) /** * 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) /** * 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) /** * 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) } /** - * 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) /** * 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) /** * 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) /** * 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) } /** - * 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) { From patchwork Mon Nov 16 22:41:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 11910975 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DC7AEA6A for ; Mon, 16 Nov 2020 22:43:09 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 551DA2244C for ; Mon, 16 Nov 2020 22:43:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Y2OhVhMA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 551DA2244C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:33132 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kenDI-0005gF-3G for patchwork-qemu-devel@patchwork.kernel.org; Mon, 16 Nov 2020 17:43:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43418) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kenC6-00040i-KM for qemu-devel@nongnu.org; Mon, 16 Nov 2020 17:41:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:56678) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kenC3-0000Fu-RO for qemu-devel@nongnu.org; Mon, 16 Nov 2020 17:41:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605566511; 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=Y2OhVhMAuAa+LQqqvULIQG6MPohh63RSTr07ws7lZLL4tpmQcyBwvBLNf4OqrQ5n+tMBal cLscoVNRBUOBhcpYXKmmFbsfHyrng+0uKqtXDa5oK2ddnkiHPRUTu2RkSZDnzCQROU2vD7 RgYG45ORO2TatWLYh3sMfRBqJVZ+2Js= 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-559-4jkK7c_IM5qn0gZGytVzFQ-1; Mon, 16 Nov 2020 17:41:49 -0500 X-MC-Unique: 4jkK7c_IM5qn0gZGytVzFQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9528F80B736 for ; Mon, 16 Nov 2020 22:41:48 +0000 (UTC) Received: from localhost (ovpn-115-101.rdu2.redhat.com [10.10.115.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id 29AE710013D7; Mon, 16 Nov 2020 22:41:47 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH v2 2/8] qnum: Make qnum_get_double() get const pointer Date: Mon, 16 Nov 2020 17:41:37 -0500 Message-Id: <20201116224143.1284278-3-ehabkost@redhat.com> In-Reply-To: <20201116224143.1284278-1-ehabkost@redhat.com> References: <20201116224143.1284278-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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 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/15 22:35:17 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_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Markus Armbruster Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" qnum_get_double() won't change the object, the argument can be const. Signed-off-by: Eduardo Habkost Reviewed-by: Marc-André Lureau --- 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); -double qnum_get_double(QNum *qn); +double qnum_get_double(const QNum *qn); char *qnum_to_string(QNum *qn); 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: From patchwork Mon Nov 16 22:41:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 11910981 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6F4C2A6A for ; Mon, 16 Nov 2020 22:43:33 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DA8AD2244C for ; Mon, 16 Nov 2020 22:43:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ePR11ZLe" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DA8AD2244C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:33358 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kenDf-0005lc-UR for patchwork-qemu-devel@patchwork.kernel.org; Mon, 16 Nov 2020 17:43:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43430) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kenC7-000417-EX for qemu-devel@nongnu.org; Mon, 16 Nov 2020 17:41:55 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:56697) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kenC5-0000GF-Ds for qemu-devel@nongnu.org; Mon, 16 Nov 2020 17:41:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605566512; 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=IEEaYYsnt6cwYZQTB2AHarcuCC3pyGUKzEmmKsNwJzA=; b=ePR11ZLeKeOlpOoWGY1dfrExVfkz6t/cJ0EhSPrqTGNV60mJUMvp1d5mm0EKiivcvb/Jtg DIn8ZebeyHle/wpKCDl20IzqI1Rb/1A2xo/PXu2ONaX8DP4Yt+hpUCktQrC9TtXJNFjAZ9 5HtPm7zdJYhQ+NmINKkkjGKFdbfoPMs= 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-46-81VryynnMCy4jklhD7RdtA-1; Mon, 16 Nov 2020 17:41:50 -0500 X-MC-Unique: 81VryynnMCy4jklhD7RdtA-1 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 CCB226D58A for ; Mon, 16 Nov 2020 22:41:49 +0000 (UTC) Received: from localhost (ovpn-115-101.rdu2.redhat.com [10.10.115.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9060760C04; Mon, 16 Nov 2020 22:41:49 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH v2 3/8] qnum: QNumValue type for QNum value literals Date: Mon, 16 Nov 2020 17:41:38 -0500 Message-Id: <20201116224143.1284278-4-ehabkost@redhat.com> In-Reply-To: <20201116224143.1284278-1-ehabkost@redhat.com> References: <20201116224143.1284278-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 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/16 04:46:27 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_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Markus Armbruster Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- Changes v1 -> v2: * Fix "make check" failure, by updating check-qnum unit test to use the new struct fields --- include/qapi/qmp/qnum.h | 40 +++++++++++++++++++-- qobject/qnum.c | 78 ++++++++++++++++++++--------------------- tests/check-qnum.c | 14 ++++---- 3 files changed, 84 insertions(+), 48 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 = QNUM_I64, .u.i64 = value } +#define QNUM_VAL_UINT(value) \ + { .kind = QNUM_U64, .u.u64 = value } +#define QNUM_VAL_DOUBLE(value) \ + { .kind = QNUM_DOUBLE, .u.dbl = value } + +struct QNum { + struct QObjectBase_ base; + QNumValue value; }; +/** + * 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); +/** + * 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); 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" +QNum *qnum_from_value(QNumValue value) +{ + QNum *qn = g_new(QNum, 1); + + qobject_init(QOBJECT(qn), QTYPE_QNUM); + qn->value = 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 = g_new(QNum, 1); - - qobject_init(QOBJECT(qn), QTYPE_QNUM); - qn->kind = QNUM_I64; - qn->u.i64 = value; - - return qn; + return qnum_from_value((QNumValue) QNUM_VAL_INT(value)); } /** @@ -40,13 +43,7 @@ QNum *qnum_from_int(int64_t value) */ QNum *qnum_from_uint(uint64_t value) { - QNum *qn = g_new(QNum, 1); - - qobject_init(QOBJECT(qn), QTYPE_QNUM); - qn->kind = QNUM_U64; - qn->u.u64 = value; - - return qn; + return qnum_from_value((QNumValue) QNUM_VAL_UINT(value)); } /** @@ -57,13 +54,7 @@ QNum *qnum_from_uint(uint64_t value) */ QNum *qnum_from_double(double value) { - QNum *qn = g_new(QNum, 1); - - qobject_init(QOBJECT(qn), QTYPE_QNUM); - qn->kind = QNUM_DOUBLE; - qn->u.dbl = value; - - return qn; + return qnum_from_value((QNumValue) QNUM_VAL_DOUBLE(value)); } /** @@ -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 = &qn->value; + + switch (qv->kind) { case QNUM_I64: - *val = qn->u.i64; + *val = qv->u.i64; return true; case QNUM_U64: - if (qn->u.u64 > INT64_MAX) { + if (qv->u.u64 > INT64_MAX) { return false; } - *val = qn->u.u64; + *val = 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 = &qn->value; + + switch (qv->kind) { case QNUM_I64: - if (qn->u.i64 < 0) { + if (qv->u.i64 < 0) { return false; } - *val = qn->u.i64; + *val = qv->u.i64; return true; case QNUM_U64: - *val = qn->u.u64; + *val = 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 = &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; } assert(0); @@ -171,14 +168,15 @@ double qnum_get_double(const QNum *qn) char *qnum_to_string(QNum *qn) { + const QNumValue *qv = &qn->value; char *buffer; int len; - 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 = g_strdup_printf("%f" , qn->u.dbl); + buffer = g_strdup_printf("%f" , qv->u.dbl); len = strlen(buffer); while (len > 0 && buffer[len - 1] == '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 = qobject_to(QNum, x); - QNum *num_y = qobject_to(QNum, y); + const QNum *qnum_x = qobject_to(QNum, x); + const QNum *qnum_y = qobject_to(QNum, y); + const QNumValue *num_x = &qnum_x->value; + const QNumValue *num_y = &qnum_y->value; switch (num_x->kind) { case QNUM_I64: diff --git a/tests/check-qnum.c b/tests/check-qnum.c index 4105015872..9499b0d845 100644 --- a/tests/check-qnum.c +++ b/tests/check-qnum.c @@ -30,8 +30,8 @@ static void qnum_from_int_test(void) qn = qnum_from_int(value); g_assert(qn != NULL); - g_assert_cmpint(qn->kind, ==, QNUM_I64); - g_assert_cmpint(qn->u.i64, ==, value); + g_assert_cmpint(qn->value.kind, ==, QNUM_I64); + g_assert_cmpint(qn->value.u.i64, ==, value); g_assert_cmpint(qn->base.refcnt, ==, 1); g_assert_cmpint(qobject_type(QOBJECT(qn)), ==, QTYPE_QNUM); @@ -45,8 +45,8 @@ static void qnum_from_uint_test(void) qn = qnum_from_uint(value); g_assert(qn != NULL); - g_assert_cmpint(qn->kind, ==, QNUM_U64); - g_assert(qn->u.u64 == value); + g_assert_cmpint(qn->value.kind, ==, QNUM_U64); + g_assert(qn->value.u.u64 == value); g_assert(qn->base.refcnt == 1); g_assert(qobject_type(QOBJECT(qn)) == QTYPE_QNUM); @@ -60,8 +60,8 @@ static void qnum_from_double_test(void) qn = qnum_from_double(value); g_assert(qn != NULL); - g_assert_cmpint(qn->kind, ==, QNUM_DOUBLE); - g_assert_cmpfloat(qn->u.dbl, ==, value); + g_assert_cmpint(qn->value.kind, ==, QNUM_DOUBLE); + g_assert_cmpfloat(qn->value.u.dbl, ==, value); g_assert_cmpint(qn->base.refcnt, ==, 1); g_assert_cmpint(qobject_type(QOBJECT(qn)), ==, QTYPE_QNUM); @@ -74,7 +74,7 @@ static void qnum_from_int64_test(void) const int64_t value = 0x1234567890abcdefLL; qn = qnum_from_int(value); - g_assert_cmpint((int64_t) qn->u.i64, ==, value); + g_assert_cmpint((int64_t) qn->value.u.i64, ==, value); qobject_unref(qn); } From patchwork Mon Nov 16 22:41:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 11910979 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B202E175A for ; Mon, 16 Nov 2020 22:43:10 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5C86A2244C for ; Mon, 16 Nov 2020 22:43:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Sz2uy0ac" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5C86A2244C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:33196 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kenDI-0005hj-SJ for patchwork-qemu-devel@patchwork.kernel.org; Mon, 16 Nov 2020 17:43:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43436) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kenC8-00042X-9G for qemu-devel@nongnu.org; Mon, 16 Nov 2020 17:41:56 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:54927) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kenC6-0000GU-FU for qemu-devel@nongnu.org; Mon, 16 Nov 2020 17:41:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605566513; 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=Sz2uy0acwsjXqdKIHiomEWhGtXUCTt+6+Ua3HIynnkK+JuIX4mqVq5tlNV8wW+0wXY7Htb HwWFFgSW69ZhD3Wk4OU4lw2awLXs2pRfloNwMz73Owfbh40DZ8z0CvyMVVKA0Q9N2BbpLF WbeVwjRIF/dOcC7BfrRFoUIJCEoO7Ek= 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-583-aHcKrMxOPjivRj6ireOFIw-1; Mon, 16 Nov 2020 17:41:52 -0500 X-MC-Unique: aHcKrMxOPjivRj6ireOFIw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2DC10108E1A2 for ; Mon, 16 Nov 2020 22:41:51 +0000 (UTC) Received: from localhost (ovpn-115-101.rdu2.redhat.com [10.10.115.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id E6D0C5B4A8; Mon, 16 Nov 2020 22:41:50 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH v2 4/8] qnum: qnum_value_is_equal() function Date: Mon, 16 Nov 2020 17:41:39 -0500 Message-Id: <20201116224143.1284278-5-ehabkost@redhat.com> In-Reply-To: <20201116224143.1284278-1-ehabkost@redhat.com> References: <20201116224143.1284278-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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 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/15 22:35:17 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_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Markus Armbruster Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Extract the QNum value comparison logic to a function that takes QNumValue* as argument. Signed-off-by: Eduardo Habkost Reviewed-by: Marc-André Lureau --- 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); char *qnum_to_string(QNum *qn); +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); 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) } /** - * 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 = qobject_to(QNum, x); - const QNum *qnum_y = qobject_to(QNum, y); - const QNumValue *num_x = &qnum_x->value; - const QNumValue *num_y = &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 == num_y->u.u64; @@ -264,6 +259,20 @@ bool qnum_is_equal(const QObject *x, const QObject *y) abort(); } +/** + * 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 = qobject_to(QNum, x); + const QNum *qnum_y = 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 * From patchwork Mon Nov 16 22:41:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 11911003 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5E5C2A6A for ; Mon, 16 Nov 2020 22:48:28 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 176382244C for ; Mon, 16 Nov 2020 22:48:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="AbKmv6A2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 176382244C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:49966 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kenIR-0004Hf-2E for patchwork-qemu-devel@patchwork.kernel.org; Mon, 16 Nov 2020 17:48:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43452) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kenC9-00043d-RS for qemu-devel@nongnu.org; Mon, 16 Nov 2020 17:42:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:48560) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kenC7-0000Gj-GF for qemu-devel@nongnu.org; Mon, 16 Nov 2020 17:41:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605566514; 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=K3aLEBcDRD57P9ZHIehSKLtQFOODVi8LLUtPBiURLN4=; b=AbKmv6A2SuQOU3uk8Hpc97h4rD6Z065fBYY7TLrn2xJ10BlJs1SxoKmJz5aOAOX5kKf/su tBVE8EeGY1HntQ3sFn88ik4CnyP8CFqRSTdMozlEiQmr7W+gGxhr68g0I8Ex3mfFitu/pG larOw0qgTyNO2v94gIhC7bgM/buqbzc= 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-593-Ui79qk4pPtuxu4tcSo_7PQ-1; Mon, 16 Nov 2020 17:41:53 -0500 X-MC-Unique: Ui79qk4pPtuxu4tcSo_7PQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1B86E6D582 for ; Mon, 16 Nov 2020 22:41:52 +0000 (UTC) Received: from localhost (ovpn-115-101.rdu2.redhat.com [10.10.115.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id C526310013D7; Mon, 16 Nov 2020 22:41:51 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH v2 5/8] qlit: Support all types of QNums Date: Mon, 16 Nov 2020 17:41:40 -0500 Message-Id: <20201116224143.1284278-6-ehabkost@redhat.com> In-Reply-To: <20201116224143.1284278-1-ehabkost@redhat.com> References: <20201116224143.1284278-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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 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/15 22:35:17 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_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Markus Armbruster Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 Reviewed-by: Marc-André Lureau --- Changes v1 -> v2: * Coding style fix at qlit_equal_qobject() --- include/qapi/qmp/qlit.h | 11 +++++-- qobject/qlit.c | 5 +-- tests/check-qjson.c | 72 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 79 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 #include "qobject.h" +#include "qnum.h" 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 = QTYPE_QNULL } #define QLIT_QBOOL(val) \ { .type = QTYPE_QBOOL, .value.qbool = (val) } +#define QLIT_QNUM_INT(val) \ + { .type = QTYPE_QNUM, .value.qnum = QNUM_VAL_INT(val) } +#define QLIT_QNUM_UINT(val) \ + { .type = QTYPE_QNUM, .value.qnum = QNUM_VAL_UINT(val) } +#define QLIT_QNUM_DOUBLE(val) \ + { .type = QTYPE_QNUM, .value.qnum = QNUM_VAL_DOUBLE(val) } #define QLIT_QNUM(val) \ - { .type = QTYPE_QNUM, .value.qnum = (val) } + QLIT_QNUM_INT(val) #define QLIT_QSTR(val) \ { .type = QTYPE_QSTRING, .value.qstr = (val) } #define QLIT_QDICT(val) \ diff --git a/qobject/qlit.c b/qobject/qlit.c index be8332136c..b23cdc4532 100644 --- a/qobject/qlit.c +++ b/qobject/qlit.c @@ -71,7 +71,8 @@ bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs) case QTYPE_QBOOL: return lhs->value.qbool == qbool_get_bool(qobject_to(QBool, rhs)); case QTYPE_QNUM: - return lhs->value.qnum == qnum_get_int(qobject_to(QNum, rhs)); + return qnum_value_is_equal(&lhs->value.qnum, + qnum_get_value(qobject_to(QNum, rhs))); case QTYPE_QSTRING: return (strcmp(lhs->value.qstr, qstring_get_str(qobject_to(QString, rhs))) == 0); @@ -94,7 +95,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[] = { - { "0", 0 }, - { "1234", 1234 }, - { "1", 1 }, - { "-32", -32 }, - { "-0", 0, .skip = 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 = 1 }, { }, }; for (i = 0; test_cases[i].encoded; i++) { QNum *qnum; int64_t val; + QNum *qlit_num; + int64_t qlit_val; qnum = 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, ==, test_cases[i].decoded); + if (test_cases[i].skip == 0) { QString *str; @@ -826,9 +830,66 @@ static void simple_number(void) } qobject_unref(qnum); + + qlit_num = 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, ==, test_cases[i].decoded); + + qobject_unref(qlit_num); } } +static void qlit_large_number(void) +{ + QLitObject maxu64 = QLIT_QNUM_UINT(UINT64_MAX); + QLitObject maxi64 = QLIT_QNUM(INT64_MAX); + QLitObject mini64 = QLIT_QNUM(INT64_MIN); + QLitObject gtu64 = QLIT_QNUM_DOUBLE(18446744073709552e3); + QLitObject lti64 = QLIT_QNUM_DOUBLE(-92233720368547758e2); + QNum *qnum; + uint64_t val; + int64_t ival; + + qnum = qobject_to(QNum, qobject_from_qlit(&maxu64)); + g_assert(qnum); + g_assert_cmpuint(qnum_get_uint(qnum), ==, UINT64_MAX); + g_assert(!qnum_get_try_int(qnum, &ival)); + + qobject_unref(qnum); + + qnum = qobject_to(QNum, qobject_from_qlit(&maxi64)); + g_assert(qnum); + g_assert_cmpuint(qnum_get_uint(qnum), ==, INT64_MAX); + g_assert_cmpint(qnum_get_int(qnum), ==, INT64_MAX); + + qobject_unref(qnum); + + qnum = 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), ==, INT64_MIN); + + qobject_unref(qnum); + + qnum = qobject_to(QNum, qobject_from_qlit(>u64)); + g_assert(qnum); + g_assert_cmpfloat(qnum_get_double(qnum), ==, 18446744073709552e3); + g_assert(!qnum_get_try_uint(qnum, &val)); + g_assert(!qnum_get_try_int(qnum, &ival)); + + qobject_unref(qnum); + + qnum = qobject_to(QNum, qobject_from_qlit(<i64)); + g_assert(qnum); + g_assert_cmpfloat(qnum_get_double(qnum), ==, -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 = "18446744073709551615"; /* 2^64-1 */ @@ -1472,6 +1533,7 @@ int main(int argc, char **argv) g_test_add_func("/literals/string/utf8", utf8_string); 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); From patchwork Mon Nov 16 22:41:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 11911001 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1FABD1391 for ; Mon, 16 Nov 2020 22:48:27 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 81FB52244C for ; Mon, 16 Nov 2020 22:48:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Vn7cdri9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 81FB52244C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:49772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kenIP-0004Cs-6S for patchwork-qemu-devel@patchwork.kernel.org; Mon, 16 Nov 2020 17:48:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43472) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kenCG-00045f-Fg for qemu-devel@nongnu.org; Mon, 16 Nov 2020 17:42:07 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:38252) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kenC8-0000Gt-Rj for qemu-devel@nongnu.org; Mon, 16 Nov 2020 17:41:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605566515; 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=Vn7cdri94SFLmEApDv+HlIDPorBxajjdq2OcFD97I2Tk3pu17OOT0w2jVz/0nk03rwBNye 7KDfeijBRk8CJmujBCqb3QQZ82QH+qlpiBOP3jDH89xziz7ZBAWY3fwWE3bNWT/WYC/1zl 8eBQo5N6r4Mu2xwl+5a0DyG8XJK37/E= 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-192-x3TLHTtmMnO_UsMWOWG4Rg-1; Mon, 16 Nov 2020 17:41:54 -0500 X-MC-Unique: x3TLHTtmMnO_UsMWOWG4Rg-1 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 5F7641017DC6 for ; Mon, 16 Nov 2020 22:41:53 +0000 (UTC) Received: from localhost (ovpn-115-101.rdu2.redhat.com [10.10.115.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id 12F0119C78; Mon, 16 Nov 2020 22:41:52 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH v2 6/8] qlit: qlit_type() function Date: Mon, 16 Nov 2020 17:41:41 -0500 Message-Id: <20201116224143.1284278-7-ehabkost@redhat.com> In-Reply-To: <20201116224143.1284278-1-ehabkost@redhat.com> References: <20201116224143.1284278-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 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/16 04:46:27 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_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Markus Armbruster Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Useful function where we need to check for the qlit type before converting it to an actual QObject. Signed-off-by: Eduardo Habkost Reviewed-by: Marc-André Lureau --- 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 QObject *rhs); QObject *qobject_from_qlit(const QLitObject *qlit); +static inline QType qlit_type(const QLitObject *qlit) +{ + return qlit->type; +} + #endif /* QLIT_H */ From patchwork Mon Nov 16 22:41:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 11910983 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 24FD8A6A for ; Mon, 16 Nov 2020 22:45:20 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BE0B82244C for ; Mon, 16 Nov 2020 22:45:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="J+6Ym0/6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BE0B82244C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:41402 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kenFO-0000dq-CG for patchwork-qemu-devel@patchwork.kernel.org; Mon, 16 Nov 2020 17:45:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43478) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kenCH-00045h-3M for qemu-devel@nongnu.org; Mon, 16 Nov 2020 17:42:07 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:29471) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kenC9-0000HW-O0 for qemu-devel@nongnu.org; Mon, 16 Nov 2020 17:42:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605566517; 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=J+6Ym0/6ntZg+Tx5tsD+71pqRbqSfHJJ73pYGc84HrHSmK85Bqt2Mo/POSvkgU4hFFdk+H dNocEGqrnG0P0JtcOTdbfTXc+4Yl5KWIuAd0GUeJ4Ee4ygHpYBZte/tXc3MnnOjuSmjMWP 9hhP+5TlF6Wue7U/J2Cv5kfFOn1KxHA= 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-269-pqh9vlEfNVWgIK53MIDueQ-1; Mon, 16 Nov 2020 17:41:55 -0500 X-MC-Unique: pqh9vlEfNVWgIK53MIDueQ-1 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 AADB3188C143 for ; Mon, 16 Nov 2020 22:41:54 +0000 (UTC) Received: from localhost (ovpn-115-101.rdu2.redhat.com [10.10.115.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5DFEA6EF46; Mon, 16 Nov 2020 22:41:54 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH v2 7/8] qom: Make object_property_set_default() public Date: Mon, 16 Nov 2020 17:41:42 -0500 Message-Id: <20201116224143.1284278-8-ehabkost@redhat.com> In-Reply-To: <20201116224143.1284278-1-ehabkost@redhat.com> References: <20201116224143.1284278-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 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/15 22:35:17 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_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Markus Armbruster Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 Reviewed-by: Marc-André Lureau --- 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(ObjectClass *klass, const char *name, ObjectPropertyRelease *release, void *opaque); +/** + * 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); } -static void object_property_set_default(ObjectProperty *prop, QObject *defval) +void object_property_set_default(ObjectProperty *prop, QObject *defval) { assert(!prop->defval); assert(!prop->init); From patchwork Mon Nov 16 22:41:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 11910987 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 23BC81391 for ; Mon, 16 Nov 2020 22:45:22 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9BCC12244C for ; Mon, 16 Nov 2020 22:45:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="aRhDXu/S" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9BCC12244C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:41624 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kenFQ-0000jT-GG for patchwork-qemu-devel@patchwork.kernel.org; Mon, 16 Nov 2020 17:45:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43496) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kenCM-00046d-Au for qemu-devel@nongnu.org; Mon, 16 Nov 2020 17:42:14 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:36645) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kenCD-0000Hn-CV for qemu-devel@nongnu.org; Mon, 16 Nov 2020 17:42:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605566519; 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=FD910N55Oayo7xuw8XipPIPdyeJyyT2iTKSF0tlXpo0=; b=aRhDXu/S6JEjtVQcRu8BDGZ3r7RRNk1/sCG1LJrvSdCS4mcUikiN3lyVgEP8ScuxeZadA4 hSF75pi4J5KZpXRac+aXaYsTSR4Ev3ZSZYXVkg1vWJwuONxAfCbDKGHRfLAF/VYYqd7izz 2K7wtChNDcCiwE2nZt1SfA+gU43cMe8= 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-205-IEtSVNsHMI24nDCrQYfvgQ-1; Mon, 16 Nov 2020 17:41:57 -0500 X-MC-Unique: IEtSVNsHMI24nDCrQYfvgQ-1 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 45FE0800461 for ; Mon, 16 Nov 2020 22:41:56 +0000 (UTC) Received: from localhost (ovpn-115-101.rdu2.redhat.com [10.10.115.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7CD45C1C4; Mon, 16 Nov 2020 22:41:55 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH v2 8/8] qom: Use qlit to represent property defaults Date: Mon, 16 Nov 2020 17:41:43 -0500 Message-Id: <20201116224143.1284278-9-ehabkost@redhat.com> In-Reply-To: <20201116224143.1284278-1-ehabkost@redhat.com> References: <20201116224143.1284278-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 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/15 22:35:17 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_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Markus Armbruster Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 Reviewed-by: Marc-André Lureau --- Changes v1 -> v2: * Instead of initializing defval to QLIT_QNULL by default, just check for QTYPE_NONE, to find out if .defval was explicitly set. This avoids extra complexity at set_prop_arraylen(). --- 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 | 19 ++++++-------- hw/core/qdev-properties-system.c | 8 ------ qom/field-property.c | 27 ++++++++++++++------ qom/property-types.c | 36 ++++----------------------- 7 files changed, 42 insertions(+), 80 deletions(-) diff --git a/include/hw/qdev-properties-system.h b/include/hw/qdev-properties-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; #define DEFINE_PROP_UUID(_name, _state, _field) \ DEFINE_PROP(_name, _state, _field, qdev_prop_uuid, QemuUUID, \ - .set_default = true) + .defval = QLIT_QSTR("auto")) #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-property-internal.h index a7b7e2b69d..9bc29e9b67 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, 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); 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 0cb1fe2217..3cfd19cc14 100644 --- a/include/qom/field-property.h +++ b/include/qom/field-property.h @@ -6,6 +6,7 @@ #include "qom/object.h" #include "qapi/util.h" +#include "qapi/qmp/qlit.h" /** * struct Property: definition of a field property @@ -27,21 +28,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_init). - */ - 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 QTYPE_NONE, the default value for the property */ + QLitObject defval; /* private: */ int arrayoffset; const PropertyInfo *arrayinfo; @@ -61,7 +49,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 3132ddafd9..869d1a993a 100644 --- a/include/qom/property-types.h +++ b/include/qom/property-types.h @@ -5,6 +5,7 @@ #define QOM_PROPERTY_TYPES_H #include "qom/field-property.h" +#include "qapi/qmp/qlit.h" extern const PropertyInfo prop_info_bit; extern const PropertyInfo prop_info_bit64; @@ -25,34 +26,29 @@ extern const PropertyInfo prop_info_link; #define PROP_SIGNED(_state, _field, _defval, _prop, _type, ...) \ FIELD_PROP(_state, _field, _prop, _type, \ - .set_default = true, \ - .defval.i = (_type)_defval, \ + .defval = QLIT_QNUM_INT((_type)_defval), \ __VA_ARGS__) #define PROP_UNSIGNED(_state, _field, _defval, _prop, _type, ...) \ FIELD_PROP(_state, _field, _prop, _type, \ - .set_default = true, \ - .defval.u = (_type)_defval, \ + .defval = QLIT_QNUM_UINT((_type)_defval), \ __VA_ARGS__) #define PROP_BIT(_state, _field, _bit, _defval, ...) \ FIELD_PROP(_state, _field, prop_info_bit, uint32_t, \ .bitnr = (_bit), \ - .set_default = true, \ - .defval.u = (bool)_defval, \ + .defval = QLIT_QBOOL(_defval), \ __VA_ARGS__) #define PROP_BIT64(_state, _field, _bit, _defval, ...) \ FIELD_PROP(_state, _field, prop_info_bit64, uint64_t, \ .bitnr = (_bit), \ - .set_default = true, \ - .defval.u = (bool)_defval, \ + .defval = QLIT_QBOOL(_defval), \ __VA_ARGS__) #define PROP_BOOL(_state, _field, _defval, ...) \ FIELD_PROP(_state, _field, prop_info_bool, bool, \ - .set_default = true, \ - .defval.u = (bool)_defval, \ + .defval = QLIT_QBOOL(_defval), \ __VA_ARGS__) #define PROP_LINK(_state, _field, _type, _ptr_type, ...) \ @@ -131,8 +127,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 = true, \ - .defval.u = 0, \ + .defval = QLIT_QNUM_UINT(0), \ .arrayinfo = &(_arrayprop), \ .arrayfieldsize = sizeof(_arraytype), \ .arrayoffset = offsetof(_state, _arrayfield)) diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.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 = { " and " MAX_BLOCK_SIZE_STR, .get = field_prop_get_size32, .set = set_blocksize, - .set_default_value = field_prop_set_default_value_uint, }; /* --- Block device error handling policy --- */ @@ -768,7 +767,6 @@ const PropertyInfo qdev_prop_pci_devfn = { .print = print_pci_devfn, .get = field_prop_get_int32, .set = set_pci_devfn, - .set_default_value = field_prop_set_default_value_int, }; /* --- pci host address --- */ @@ -1080,16 +1078,10 @@ static void set_uuid(Object *obj, Visitor *v, const char *name, void *opaque, g_free(str); } -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 = { .name = "str", .description = "UUID (aka GUID) or \"" UUID_VALUE_AUTO "\" for random value (default)", .get = get_uuid, .set = set_uuid, - .set_default_value = set_default_uuid_auto, }; diff --git a/qom/field-property.c b/qom/field-property.c index cb729626ce..9cb5ded41a 100644 --- a/qom/field-property.c +++ b/qom/field-property.c @@ -47,6 +47,20 @@ static ObjectPropertyAccessor *field_prop_setter(const PropertyInfo *info) return info->set ? field_prop_set : NULL; } +static void field_prop_set_default_value(ObjectProperty *op, + Property *prop) +{ + if (qlit_type(&prop->defval) == QTYPE_NONE) { + 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)); + } +} + /* * Property release callback for dynamically-created properties: * We call the underlying element's property release hook, and @@ -83,11 +97,9 @@ object_property_add_field(Object *obj, const char *name, object_property_set_description(obj, name, newprop->info->description); - if (newprop->set_default) { - newprop->info->set_default_value(op, newprop); - if (op->init) { - op->init(obj, op); - } + field_prop_set_default_value(op, prop); + if (op->init) { + op->init(obj, op); } op->allow_set = allow_set; @@ -113,9 +125,8 @@ object_class_property_add_field_static(ObjectClass *oc, const char *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 4b3fe15b6a..fe96f1f49a 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 = qobject_from_qlit(&prop->defval); + const char *str = qapi_enum_lookup(prop->info->enum_table, + qnum_get_int(qobject_to(QNum, defval))); + object_property_set_default_str(op, str); + qobject_unref(defval); } const PropertyInfo prop_info_enum = { @@ -80,17 +83,11 @@ static void prop_set_bit(Object *obj, Visitor *v, const char *name, bit_prop_set(obj, prop, value); } -static void set_default_value_bool(ObjectProperty *op, const Property *prop) -{ - object_property_set_default_bool(op, prop->defval.u); -} - const PropertyInfo prop_info_bit = { .name = "bool", .description = "on/off", .get = prop_get_bit, .set = prop_set_bit, - .set_default_value = set_default_value_bool, }; /* Bit64 */ @@ -139,7 +136,6 @@ const PropertyInfo prop_info_bit64 = { .description = "on/off", .get = prop_get_bit64, .set = prop_set_bit64, - .set_default_value = set_default_value_bool, }; /* --- bool --- */ @@ -166,7 +162,6 @@ const PropertyInfo prop_info_bool = { .name = "bool", .get = get_bool, .set = set_bool, - .set_default_value = set_default_value_bool, }; /* --- 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); } -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 = { .name = "uint8", .get = get_uint8, .set = set_uint8, - .set_default_value = field_prop_set_default_value_uint, }; /* --- 16bit integer --- */ @@ -232,7 +214,6 @@ const PropertyInfo prop_info_uint16 = { .name = "uint16", .get = get_uint16, .set = set_uint16, - .set_default_value = field_prop_set_default_value_uint, }; /* --- 32bit integer --- */ @@ -277,14 +258,12 @@ const PropertyInfo prop_info_uint32 = { .name = "uint32", .get = get_uint32, .set = set_uint32, - .set_default_value = field_prop_set_default_value_uint, }; const PropertyInfo prop_info_int32 = { .name = "int32", .get = field_prop_get_int32, .set = set_int32, - .set_default_value = field_prop_set_default_value_int, }; /* --- 64bit integer --- */ @@ -329,14 +308,12 @@ const PropertyInfo prop_info_uint64 = { .name = "uint64", .get = get_uint64, .set = set_uint64, - .set_default_value = field_prop_set_default_value_uint, }; const PropertyInfo prop_info_int64 = { .name = "int64", .get = get_int64, .set = set_int64, - .set_default_value = field_prop_set_default_value_int, }; /* --- string --- */ @@ -431,7 +408,6 @@ const PropertyInfo prop_info_size32 = { .name = "size", .get = field_prop_get_size32, .set = set_size32, - .set_default_value = field_prop_set_default_value_uint, }; /* --- support for array properties --- */ @@ -495,7 +471,6 @@ const PropertyInfo prop_info_arraylen = { .name = "uint32", .get = get_uint32, .set = set_prop_arraylen, - .set_default_value = field_prop_set_default_value_uint, }; /* --- 64bit unsigned int 'size' type --- */ @@ -522,7 +497,6 @@ const PropertyInfo prop_info_size = { .name = "size", .get = get_size, .set = set_size, - .set_default_value = field_prop_set_default_value_uint, }; /* --- object link property --- */