From nobody Thu May 16 15:04:34 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=1608375432; cv=none; d=zohomail.com; s=zohoarc; b=lhjCx4QfpxEE4RH915ZUVdV+GKqsO3guiIDDuTV+RcK7Cb4/dPCpq45+AllSAVYREXdFrBMeO1K7waQxnx6jRptkFLBhWwMbFx29NhelatZU8/raAJt0Dn7ujyxarislQZlFSm/kibELzakV2k+/5BpeE2n94FB2rHvFW+mIQAI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608375432; 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=ftD+ab12Mnv8bQftkg2cB+Xv1xKs7O8+U/Oklx5mKro=; b=Tqq6zhXfesdGls4tLSEiBDg1crvuIs0HHaRkxZm099mKKrf9yhQ5S4IBsUP7Eq6AmVgzHsFF93HTFUrH5XP+WOi0oD8QldDTgarNBg99TeefXdWZJBI1K+eYmDIMX0r2CMHP0GZhMrmpAwOGE+klNv9pHl7LkaWWH7drPMDBZKs= 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 1608375432835830.077173557026; Sat, 19 Dec 2020 02:57:12 -0800 (PST) Received: from localhost ([::1]:41884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqZvD-0006VL-Nn for importer@patchew.org; Sat, 19 Dec 2020 05:57:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50520) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZtl-0004cR-Af for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:35559) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZti-0007Du-UN for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:40 -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-193-EIcJHGlyPl-mqmgnXIHp1Q-1; Sat, 19 Dec 2020 05:55:35 -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 0A1261005504; Sat, 19 Dec 2020 10:55:34 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B81B45191C; Sat, 19 Dec 2020 10:55:33 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 495021141D30; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375337; 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=ftD+ab12Mnv8bQftkg2cB+Xv1xKs7O8+U/Oklx5mKro=; b=SBaPvwNdDDn/F8OjqDPuQ3aPu/GxABz/N8MngegCmpkHYB5xyZZ4/M9uCNdyqenbG8bLhF FicPVZpqJ/1bAcJhpHGa0vQZfzJ+0slAmc5cyPcdKsAj9usq/3N297q9Ug/0pxR+mNisRi KNAEN7VHKvPvjfBQ1fWn6bu2MunIA1M= X-MC-Unique: EIcJHGlyPl-mqmgnXIHp1Q-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 01/33] rocker: Revamp fp_port_get_info Date: Sat, 19 Dec 2020 11:55:00 +0100 Message-Id: <20201219105532.1734134-2-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H3=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: peter.maydell@linaro.org 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" From: Eric Blake Instead of modifying the value member of a list element passed as a parameter, and open-coding the manipulation of that list, it's nicer to just return a freshly allocated value to be prepended to a list using QAPI_LIST_PREPEND. Signed-off-by: Eric Blake Message-Id: <20201113011340.463563-3-eblake@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- hw/net/rocker/rocker_fp.h | 2 +- hw/net/rocker/rocker.c | 8 +------- hw/net/rocker/rocker_fp.c | 17 ++++++++++------- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/hw/net/rocker/rocker_fp.h b/hw/net/rocker/rocker_fp.h index dbe1dd329a..7ff57aac01 100644 --- a/hw/net/rocker/rocker_fp.h +++ b/hw/net/rocker/rocker_fp.h @@ -28,7 +28,7 @@ int fp_port_eg(FpPort *port, const struct iovec *iov, int= iovcnt); =20 char *fp_port_get_name(FpPort *port); bool fp_port_get_link_up(FpPort *port); -void fp_port_get_info(FpPort *port, RockerPortList *info); +RockerPort *fp_port_get_info(FpPort *port); void fp_port_get_macaddr(FpPort *port, MACAddr *macaddr); void fp_port_set_macaddr(FpPort *port, MACAddr *macaddr); uint8_t fp_port_get_learning(FpPort *port); diff --git a/hw/net/rocker/rocker.c b/hw/net/rocker/rocker.c index 1af1e6fa2f..c53a02315e 100644 --- a/hw/net/rocker/rocker.c +++ b/hw/net/rocker/rocker.c @@ -127,13 +127,7 @@ RockerPortList *qmp_query_rocker_ports(const char *nam= e, Error **errp) } =20 for (i =3D r->fp_ports - 1; i >=3D 0; i--) { - RockerPortList *info =3D g_malloc0(sizeof(*info)); - info->value =3D g_malloc0(sizeof(*info->value)); - struct fp_port *port =3D r->fp_port[i]; - - fp_port_get_info(port, info); - info->next =3D list; - list =3D info; + QAPI_LIST_PREPEND(list, fp_port_get_info(r->fp_port[i])); } =20 return list; diff --git a/hw/net/rocker/rocker_fp.c b/hw/net/rocker/rocker_fp.c index 4aa7da79b8..cbeed65bd5 100644 --- a/hw/net/rocker/rocker_fp.c +++ b/hw/net/rocker/rocker_fp.c @@ -51,14 +51,17 @@ bool fp_port_get_link_up(FpPort *port) return !qemu_get_queue(port->nic)->link_down; } =20 -void fp_port_get_info(FpPort *port, RockerPortList *info) +RockerPort *fp_port_get_info(FpPort *port) { - info->value->name =3D g_strdup(port->name); - info->value->enabled =3D port->enabled; - info->value->link_up =3D fp_port_get_link_up(port); - info->value->speed =3D port->speed; - info->value->duplex =3D port->duplex; - info->value->autoneg =3D port->autoneg; + RockerPort *value =3D g_malloc0(sizeof(*value)); + + value->name =3D g_strdup(port->name); + value->enabled =3D port->enabled; + value->link_up =3D fp_port_get_link_up(port); + value->speed =3D port->speed; + value->duplex =3D port->duplex; + value->autoneg =3D port->autoneg; + return value; } =20 void fp_port_get_macaddr(FpPort *port, MACAddr *macaddr) --=20 2.26.2 From nobody Thu May 16 15:04:34 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=1608375933; cv=none; d=zohomail.com; s=zohoarc; b=Xp/GpwqyUsW5McGTlD1i90WDFqeoW8lUq0vIHcoyZobm3B3Jnz7h7o7T7a9mRCmMjQTPZBKnuCBciTxME6LUVtweQudgVvCFE7tyN5dFaJTGvdjSbypXNma1WSjN0WIQPdFfbLu01jHo10GXkw2+GyRGSdkLGoterCB3PUu6o8Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608375933; 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=Ig0zE5llWu6s4iWlo9lQbO/vom8IbDvTtRmRvkVQrQQ=; b=LMHa47c+dZVyUrLMRacr83hUBFTL3u1KVu2e+XsNNA+Lj4WKN88O57YrfGwbDwZXDxxGPfAIKheiZ+gb+WETJ3oToZjNo02qS9MwWD5LNtNNwIKyqpNktHIo+zUeWp1LyvrKOXaLwW7Si7gey1eR9V6ou8A2CTYGjC5fye2L9GM= 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 1608375933267484.11755388662266; Sat, 19 Dec 2020 03:05:33 -0800 (PST) Received: from localhost ([::1]:39268 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqa3E-0000Dl-Uy for importer@patchew.org; Sat, 19 Dec 2020 06:05:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50680) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZtq-0004kI-18 for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:46 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:38759) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtj-0007FI-Vs for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:45 -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-193-aP8dOV3XOgKgmNwCXuMkUw-1; Sat, 19 Dec 2020 05:55:35 -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 096AB51B6; Sat, 19 Dec 2020 10:55:34 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B7F3B2BCCD; Sat, 19 Dec 2020 10:55:33 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 4D162114200A; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375339; 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=Ig0zE5llWu6s4iWlo9lQbO/vom8IbDvTtRmRvkVQrQQ=; b=e3N6sNPmImQmqzDLKvw9rNXHzoH6VoGSRMfFwcQmc4xojG3ia0cFvdrkRxC6C2ccuPqP6H zE/XynKB+S+NreVIMUSVLZKTBGvtO0X62lFG44yVbiBaBLttAKyY/ZptCxGzssl+Jr7oAj BzyJKt1eiGwTv5u2oCFkILs0IsLkfsc= X-MC-Unique: aP8dOV3XOgKgmNwCXuMkUw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 02/33] migration: Refactor migrate_cap_add Date: Sat, 19 Dec 2020 11:55:01 +0100 Message-Id: <20201219105532.1734134-3-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H3=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: peter.maydell@linaro.org 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" From: Eric Blake Instead of taking a list parameter and returning a new head at a distance, just return the new item for the caller to insert into a list via QAPI_LIST_PREPEND. Signed-off-by: Eric Blake Message-Id: <20201113011340.463563-4-eblake@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- migration/migration.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index e0dbde4091..ccf969a62e 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1654,27 +1654,23 @@ void migrate_set_state(int *state, int old_state, i= nt new_state) } } =20 -static MigrationCapabilityStatusList *migrate_cap_add( - MigrationCapabilityStatusList *list, - MigrationCapability index, - bool state) +static MigrationCapabilityStatus *migrate_cap_add(MigrationCapability inde= x, + bool state) { - MigrationCapabilityStatusList *cap; + MigrationCapabilityStatus *cap; =20 - cap =3D g_new0(MigrationCapabilityStatusList, 1); - cap->value =3D g_new0(MigrationCapabilityStatus, 1); - cap->value->capability =3D index; - cap->value->state =3D state; - cap->next =3D list; + cap =3D g_new0(MigrationCapabilityStatus, 1); + cap->capability =3D index; + cap->state =3D state; =20 return cap; } =20 void migrate_set_block_enabled(bool value, Error **errp) { - MigrationCapabilityStatusList *cap; + MigrationCapabilityStatusList *cap =3D NULL; =20 - cap =3D migrate_cap_add(NULL, MIGRATION_CAPABILITY_BLOCK, value); + QAPI_LIST_PREPEND(cap, migrate_cap_add(MIGRATION_CAPABILITY_BLOCK, val= ue)); qmp_migrate_set_capabilities(cap, errp); qapi_free_MigrationCapabilityStatusList(cap); } @@ -3863,7 +3859,7 @@ static bool migration_object_check(MigrationState *ms= , Error **errp) =20 for (i =3D 0; i < MIGRATION_CAPABILITY__MAX; i++) { if (ms->enabled_capabilities[i]) { - head =3D migrate_cap_add(head, i, true); + QAPI_LIST_PREPEND(head, migrate_cap_add(i, true)); } } =20 --=20 2.26.2 From nobody Thu May 16 15:04:34 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=1608376650; cv=none; d=zohomail.com; s=zohoarc; b=Q6aUY48bGT5RN3xA0xJIMf3iBcXVU0ccFF15tPHLyu3n5cJrIoMzYCmzxKSSHxyjer2nkC+lqIBEhh55NEO7drc41R+aMyMyfHzK4uJIqu8ReuABMw84IP613XRHYXVyByvJCRJmRVcuUvKWldUUfbVUo5PIyKARapjeasBF6/Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608376650; 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=9wOKsH2VU38NSFB0U1djpqjZYw7wAJrQDrBOGfSmmeE=; b=ZB+OfEYuGvSgSJiMccbdO6sgItgkEvTWEO71WPxZgAh10heFCO1BeOdBiqGPkrTp3kKBpdb6yhw7UylVaOSYUsi73V3u2b8XC4yA7/IN+cRhTbLvWEcYb9ZPuM/JCqbGofQk9HP8PVj3x2nNgz7ejCxkjLapIXWsPa6bSZgjJk0= 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 1608376650964386.3427361287853; Sat, 19 Dec 2020 03:17:30 -0800 (PST) Received: from localhost ([::1]:50180 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqaEr-00088X-Oz for importer@patchew.org; Sat, 19 Dec 2020 06:17:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50930) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZu6-0005XH-8v for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:56:02 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:33184) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtx-0007MU-VS for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:56:02 -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-90-zYOVnnZNOPOnPdpYh4BKPg-1; Sat, 19 Dec 2020 05:55:38 -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 A6EB1801AA5; Sat, 19 Dec 2020 10:55:37 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BAF825D9DB; Sat, 19 Dec 2020 10:55:33 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5191A114200B; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375353; 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=9wOKsH2VU38NSFB0U1djpqjZYw7wAJrQDrBOGfSmmeE=; b=XLHqADXxhu+lUheEFsowV7QMjxEBCvrlBeROjvPdLPmXccjmKM2YoOcJf/K9mxeRlmeLoF bTi8CV/CZLr1D1fTSoZ/9KByR9puH6/n8/Ybp0gm9lpufpXrKvmolBMPXrOEAIeDRsZfUm I6xqGyH9Chm2ZykKE5CLBvsFjSMnMPI= X-MC-Unique: zYOVnnZNOPOnPdpYh4BKPg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 03/33] qapi: Use QAPI_LIST_PREPEND() where possible Date: Sat, 19 Dec 2020 11:55:02 +0100 Message-Id: <20201219105532.1734134-4-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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: peter.maydell@linaro.org, Stefan Hajnoczi 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" From: Eric Blake Anywhere we create a list of just one item or by prepending items (typically because order doesn't matter), we can use QAPI_LIST_PREPEND(). But places where we must keep the list in order by appending remain open-coded until later patches. Note that as a side effect, this also performs a cleanup of two minor issues in qga/commands-posix.c: the old code was performing new =3D g_malloc0(sizeof(*ret)); which 1) is confusing because you have to verify whether 'new' and 'ret' are variables with the same type, and 2) would conflict with C++ compilation (not an actual problem for this file, but makes copy-and-paste harder). Signed-off-by: Eric Blake Message-Id: <20201113011340.463563-5-eblake@redhat.com> Reviewed-by: Markus Armbruster Acked-by: Stefan Hajnoczi [Straightforward conflicts due to commit a8aa94b5f8 "qga: update schema for guest-get-disks 'dependents' field" and commit a10b453a52 "target/mips: Move mips_cpu_add_definition() from helper.c to cpu.c" resolved. Commit message tweaked.] Signed-off-by: Markus Armbruster --- docs/devel/writing-qmp-commands.txt | 12 +-- block/gluster.c | 4 +- block/qapi.c | 7 +- chardev/char.c | 20 ++--- hw/core/machine-qmp-cmds.c | 6 +- hw/core/machine.c | 11 +-- hw/net/rocker/rocker_of_dpa.c | 20 ++--- hw/net/virtio-net.c | 21 ++---- migration/migration.c | 7 +- migration/postcopy-ram.c | 7 +- monitor/hmp-cmds.c | 13 ++-- monitor/misc.c | 25 +++--- monitor/qmp-cmds-control.c | 10 +-- qemu-img.c | 5 +- qga/commands-posix-ssh.c | 7 +- qga/commands-posix.c | 47 +++--------- qga/commands-win32.c | 32 ++------ qga/commands.c | 6 +- qom/qom-qmp-cmds.c | 29 ++----- target/arm/helper.c | 6 +- target/arm/monitor.c | 13 +--- target/i386/cpu.c | 6 +- target/mips/cpu.c | 6 +- target/s390x/cpu_models.c | 12 +-- tests/test-clone-visitor.c | 7 +- tests/test-qobject-output-visitor.c | 42 +++++------ tests/test-visitor-serialization.c | 113 ++++------------------------ trace/qmp.c | 22 +++--- ui/input.c | 16 ++-- ui/vnc.c | 21 ++---- util/qemu-config.c | 14 +--- target/ppc/translate_init.c.inc | 12 +-- 32 files changed, 158 insertions(+), 421 deletions(-) diff --git a/docs/devel/writing-qmp-commands.txt b/docs/devel/writing-qmp-c= ommands.txt index 28984686c9..258e63bff5 100644 --- a/docs/devel/writing-qmp-commands.txt +++ b/docs/devel/writing-qmp-commands.txt @@ -531,15 +531,11 @@ TimerAlarmMethodList *qmp_query_alarm_methods(Error *= *errp) bool current =3D true; =20 for (p =3D alarm_timers; p->name; p++) { - TimerAlarmMethodList *info =3D g_malloc0(sizeof(*info)); - info->value =3D g_malloc0(sizeof(*info->value)); - info->value->method_name =3D g_strdup(p->name); - info->value->current =3D current; - + TimerAlarmMethod *value =3D g_malloc0(*value); + value->method_name =3D g_strdup(p->name); + value->current =3D current; + QAPI_LIST_PREPEND(method_list, value); current =3D false; - - info->next =3D method_list; - method_list =3D info; } =20 return method_list; diff --git a/block/gluster.c b/block/gluster.c index 4f1448e2bc..1f8699b938 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -359,8 +359,8 @@ static int qemu_gluster_parse_uri(BlockdevOptionsGluste= r *gconf, return -EINVAL; } =20 - gconf->server =3D g_new0(SocketAddressList, 1); - gconf->server->value =3D gsconf =3D g_new0(SocketAddress, 1); + gsconf =3D g_new0(SocketAddress, 1); + QAPI_LIST_PREPEND(gconf->server, gsconf); =20 /* transport */ if (!uri->scheme || !strcmp(uri->scheme, "gluster")) { diff --git a/block/qapi.c b/block/qapi.c index 036da085ee..0ca206f559 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -486,12 +486,7 @@ static void bdrv_query_blk_stats(BlockDeviceStats *ds,= BlockBackend *blk) ds->account_failed =3D stats->account_failed; =20 while ((ts =3D block_acct_interval_next(stats, ts))) { - BlockDeviceTimedStatsList *timed_stats =3D - g_malloc0(sizeof(*timed_stats)); BlockDeviceTimedStats *dev_stats =3D g_malloc0(sizeof(*dev_stats)); - timed_stats->next =3D ds->timed_stats; - timed_stats->value =3D dev_stats; - ds->timed_stats =3D timed_stats; =20 TimedAverage *rd =3D &ts->latency[BLOCK_ACCT_READ]; TimedAverage *wr =3D &ts->latency[BLOCK_ACCT_WRITE]; @@ -515,6 +510,8 @@ static void bdrv_query_blk_stats(BlockDeviceStats *ds, = BlockBackend *blk) block_acct_queue_depth(ts, BLOCK_ACCT_READ); dev_stats->avg_wr_queue_depth =3D block_acct_queue_depth(ts, BLOCK_ACCT_WRITE); + + QAPI_LIST_PREPEND(ds->timed_stats, dev_stats); } =20 bdrv_latency_histogram_stats(&stats->latency_histogram[BLOCK_ACCT_READ= ], diff --git a/chardev/char.c b/chardev/char.c index a9b8c5a9aa..288efebd12 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -776,15 +776,13 @@ static int qmp_query_chardev_foreach(Object *obj, voi= d *data) { Chardev *chr =3D CHARDEV(obj); ChardevInfoList **list =3D data; - ChardevInfoList *info =3D g_malloc0(sizeof(*info)); + ChardevInfo *value =3D g_malloc0(sizeof(*value)); =20 - info->value =3D g_malloc0(sizeof(*info->value)); - info->value->label =3D g_strdup(chr->label); - info->value->filename =3D g_strdup(chr->filename); - info->value->frontend_open =3D chr->be && chr->be->fe_open; + value->label =3D g_strdup(chr->label); + value->filename =3D g_strdup(chr->filename); + value->frontend_open =3D chr->be && chr->be->fe_open; =20 - info->next =3D *list; - *list =3D info; + QAPI_LIST_PREPEND(*list, value); =20 return 0; } @@ -803,12 +801,10 @@ static void qmp_prepend_backend(const char *name, void *opaque) { ChardevBackendInfoList **list =3D opaque; - ChardevBackendInfoList *info =3D g_malloc0(sizeof(*info)); + ChardevBackendInfo *value =3D g_new0(ChardevBackendInfo, 1); =20 - info->value =3D g_malloc0(sizeof(*info->value)); - info->value->name =3D g_strdup(name); - info->next =3D *list; - *list =3D info; + value->name =3D g_strdup(name); + QAPI_LIST_PREPEND(*list, value); } =20 ChardevBackendInfoList *qmp_query_chardev_backends(Error **errp) diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c index 87f14140a3..affffe0c4a 100644 --- a/hw/core/machine-qmp-cmds.c +++ b/hw/core/machine-qmp-cmds.c @@ -215,7 +215,6 @@ MachineInfoList *qmp_query_machines(Error **errp) =20 for (el =3D machines; el; el =3D el->next) { MachineClass *mc =3D el->data; - MachineInfoList *entry; MachineInfo *info; =20 info =3D g_malloc0(sizeof(*info)); @@ -243,10 +242,7 @@ MachineInfoList *qmp_query_machines(Error **errp) info->has_default_ram_id =3D true; } =20 - entry =3D g_malloc0(sizeof(*entry)); - entry->value =3D info; - entry->next =3D mach_list; - mach_list =3D entry; + QAPI_LIST_PREPEND(mach_list, info); } =20 g_slist_free(machines); diff --git a/hw/core/machine.c b/hw/core/machine.c index 05dcaf09c9..de3b8f1b31 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -504,11 +504,7 @@ static void machine_set_nvdimm_persistence(Object *obj= , const char *value, =20 void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *= type) { - strList *item =3D g_new0(strList, 1); - - item->value =3D g_strdup(type); - item->next =3D mc->allowed_dynamic_sysbus_devices; - mc->allowed_dynamic_sysbus_devices =3D item; + QAPI_LIST_PREPEND(mc->allowed_dynamic_sysbus_devices, g_strdup(type)); } =20 static void validate_sysbus_device(SysBusDevice *sbdev, void *opaque) @@ -569,7 +565,6 @@ HotpluggableCPUList *machine_query_hotpluggable_cpus(Ma= chineState *machine) =20 for (i =3D 0; i < machine->possible_cpus->len; i++) { Object *cpu; - HotpluggableCPUList *list_item =3D g_new0(typeof(*list_item), 1); HotpluggableCPU *cpu_item =3D g_new0(typeof(*cpu_item), 1); =20 cpu_item->type =3D g_strdup(machine->possible_cpus->cpus[i].type); @@ -582,9 +577,7 @@ HotpluggableCPUList *machine_query_hotpluggable_cpus(Ma= chineState *machine) cpu_item->has_qom_path =3D true; cpu_item->qom_path =3D object_get_canonical_path(cpu); } - list_item->value =3D cpu_item; - list_item->next =3D head; - head =3D list_item; + QAPI_LIST_PREPEND(head, cpu_item); } return head; } diff --git a/hw/net/rocker/rocker_of_dpa.c b/hw/net/rocker/rocker_of_dpa.c index 8e347d1ee4..b3b8c5bb6d 100644 --- a/hw/net/rocker/rocker_of_dpa.c +++ b/hw/net/rocker/rocker_of_dpa.c @@ -2296,7 +2296,6 @@ static void of_dpa_flow_fill(void *cookie, void *valu= e, void *user_data) struct of_dpa_flow_key *key =3D &flow->key; struct of_dpa_flow_key *mask =3D &flow->mask; struct of_dpa_flow_fill_context *flow_context =3D user_data; - RockerOfDpaFlowList *new; RockerOfDpaFlow *nflow; RockerOfDpaFlowKey *nkey; RockerOfDpaFlowMask *nmask; @@ -2307,8 +2306,7 @@ static void of_dpa_flow_fill(void *cookie, void *valu= e, void *user_data) return; } =20 - new =3D g_malloc0(sizeof(*new)); - nflow =3D new->value =3D g_malloc0(sizeof(*nflow)); + nflow =3D g_malloc0(sizeof(*nflow)); nkey =3D nflow->key =3D g_malloc0(sizeof(*nkey)); nmask =3D nflow->mask =3D g_malloc0(sizeof(*nmask)); naction =3D nflow->action =3D g_malloc0(sizeof(*naction)); @@ -2424,8 +2422,7 @@ static void of_dpa_flow_fill(void *cookie, void *valu= e, void *user_data) naction->new_vlan_id =3D flow->action.apply.new_vlan_id; } =20 - new->next =3D flow_context->list; - flow_context->list =3D new; + QAPI_LIST_PREPEND(flow_context->list, nflow); } =20 RockerOfDpaFlowList *qmp_query_rocker_of_dpa_flows(const char *name, @@ -2469,9 +2466,7 @@ static void of_dpa_group_fill(void *key, void *value,= void *user_data) { struct of_dpa_group *group =3D value; struct of_dpa_group_fill_context *flow_context =3D user_data; - RockerOfDpaGroupList *new; RockerOfDpaGroup *ngroup; - struct uint32List *id; int i; =20 if (flow_context->type !=3D 9 && @@ -2479,8 +2474,7 @@ static void of_dpa_group_fill(void *key, void *value,= void *user_data) return; } =20 - new =3D g_malloc0(sizeof(*new)); - ngroup =3D new->value =3D g_malloc0(sizeof(*ngroup)); + ngroup =3D g_malloc0(sizeof(*ngroup)); =20 ngroup->id =3D group->id; =20 @@ -2525,10 +2519,7 @@ static void of_dpa_group_fill(void *key, void *value= , void *user_data) ngroup->index =3D ROCKER_GROUP_INDEX_GET(group->id); for (i =3D 0; i < group->l2_flood.group_count; i++) { ngroup->has_group_ids =3D true; - id =3D g_malloc0(sizeof(*id)); - id->value =3D group->l2_flood.group_ids[i]; - id->next =3D ngroup->group_ids; - ngroup->group_ids =3D id; + QAPI_LIST_PREPEND(ngroup->group_ids, group->l2_flood.group_ids= [i]); } break; case ROCKER_OF_DPA_GROUP_TYPE_L3_UCAST: @@ -2557,8 +2548,7 @@ static void of_dpa_group_fill(void *key, void *value,= void *user_data) break; } =20 - new->next =3D flow_context->list; - flow_context->list =3D new; + QAPI_LIST_PREPEND(flow_context->list, ngroup); } =20 RockerOfDpaGroupList *qmp_query_rocker_of_dpa_groups(const char *name, diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 044ac95f6f..8356eeec13 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -437,17 +437,14 @@ static void rxfilter_notify(NetClientState *nc) =20 static intList *get_vlan_table(VirtIONet *n) { - intList *list, *entry; + intList *list; int i, j; =20 list =3D NULL; for (i =3D 0; i < MAX_VLAN >> 5; i++) { for (j =3D 0; n->vlans[i] && j <=3D 0x1f; j++) { if (n->vlans[i] & (1U << j)) { - entry =3D g_malloc0(sizeof(*entry)); - entry->value =3D (i << 5) + j; - entry->next =3D list; - list =3D entry; + QAPI_LIST_PREPEND(list, (i << 5) + j); } } } @@ -460,7 +457,7 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetClien= tState *nc) VirtIONet *n =3D qemu_get_nic_opaque(nc); VirtIODevice *vdev =3D VIRTIO_DEVICE(n); RxFilterInfo *info; - strList *str_list, *entry; + strList *str_list; int i; =20 info =3D g_malloc0(sizeof(*info)); @@ -491,19 +488,15 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetCli= entState *nc) =20 str_list =3D NULL; for (i =3D 0; i < n->mac_table.first_multi; i++) { - entry =3D g_malloc0(sizeof(*entry)); - entry->value =3D qemu_mac_strdup_printf(n->mac_table.macs + i * ET= H_ALEN); - entry->next =3D str_list; - str_list =3D entry; + QAPI_LIST_PREPEND(str_list, + qemu_mac_strdup_printf(n->mac_table.macs + i * ETH_A= LEN)); } info->unicast_table =3D str_list; =20 str_list =3D NULL; for (i =3D n->mac_table.first_multi; i < n->mac_table.in_use; i++) { - entry =3D g_malloc0(sizeof(*entry)); - entry->value =3D qemu_mac_strdup_printf(n->mac_table.macs + i * ET= H_ALEN); - entry->next =3D str_list; - str_list =3D entry; + QAPI_LIST_PREPEND(str_list, + qemu_mac_strdup_printf(n->mac_table.macs + i * ETH_A= LEN)); } info->multicast_table =3D str_list; info->vlan_table =3D get_vlan_table(n); diff --git a/migration/migration.c b/migration/migration.c index ccf969a62e..3f4191a9c7 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -406,12 +406,9 @@ int migration_incoming_enable_colo(void) void migrate_add_address(SocketAddress *address) { MigrationIncomingState *mis =3D migration_incoming_get_current(); - SocketAddressList *addrs; =20 - addrs =3D g_new0(SocketAddressList, 1); - addrs->next =3D mis->socket_address_list; - mis->socket_address_list =3D addrs; - addrs->value =3D QAPI_CLONE(SocketAddress, address); + QAPI_LIST_PREPEND(mis->socket_address_list, + QAPI_CLONE(SocketAddress, address)); } =20 static void qemu_start_incoming_migration(const char *uri, Error **errp) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index d99842eb1b..ab482adef1 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -145,14 +145,11 @@ static struct PostcopyBlocktimeContext *blocktime_con= text_new(void) static uint32List *get_vcpu_blocktime_list(PostcopyBlocktimeContext *ctx) { MachineState *ms =3D MACHINE(qdev_get_machine()); - uint32List *list =3D NULL, *entry =3D NULL; + uint32List *list =3D NULL; int i; =20 for (i =3D ms->smp.cpus - 1; i >=3D 0; i--) { - entry =3D g_new0(uint32List, 1); - entry->value =3D ctx->vcpu_blocktime[i]; - entry->next =3D list; - list =3D entry; + QAPI_LIST_PREPEND(list, ctx->vcpu_blocktime[i]); } =20 return list; diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 65d8ff4849..73b79df7d8 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1255,7 +1255,8 @@ void hmp_migrate_set_capability(Monitor *mon, const Q= Dict *qdict) const char *cap =3D qdict_get_str(qdict, "capability"); bool state =3D qdict_get_bool(qdict, "state"); Error *err =3D NULL; - MigrationCapabilityStatusList *caps =3D g_malloc0(sizeof(*caps)); + MigrationCapabilityStatusList *caps =3D NULL; + MigrationCapabilityStatus *value; int val; =20 val =3D qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err); @@ -1263,14 +1264,14 @@ void hmp_migrate_set_capability(Monitor *mon, const= QDict *qdict) goto end; } =20 - caps->value =3D g_malloc0(sizeof(*caps->value)); - caps->value->capability =3D val; - caps->value->state =3D state; - caps->next =3D NULL; + value =3D g_malloc0(sizeof(*value)); + value->capability =3D val; + value->state =3D state; + QAPI_LIST_PREPEND(caps, value); qmp_migrate_set_capabilities(caps, &err); + qapi_free_MigrationCapabilityStatusList(caps); =20 end: - qapi_free_MigrationCapabilityStatusList(caps); hmp_handle_error(mon, err); } =20 diff --git a/monitor/misc.c b/monitor/misc.c index fde6e36a0b..f2ee7cd77a 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -1430,33 +1430,26 @@ FdsetInfoList *qmp_query_fdsets(Error **errp) =20 QEMU_LOCK_GUARD(&mon_fdsets_lock); QLIST_FOREACH(mon_fdset, &mon_fdsets, next) { - FdsetInfoList *fdset_info =3D g_malloc0(sizeof(*fdset_info)); - FdsetFdInfoList *fdsetfd_list =3D NULL; + FdsetInfo *fdset_info =3D g_malloc0(sizeof(*fdset_info)); =20 - fdset_info->value =3D g_malloc0(sizeof(*fdset_info->value)); - fdset_info->value->fdset_id =3D mon_fdset->id; + fdset_info->fdset_id =3D mon_fdset->id; =20 QLIST_FOREACH(mon_fdset_fd, &mon_fdset->fds, next) { - FdsetFdInfoList *fdsetfd_info; + FdsetFdInfo *fdsetfd_info; =20 fdsetfd_info =3D g_malloc0(sizeof(*fdsetfd_info)); - fdsetfd_info->value =3D g_malloc0(sizeof(*fdsetfd_info->value)= ); - fdsetfd_info->value->fd =3D mon_fdset_fd->fd; + fdsetfd_info->fd =3D mon_fdset_fd->fd; if (mon_fdset_fd->opaque) { - fdsetfd_info->value->has_opaque =3D true; - fdsetfd_info->value->opaque =3D g_strdup(mon_fdset_fd->opa= que); + fdsetfd_info->has_opaque =3D true; + fdsetfd_info->opaque =3D g_strdup(mon_fdset_fd->opaque); } else { - fdsetfd_info->value->has_opaque =3D false; + fdsetfd_info->has_opaque =3D false; } =20 - fdsetfd_info->next =3D fdsetfd_list; - fdsetfd_list =3D fdsetfd_info; + QAPI_LIST_PREPEND(fdset_info->fds, fdsetfd_info); } =20 - fdset_info->value->fds =3D fdsetfd_list; - - fdset_info->next =3D fdset_list; - fdset_list =3D fdset_info; + QAPI_LIST_PREPEND(fdset_list, fdset_info); } =20 return fdset_list; diff --git a/monitor/qmp-cmds-control.c b/monitor/qmp-cmds-control.c index a456762f6a..17514f4959 100644 --- a/monitor/qmp-cmds-control.c +++ b/monitor/qmp-cmds-control.c @@ -138,18 +138,18 @@ EventInfoList *qmp_query_events(Error **errp) * QAPIEvent_str() and QAPIEvent_lookup[]. When the command goes, * they should go, too. */ - EventInfoList *info, *ev_list =3D NULL; + EventInfoList *ev_list =3D NULL; QAPIEvent e; =20 for (e =3D 0 ; e < QAPI_EVENT__MAX ; e++) { const char *event_name =3D QAPIEvent_str(e); + EventInfo *info; + assert(event_name !=3D NULL); info =3D g_malloc0(sizeof(*info)); - info->value =3D g_malloc0(sizeof(*info->value)); - info->value->name =3D g_strdup(event_name); + info->name =3D g_strdup(event_name); =20 - info->next =3D ev_list; - ev_list =3D info; + QAPI_LIST_PREPEND(ev_list, info); } =20 return ev_list; diff --git a/qemu-img.c b/qemu-img.c index 8bdea40b58..d599659c7f 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1652,14 +1652,13 @@ static void do_dirty_bitmap_merge(const char *dst_n= ode, const char *dst_name, Error **errp) { BlockDirtyBitmapMergeSource *merge_src; - BlockDirtyBitmapMergeSourceList *list; + BlockDirtyBitmapMergeSourceList *list =3D NULL; =20 merge_src =3D g_new0(BlockDirtyBitmapMergeSource, 1); merge_src->type =3D QTYPE_QDICT; merge_src->u.external.node =3D g_strdup(src_node); merge_src->u.external.name =3D g_strdup(src_name); - list =3D g_new0(BlockDirtyBitmapMergeSourceList, 1); - list->value =3D merge_src; + QAPI_LIST_PREPEND(list, merge_src); qmp_block_dirty_bitmap_merge(dst_node, dst_name, list, errp); qapi_free_BlockDirtyBitmapMergeSourceList(list); } diff --git a/qga/commands-posix-ssh.c b/qga/commands-posix-ssh.c index 749167e82d..2dda136d64 100644 --- a/qga/commands-posix-ssh.c +++ b/qga/commands-posix-ssh.c @@ -293,17 +293,12 @@ qmp_guest_ssh_get_authorized_keys(const char *usernam= e, Error **errp) =20 ret =3D g_new0(GuestAuthorizedKeys, 1); for (i =3D 0; authkeys[i] !=3D NULL; i++) { - strList *new; - g_strstrip(authkeys[i]); if (!authkeys[i][0] || authkeys[i][0] =3D=3D '#') { continue; } =20 - new =3D g_new0(strList, 1); - new->value =3D g_strdup(authkeys[i]); - new->next =3D ret->keys; - ret->keys =3D new; + QAPI_LIST_PREPEND(ret->keys, g_strdup(authkeys[i])); } =20 return g_steal_pointer(&ret); diff --git a/qga/commands-posix.c b/qga/commands-posix.c index c089e38120..849923b260 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -1036,7 +1036,6 @@ static void build_guest_fsinfo_for_real_device(char c= onst *syspath, { GuestDiskAddress *disk; GuestPCIAddress *pciaddr; - GuestDiskAddressList *list =3D NULL; bool has_hwinf; #ifdef CONFIG_LIBUDEV struct udev *udev =3D NULL; @@ -1053,9 +1052,6 @@ static void build_guest_fsinfo_for_real_device(char c= onst *syspath, disk->pci_controller =3D pciaddr; disk->bus_type =3D GUEST_DISK_BUS_TYPE_UNKNOWN; =20 - list =3D g_new0(GuestDiskAddressList, 1); - list->value =3D disk; - #ifdef CONFIG_LIBUDEV udev =3D udev_new(); udevice =3D udev_device_new_from_syspath(udev, syspath); @@ -1089,10 +1085,9 @@ static void build_guest_fsinfo_for_real_device(char = const *syspath, } =20 if (has_hwinf || disk->has_dev || disk->has_serial) { - list->next =3D fs->disk; - fs->disk =3D list; + QAPI_LIST_PREPEND(fs->disk, disk); } else { - qapi_free_GuestDiskAddressList(list); + qapi_free_GuestDiskAddress(disk); } } =20 @@ -1288,7 +1283,6 @@ static void get_disk_deps(const char *disk_dir, Guest= DiskInfo *disk) disk->has_dependencies =3D true; while ((dep =3D g_dir_read_name(dp_deps)) !=3D NULL) { g_autofree char *dep_dir =3D NULL; - strList *dep_item =3D NULL; char *dev_name; =20 /* Add dependent disks */ @@ -1296,10 +1290,7 @@ static void get_disk_deps(const char *disk_dir, Gues= tDiskInfo *disk) dev_name =3D get_device_for_syspath(dep_dir); if (dev_name !=3D NULL) { g_debug(" adding dependent device: %s", dev_name); - dep_item =3D g_new0(strList, 1); - dep_item->value =3D dev_name; - dep_item->next =3D disk->dependencies; - disk->dependencies =3D dep_item; + QAPI_LIST_PREPEND(disk->dependencies, dev_name); } } g_dir_close(dp_deps); @@ -1318,7 +1309,7 @@ static GuestDiskInfoList *get_disk_partitions( const char *disk_name, const char *disk_dir, const char *disk_dev) { - GuestDiskInfoList *item, *ret =3D list; + GuestDiskInfoList *ret =3D list; struct dirent *de_disk; DIR *dp_disk =3D NULL; size_t len =3D strlen(disk_name); @@ -1352,15 +1343,9 @@ static GuestDiskInfoList *get_disk_partitions( partition->name =3D dev_name; partition->partition =3D true; /* Add parent disk as dependent for easier tracking of hierarchy */ - partition->dependencies =3D g_new0(strList, 1); - partition->dependencies->value =3D g_strdup(disk_dev); - partition->has_dependencies =3D true; - - item =3D g_new0(GuestDiskInfoList, 1); - item->value =3D partition; - item->next =3D ret; - ret =3D item; + QAPI_LIST_PREPEND(partition->dependencies, g_strdup(disk_dev)); =20 + QAPI_LIST_PREPEND(ret, partition); } closedir(dp_disk); =20 @@ -1369,7 +1354,7 @@ static GuestDiskInfoList *get_disk_partitions( =20 GuestDiskInfoList *qmp_guest_get_disks(Error **errp) { - GuestDiskInfoList *item, *ret =3D NULL; + GuestDiskInfoList *ret =3D NULL; GuestDiskInfo *disk; DIR *dp =3D NULL; struct dirent *de =3D NULL; @@ -1415,10 +1400,7 @@ GuestDiskInfoList *qmp_guest_get_disks(Error **errp) disk->partition =3D false; disk->alias =3D get_alias_for_syspath(disk_dir); disk->has_alias =3D (disk->alias !=3D NULL); - item =3D g_new0(GuestDiskInfoList, 1); - item->value =3D disk; - item->next =3D ret; - ret =3D item; + QAPI_LIST_PREPEND(ret, disk); =20 /* Get address for non-virtual devices */ bool is_virtual =3D is_disk_virtual(disk_dir, &local_err); @@ -1495,7 +1477,7 @@ GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error *= *errp) { FsMountList mounts; struct FsMount *mount; - GuestFilesystemInfoList *new, *ret =3D NULL; + GuestFilesystemInfoList *ret =3D NULL; Error *local_err =3D NULL; =20 QTAILQ_INIT(&mounts); @@ -1508,10 +1490,7 @@ GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error = **errp) QTAILQ_FOREACH(mount, &mounts, next) { g_debug("Building guest fsinfo for '%s'", mount->dirname); =20 - new =3D g_malloc0(sizeof(*ret)); - new->value =3D build_guest_fsinfo(mount, &local_err); - new->next =3D ret; - ret =3D new; + QAPI_LIST_PREPEND(ret, build_guest_fsinfo(mount, &local_err)); if (local_err) { error_propagate(errp, local_err); qapi_free_GuestFilesystemInfoList(ret); @@ -1777,7 +1756,6 @@ GuestFilesystemTrimResponse * qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp) { GuestFilesystemTrimResponse *response; - GuestFilesystemTrimResultList *list; GuestFilesystemTrimResult *result; int ret =3D 0; FsMountList mounts; @@ -1801,10 +1779,7 @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum, = Error **errp) result =3D g_malloc0(sizeof(*result)); result->path =3D g_strdup(mount->dirname); =20 - list =3D g_malloc0(sizeof(*list)); - list->value =3D result; - list->next =3D response->paths; - response->paths =3D list; + QAPI_LIST_PREPEND(response->paths, result); =20 fd =3D qemu_open_old(mount->dirname, O_RDONLY); if (fd =3D=3D -1) { diff --git a/qga/commands-win32.c b/qga/commands-win32.c index ba1fd07d06..684639bd13 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -874,7 +874,7 @@ err_close: static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **err= p) { Error *local_err =3D NULL; - GuestDiskAddressList *list =3D NULL, *cur_item =3D NULL; + GuestDiskAddressList *list =3D NULL; GuestDiskAddress *disk =3D NULL; int i; HANDLE vol_h; @@ -926,10 +926,8 @@ static GuestDiskAddressList *build_guest_disk_info(cha= r *guid, Error **errp) error_free(local_err); goto out; } - list =3D g_malloc0(sizeof(*list)); - list->value =3D disk; + QAPI_LIST_PREPEND(list, disk); disk =3D NULL; - list->next =3D NULL; goto out; } else { error_setg_win32(errp, GetLastError(), @@ -960,11 +958,8 @@ static GuestDiskAddressList *build_guest_disk_info(cha= r *guid, Error **errp) error_propagate(errp, local_err); goto out; } - cur_item =3D g_malloc0(sizeof(*list)); - cur_item->value =3D disk; + QAPI_LIST_PREPEND(list, disk); disk =3D NULL; - cur_item->next =3D list; - list =3D cur_item; } =20 =20 @@ -982,7 +977,7 @@ out: GuestDiskInfoList *qmp_guest_get_disks(Error **errp) { ERRP_GUARD(); - GuestDiskInfoList *new =3D NULL, *ret =3D NULL; + GuestDiskInfoList *ret =3D NULL; HDEVINFO dev_info; SP_DEVICE_INTERFACE_DATA dev_iface_data; int i; @@ -1064,10 +1059,7 @@ GuestDiskInfoList *qmp_guest_get_disks(Error **errp) disk->has_address =3D true; } =20 - new =3D g_malloc0(sizeof(GuestDiskInfoList)); - new->value =3D disk; - new->next =3D ret; - ret =3D new; + QAPI_LIST_PREPEND(ret, disk); } =20 SetupDiDestroyDeviceInfoList(dev_info); @@ -1165,7 +1157,7 @@ free: GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error **errp) { HANDLE vol_h; - GuestFilesystemInfoList *new, *ret =3D NULL; + GuestFilesystemInfoList *ret =3D NULL; char guid[256]; =20 vol_h =3D FindFirstVolume(guid, sizeof(guid)); @@ -1183,10 +1175,7 @@ GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error = **errp) error_free(local_err); continue; } - new =3D g_malloc(sizeof(*ret)); - new->value =3D info; - new->next =3D ret; - ret =3D new; + QAPI_LIST_PREPEND(ret, info); } while (FindNextVolume(vol_h, guid, sizeof(guid))); =20 if (GetLastError() !=3D ERROR_NO_MORE_FILES) { @@ -1330,7 +1319,6 @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum, E= rror **errp) =20 do { GuestFilesystemTrimResult *res; - GuestFilesystemTrimResultList *list; PWCHAR uc_path; DWORD char_count =3D 0; char *path, *out; @@ -1369,11 +1357,7 @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum, = Error **errp) =20 res->path =3D path; =20 - list =3D g_new0(GuestFilesystemTrimResultList, 1); - list->value =3D res; - list->next =3D resp->paths; - - resp->paths =3D list; + QAPI_LIST_PREPEND(resp->paths, res); =20 memset(argv, 0, sizeof(argv)); argv[0] =3D (gchar *)"defrag.exe"; diff --git a/qga/commands.c b/qga/commands.c index 3dcd5fbe5c..e866fc7081 100644 --- a/qga/commands.c +++ b/qga/commands.c @@ -66,17 +66,13 @@ static void qmp_command_info(const QmpCommand *cmd, voi= d *opaque) { GuestAgentInfo *info =3D opaque; GuestAgentCommandInfo *cmd_info; - GuestAgentCommandInfoList *cmd_info_list; =20 cmd_info =3D g_new0(GuestAgentCommandInfo, 1); cmd_info->name =3D g_strdup(qmp_command_name(cmd)); cmd_info->enabled =3D qmp_command_is_enabled(cmd); cmd_info->success_response =3D qmp_has_success_response(cmd); =20 - cmd_info_list =3D g_new0(GuestAgentCommandInfoList, 1); - cmd_info_list->value =3D cmd_info; - cmd_info_list->next =3D info->supported_commands; - info->supported_commands =3D cmd_info_list; + QAPI_LIST_PREPEND(info->supported_commands, cmd_info); } =20 struct GuestAgentInfo *qmp_guest_info(Error **errp) diff --git a/qom/qom-qmp-cmds.c b/qom/qom-qmp-cmds.c index 2dd233f293..b40ac39f30 100644 --- a/qom/qom-qmp-cmds.c +++ b/qom/qom-qmp-cmds.c @@ -46,14 +46,12 @@ ObjectPropertyInfoList *qmp_qom_list(const char *path, = Error **errp) =20 object_property_iter_init(&iter, obj); while ((prop =3D object_property_iter_next(&iter))) { - ObjectPropertyInfoList *entry =3D g_malloc0(sizeof(*entry)); + ObjectPropertyInfo *value =3D g_malloc0(sizeof(ObjectPropertyInfo)= ); =20 - entry->value =3D g_malloc0(sizeof(ObjectPropertyInfo)); - entry->next =3D props; - props =3D entry; + QAPI_LIST_PREPEND(props, value); =20 - entry->value->name =3D g_strdup(prop->name); - entry->value->type =3D g_strdup(prop->type); + value->name =3D g_strdup(prop->name); + value->type =3D g_strdup(prop->type); } =20 return props; @@ -90,7 +88,7 @@ QObject *qmp_qom_get(const char *path, const char *proper= ty, Error **errp) =20 static void qom_list_types_tramp(ObjectClass *klass, void *data) { - ObjectTypeInfoList *e, **pret =3D data; + ObjectTypeInfoList **pret =3D data; ObjectTypeInfo *info; ObjectClass *parent =3D object_class_get_parent(klass); =20 @@ -102,10 +100,7 @@ static void qom_list_types_tramp(ObjectClass *klass, v= oid *data) info->parent =3D g_strdup(object_class_get_name(parent)); } =20 - e =3D g_malloc0(sizeof(*e)); - e->value =3D info; - e->next =3D *pret; - *pret =3D e; + QAPI_LIST_PREPEND(*pret, info); } =20 ObjectTypeInfoList *qmp_qom_list_types(bool has_implements, @@ -150,7 +145,6 @@ ObjectPropertyInfoList *qmp_device_list_properties(cons= t char *typename, object_property_iter_init(&iter, obj); while ((prop =3D object_property_iter_next(&iter))) { ObjectPropertyInfo *info; - ObjectPropertyInfoList *entry; =20 /* Skip Object and DeviceState properties */ if (strcmp(prop->name, "type") =3D=3D 0 || @@ -176,10 +170,7 @@ ObjectPropertyInfoList *qmp_device_list_properties(con= st char *typename, info->default_value =3D qobject_ref(prop->defval); info->has_default_value =3D !!info->default_value; =20 - entry =3D g_malloc0(sizeof(*entry)); - entry->value =3D info; - entry->next =3D prop_list; - prop_list =3D entry; + QAPI_LIST_PREPEND(prop_list, info); } =20 object_unref(obj); @@ -217,7 +208,6 @@ ObjectPropertyInfoList *qmp_qom_list_properties(const c= har *typename, } while ((prop =3D object_property_iter_next(&iter))) { ObjectPropertyInfo *info; - ObjectPropertyInfoList *entry; =20 info =3D g_malloc0(sizeof(*info)); info->name =3D g_strdup(prop->name); @@ -225,10 +215,7 @@ ObjectPropertyInfoList *qmp_qom_list_properties(const = char *typename, info->has_description =3D !!prop->description; info->description =3D g_strdup(prop->description); =20 - entry =3D g_malloc0(sizeof(*entry)); - entry->value =3D info; - entry->next =3D prop_list; - prop_list =3D entry; + QAPI_LIST_PREPEND(prop_list, info); } =20 object_unref(obj); diff --git a/target/arm/helper.c b/target/arm/helper.c index 7b8bcd6903..2d0d4cd1e1 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -8283,7 +8283,6 @@ static void arm_cpu_add_definition(gpointer data, gpo= inter user_data) { ObjectClass *oc =3D data; CpuDefinitionInfoList **cpu_list =3D user_data; - CpuDefinitionInfoList *entry; CpuDefinitionInfo *info; const char *typename; =20 @@ -8293,10 +8292,7 @@ static void arm_cpu_add_definition(gpointer data, gp= ointer user_data) strlen(typename) - strlen("-" TYPE_ARM_CPU)); info->q_typename =3D g_strdup(typename); =20 - entry =3D g_malloc0(sizeof(*entry)); - entry->value =3D info; - entry->next =3D *cpu_list; - *cpu_list =3D entry; + QAPI_LIST_PREPEND(*cpu_list, info); } =20 CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) diff --git a/target/arm/monitor.c b/target/arm/monitor.c index 169d8a64b6..198b14e95e 100644 --- a/target/arm/monitor.c +++ b/target/arm/monitor.c @@ -42,15 +42,6 @@ static GICCapability *gic_cap_new(int version) return cap; } =20 -static GICCapabilityList *gic_cap_list_add(GICCapabilityList *head, - GICCapability *cap) -{ - GICCapabilityList *item =3D g_new0(GICCapabilityList, 1); - item->value =3D cap; - item->next =3D head; - return item; -} - static inline void gic_cap_kvm_probe(GICCapability *v2, GICCapability *v3) { #ifdef CONFIG_KVM @@ -84,8 +75,8 @@ GICCapabilityList *qmp_query_gic_capabilities(Error **err= p) =20 gic_cap_kvm_probe(v2, v3); =20 - head =3D gic_cap_list_add(head, v2); - head =3D gic_cap_list_add(head, v3); + QAPI_LIST_PREPEND(head, v2); + QAPI_LIST_PREPEND(head, v3); =20 return head; } diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 0d20e156f2..35459a38bb 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5014,7 +5014,6 @@ static void x86_cpu_definition_entry(gpointer data, g= pointer user_data) ObjectClass *oc =3D data; X86CPUClass *cc =3D X86_CPU_CLASS(oc); CpuDefinitionInfoList **cpu_list =3D user_data; - CpuDefinitionInfoList *entry; CpuDefinitionInfo *info; =20 info =3D g_malloc0(sizeof(*info)); @@ -5039,10 +5038,7 @@ static void x86_cpu_definition_entry(gpointer data, = gpointer user_data) info->has_alias_of =3D !!info->alias_of; } =20 - entry =3D g_malloc0(sizeof(*entry)); - entry->value =3D info; - entry->next =3D *cpu_list; - *cpu_list =3D entry; + QAPI_LIST_PREPEND(*cpu_list, info); } =20 CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) diff --git a/target/mips/cpu.c b/target/mips/cpu.c index aadc6f8e74..b2cd69ff7f 100644 --- a/target/mips/cpu.c +++ b/target/mips/cpu.c @@ -543,7 +543,6 @@ static void mips_cpu_add_definition(gpointer data, gpoi= nter user_data) { ObjectClass *oc =3D data; CpuDefinitionInfoList **cpu_list =3D user_data; - CpuDefinitionInfoList *entry; CpuDefinitionInfo *info; const char *typename; =20 @@ -553,10 +552,7 @@ static void mips_cpu_add_definition(gpointer data, gpo= inter user_data) strlen(typename) - strlen("-" TYPE_MIPS_CPU)); info->q_typename =3D g_strdup(typename); =20 - entry =3D g_malloc0(sizeof(*entry)); - entry->value =3D info; - entry->next =3D *cpu_list; - *cpu_list =3D entry; + QAPI_LIST_PREPEND(*cpu_list, info); } =20 CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c index b5abff8bef..a23fd3e32b 100644 --- a/target/s390x/cpu_models.c +++ b/target/s390x/cpu_models.c @@ -427,7 +427,6 @@ static void create_cpu_model_list(ObjectClass *klass, v= oid *opaque) { struct CpuDefinitionInfoListData *cpu_list_data =3D opaque; CpuDefinitionInfoList **cpu_list =3D &cpu_list_data->list; - CpuDefinitionInfoList *entry; CpuDefinitionInfo *info; char *name =3D g_strdup(object_class_get_name(klass)); S390CPUClass *scc =3D S390_CPU_CLASS(klass); @@ -454,10 +453,7 @@ static void create_cpu_model_list(ObjectClass *klass, = void *opaque) object_unref(obj); } =20 - entry =3D g_new0(CpuDefinitionInfoList, 1); - entry->value =3D info; - entry->next =3D *cpu_list; - *cpu_list =3D entry; + QAPI_LIST_PREPEND(*cpu_list, info); } =20 CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) @@ -624,12 +620,8 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(C= puModelExpansionType type, static void list_add_feat(const char *name, void *opaque) { strList **last =3D (strList **) opaque; - strList *entry; =20 - entry =3D g_new0(strList, 1); - entry->value =3D g_strdup(name); - entry->next =3D *last; - *last =3D entry; + QAPI_LIST_PREPEND(*last, g_strdup(name)); } =20 CpuModelCompareInfo *qmp_query_cpu_model_comparison(CpuModelInfo *infoa, diff --git a/tests/test-clone-visitor.c b/tests/test-clone-visitor.c index 5e1e8b2f5e..4944b3d857 100644 --- a/tests/test-clone-visitor.c +++ b/tests/test-clone-visitor.c @@ -65,16 +65,13 @@ static void test_clone_alternate(void) =20 static void test_clone_list_union(void) { - uint8List *src, *dst; + uint8List *src =3D NULL, *dst; uint8List *tmp =3D NULL; int i; =20 /* Build list in reverse */ for (i =3D 10; i; i--) { - src =3D g_new0(uint8List, 1); - src->next =3D tmp; - src->value =3D i; - tmp =3D src; + QAPI_LIST_PREPEND(src, i); } =20 dst =3D QAPI_CLONE(uint8List, src); diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-outpu= t-visitor.c index 1c856d9bd2..b20ab8b29b 100644 --- a/tests/test-qobject-output-visitor.c +++ b/tests/test-qobject-output-visitor.c @@ -223,7 +223,8 @@ static void test_visitor_out_list(TestOutputVisitorData= *data, const void *unused) { const char *value_str =3D "list value"; - TestStructList *p, *head =3D NULL; + TestStruct *value; + TestStructList *head =3D NULL; const int max_items =3D 10; bool value_bool =3D true; int value_int =3D 10; @@ -233,14 +234,12 @@ static void test_visitor_out_list(TestOutputVisitorDa= ta *data, =20 /* Build the list in reverse order... */ for (i =3D 0; i < max_items; i++) { - p =3D g_malloc0(sizeof(*p)); - p->value =3D g_malloc0(sizeof(*p->value)); - p->value->integer =3D value_int + (max_items - i - 1); - p->value->boolean =3D value_bool; - p->value->string =3D g_strdup(value_str); + value =3D g_malloc0(sizeof(*value)); + value->integer =3D value_int + (max_items - i - 1); + value->boolean =3D value_bool; + value->string =3D g_strdup(value_str); =20 - p->next =3D head; - head =3D p; + QAPI_LIST_PREPEND(head, value); } =20 visit_type_TestStructList(data->ov, NULL, &head, &error_abort); @@ -270,26 +269,25 @@ static void test_visitor_out_list(TestOutputVisitorDa= ta *data, static void test_visitor_out_list_qapi_free(TestOutputVisitorData *data, const void *unused) { - UserDefTwoList *p, *head =3D NULL; + UserDefTwo *value; + UserDefTwoList *head =3D NULL; const char string[] =3D "foo bar"; int i, max_count =3D 1024; =20 for (i =3D 0; i < max_count; i++) { - p =3D g_malloc0(sizeof(*p)); - p->value =3D g_malloc0(sizeof(*p->value)); + value =3D g_malloc0(sizeof(*value)); =20 - p->value->string0 =3D g_strdup(string); - p->value->dict1 =3D g_new0(UserDefTwoDict, 1); - p->value->dict1->string1 =3D g_strdup(string); - p->value->dict1->dict2 =3D g_new0(UserDefTwoDictDict, 1); - p->value->dict1->dict2->userdef =3D g_new0(UserDefOne, 1); - p->value->dict1->dict2->userdef->string =3D g_strdup(string); - p->value->dict1->dict2->userdef->integer =3D 42; - p->value->dict1->dict2->string =3D g_strdup(string); - p->value->dict1->has_dict3 =3D false; + value->string0 =3D g_strdup(string); + value->dict1 =3D g_new0(UserDefTwoDict, 1); + value->dict1->string1 =3D g_strdup(string); + value->dict1->dict2 =3D g_new0(UserDefTwoDictDict, 1); + value->dict1->dict2->userdef =3D g_new0(UserDefOne, 1); + value->dict1->dict2->userdef->string =3D g_strdup(string); + value->dict1->dict2->userdef->integer =3D 42; + value->dict1->dict2->string =3D g_strdup(string); + value->dict1->has_dict3 =3D false; =20 - p->next =3D head; - head =3D p; + QAPI_LIST_PREPEND(head, value); } =20 qapi_free_UserDefTwoList(head); diff --git a/tests/test-visitor-serialization.c b/tests/test-visitor-serial= ization.c index 1c5a8b94ea..12275e56d8 100644 --- a/tests/test-visitor-serialization.c +++ b/tests/test-visitor-serialization.c @@ -351,135 +351,51 @@ static void test_primitive_lists(gconstpointer opaqu= e) for (i =3D 0; i < 32; i++) { switch (pl.type) { case PTYPE_STRING: { - strList *tmp =3D g_new0(strList, 1); - tmp->value =3D g_strdup(pt->value.string); - if (pl.value.strings =3D=3D NULL) { - pl.value.strings =3D tmp; - } else { - tmp->next =3D pl.value.strings; - pl.value.strings =3D tmp; - } + QAPI_LIST_PREPEND(pl.value.strings, g_strdup(pt->value.string)= ); break; } case PTYPE_INTEGER: { - intList *tmp =3D g_new0(intList, 1); - tmp->value =3D pt->value.integer; - if (pl.value.integers =3D=3D NULL) { - pl.value.integers =3D tmp; - } else { - tmp->next =3D pl.value.integers; - pl.value.integers =3D tmp; - } + QAPI_LIST_PREPEND(pl.value.integers, pt->value.integer); break; } case PTYPE_S8: { - int8List *tmp =3D g_new0(int8List, 1); - tmp->value =3D pt->value.s8; - if (pl.value.s8_integers =3D=3D NULL) { - pl.value.s8_integers =3D tmp; - } else { - tmp->next =3D pl.value.s8_integers; - pl.value.s8_integers =3D tmp; - } + QAPI_LIST_PREPEND(pl.value.s8_integers, pt->value.s8); break; } case PTYPE_S16: { - int16List *tmp =3D g_new0(int16List, 1); - tmp->value =3D pt->value.s16; - if (pl.value.s16_integers =3D=3D NULL) { - pl.value.s16_integers =3D tmp; - } else { - tmp->next =3D pl.value.s16_integers; - pl.value.s16_integers =3D tmp; - } + QAPI_LIST_PREPEND(pl.value.s16_integers, pt->value.s16); break; } case PTYPE_S32: { - int32List *tmp =3D g_new0(int32List, 1); - tmp->value =3D pt->value.s32; - if (pl.value.s32_integers =3D=3D NULL) { - pl.value.s32_integers =3D tmp; - } else { - tmp->next =3D pl.value.s32_integers; - pl.value.s32_integers =3D tmp; - } + QAPI_LIST_PREPEND(pl.value.s32_integers, pt->value.s32); break; } case PTYPE_S64: { - int64List *tmp =3D g_new0(int64List, 1); - tmp->value =3D pt->value.s64; - if (pl.value.s64_integers =3D=3D NULL) { - pl.value.s64_integers =3D tmp; - } else { - tmp->next =3D pl.value.s64_integers; - pl.value.s64_integers =3D tmp; - } + QAPI_LIST_PREPEND(pl.value.s64_integers, pt->value.s64); break; } case PTYPE_U8: { - uint8List *tmp =3D g_new0(uint8List, 1); - tmp->value =3D pt->value.u8; - if (pl.value.u8_integers =3D=3D NULL) { - pl.value.u8_integers =3D tmp; - } else { - tmp->next =3D pl.value.u8_integers; - pl.value.u8_integers =3D tmp; - } + QAPI_LIST_PREPEND(pl.value.u8_integers, pt->value.u8); break; } case PTYPE_U16: { - uint16List *tmp =3D g_new0(uint16List, 1); - tmp->value =3D pt->value.u16; - if (pl.value.u16_integers =3D=3D NULL) { - pl.value.u16_integers =3D tmp; - } else { - tmp->next =3D pl.value.u16_integers; - pl.value.u16_integers =3D tmp; - } + QAPI_LIST_PREPEND(pl.value.u16_integers, pt->value.u16); break; } case PTYPE_U32: { - uint32List *tmp =3D g_new0(uint32List, 1); - tmp->value =3D pt->value.u32; - if (pl.value.u32_integers =3D=3D NULL) { - pl.value.u32_integers =3D tmp; - } else { - tmp->next =3D pl.value.u32_integers; - pl.value.u32_integers =3D tmp; - } + QAPI_LIST_PREPEND(pl.value.u32_integers, pt->value.u32); break; } case PTYPE_U64: { - uint64List *tmp =3D g_new0(uint64List, 1); - tmp->value =3D pt->value.u64; - if (pl.value.u64_integers =3D=3D NULL) { - pl.value.u64_integers =3D tmp; - } else { - tmp->next =3D pl.value.u64_integers; - pl.value.u64_integers =3D tmp; - } + QAPI_LIST_PREPEND(pl.value.u64_integers, pt->value.u64); break; } case PTYPE_NUMBER: { - numberList *tmp =3D g_new0(numberList, 1); - tmp->value =3D pt->value.number; - if (pl.value.numbers =3D=3D NULL) { - pl.value.numbers =3D tmp; - } else { - tmp->next =3D pl.value.numbers; - pl.value.numbers =3D tmp; - } + QAPI_LIST_PREPEND(pl.value.numbers, pt->value.number); break; } case PTYPE_BOOLEAN: { - boolList *tmp =3D g_new0(boolList, 1); - tmp->value =3D pt->value.boolean; - if (pl.value.booleans =3D=3D NULL) { - pl.value.booleans =3D tmp; - } else { - tmp->next =3D pl.value.booleans; - pl.value.booleans =3D tmp; - } + QAPI_LIST_PREPEND(pl.value.booleans, pt->value.boolean); break; } default: @@ -704,10 +620,7 @@ static void test_nested_struct_list(gconstpointer opaq= ue) int i =3D 0; =20 for (i =3D 0; i < 8; i++) { - tmp =3D g_new0(UserDefTwoList, 1); - tmp->value =3D nested_struct_create(); - tmp->next =3D listp; - listp =3D tmp; + QAPI_LIST_PREPEND(listp, nested_struct_create()); } =20 ops->serialize(listp, &serialize_data, visit_nested_struct_list, diff --git a/trace/qmp.c b/trace/qmp.c index 38246e1aa6..85f81e47cc 100644 --- a/trace/qmp.c +++ b/trace/qmp.c @@ -92,39 +92,37 @@ TraceEventInfoList *qmp_trace_event_get_state(const cha= r *name, /* Get states (all errors checked above) */ trace_event_iter_init(&iter, name); while ((ev =3D trace_event_iter_next(&iter)) !=3D NULL) { - TraceEventInfoList *elem; + TraceEventInfo *value; bool is_vcpu =3D trace_event_is_vcpu(ev); if (has_vcpu && !is_vcpu) { continue; } =20 - elem =3D g_new(TraceEventInfoList, 1); - elem->value =3D g_new(TraceEventInfo, 1); - elem->value->vcpu =3D is_vcpu; - elem->value->name =3D g_strdup(trace_event_get_name(ev)); + value =3D g_new(TraceEventInfo, 1); + value->vcpu =3D is_vcpu; + value->name =3D g_strdup(trace_event_get_name(ev)); =20 if (!trace_event_get_state_static(ev)) { - elem->value->state =3D TRACE_EVENT_STATE_UNAVAILABLE; + value->state =3D TRACE_EVENT_STATE_UNAVAILABLE; } else { if (has_vcpu) { if (is_vcpu) { if (trace_event_get_vcpu_state_dynamic(cpu, ev)) { - elem->value->state =3D TRACE_EVENT_STATE_ENABLED; + value->state =3D TRACE_EVENT_STATE_ENABLED; } else { - elem->value->state =3D TRACE_EVENT_STATE_DISABLED; + value->state =3D TRACE_EVENT_STATE_DISABLED; } } /* else: already skipped above */ } else { if (trace_event_get_state_dynamic(ev)) { - elem->value->state =3D TRACE_EVENT_STATE_ENABLED; + value->state =3D TRACE_EVENT_STATE_ENABLED; } else { - elem->value->state =3D TRACE_EVENT_STATE_DISABLED; + value->state =3D TRACE_EVENT_STATE_DISABLED; } } } - elem->next =3D events; - events =3D elem; + QAPI_LIST_PREPEND(events, value); } =20 return events; diff --git a/ui/input.c b/ui/input.c index 4791b089c7..8ac407dec4 100644 --- a/ui/input.c +++ b/ui/input.c @@ -571,7 +571,7 @@ void qemu_remove_mouse_mode_change_notifier(Notifier *n= otify) MouseInfoList *qmp_query_mice(Error **errp) { MouseInfoList *mice_list =3D NULL; - MouseInfoList *info; + MouseInfo *info; QemuInputHandlerState *s; bool current =3D true; =20 @@ -581,16 +581,14 @@ MouseInfoList *qmp_query_mice(Error **errp) continue; } =20 - info =3D g_new0(MouseInfoList, 1); - info->value =3D g_new0(MouseInfo, 1); - info->value->index =3D s->id; - info->value->name =3D g_strdup(s->handler->name); - info->value->absolute =3D s->handler->mask & INPUT_EVENT_MASK_ABS; - info->value->current =3D current; + info =3D g_new0(MouseInfo, 1); + info->index =3D s->id; + info->name =3D g_strdup(s->handler->name); + info->absolute =3D s->handler->mask & INPUT_EVENT_MASK_ABS; + info->current =3D current; =20 current =3D false; - info->next =3D mice_list; - mice_list =3D info; + QAPI_LIST_PREPEND(mice_list, info); } =20 return mice_list; diff --git a/ui/vnc.c b/ui/vnc.c index 34e6dc437c..7452ac7df2 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -365,14 +365,11 @@ static VncDisplay *vnc_display_find(const char *id) =20 static VncClientInfoList *qmp_query_client_list(VncDisplay *vd) { - VncClientInfoList *cinfo, *prev =3D NULL; + VncClientInfoList *prev =3D NULL; VncState *client; =20 QTAILQ_FOREACH(client, &vd->clients, next) { - cinfo =3D g_new0(VncClientInfoList, 1); - cinfo->value =3D qmp_query_vnc_client(client); - cinfo->next =3D prev; - prev =3D cinfo; + QAPI_LIST_PREPEND(prev, qmp_query_vnc_client(client)); } return prev; } @@ -453,7 +450,6 @@ static VncServerInfo2List *qmp_query_server_entry(QIOCh= annelSocket *ioc, int subauth, VncServerInfo2List *prev) { - VncServerInfo2List *list; VncServerInfo2 *info; Error *err =3D NULL; SocketAddress *addr; @@ -476,10 +472,8 @@ static VncServerInfo2List *qmp_query_server_entry(QIOC= hannelSocket *ioc, qmp_query_auth(auth, subauth, &info->auth, &info->vencrypt, &info->has_vencrypt); =20 - list =3D g_new0(VncServerInfo2List, 1); - list->value =3D info; - list->next =3D prev; - return list; + QAPI_LIST_PREPEND(prev, info); + return prev; } =20 static void qmp_query_auth(int auth, int subauth, @@ -554,7 +548,7 @@ static void qmp_query_auth(int auth, int subauth, =20 VncInfo2List *qmp_query_vnc_servers(Error **errp) { - VncInfo2List *item, *prev =3D NULL; + VncInfo2List *prev =3D NULL; VncInfo2 *info; VncDisplay *vd; DeviceState *dev; @@ -583,10 +577,7 @@ VncInfo2List *qmp_query_vnc_servers(Error **errp) vd->ws_subauth, info->server); } =20 - item =3D g_new0(VncInfo2List, 1); - item->value =3D info; - item->next =3D prev; - prev =3D item; + QAPI_LIST_PREPEND(prev, info); } return prev; } diff --git a/util/qemu-config.c b/util/qemu-config.c index 725e3d7e4b..e2a700b284 100644 --- a/util/qemu-config.c +++ b/util/qemu-config.c @@ -55,7 +55,7 @@ QemuOpts *qemu_find_opts_singleton(const char *group) =20 static CommandLineParameterInfoList *query_option_descs(const QemuOptDesc = *desc) { - CommandLineParameterInfoList *param_list =3D NULL, *entry; + CommandLineParameterInfoList *param_list =3D NULL; CommandLineParameterInfo *info; int i; =20 @@ -87,10 +87,7 @@ static CommandLineParameterInfoList *query_option_descs(= const QemuOptDesc *desc) info->q_default =3D g_strdup(desc[i].def_value_str); } =20 - entry =3D g_malloc0(sizeof(*entry)); - entry->value =3D info; - entry->next =3D param_list; - param_list =3D entry; + QAPI_LIST_PREPEND(param_list, info); } =20 return param_list; @@ -246,7 +243,7 @@ CommandLineOptionInfoList *qmp_query_command_line_optio= ns(bool has_option, const char *opti= on, Error **errp) { - CommandLineOptionInfoList *conf_list =3D NULL, *entry; + CommandLineOptionInfoList *conf_list =3D NULL; CommandLineOptionInfo *info; int i; =20 @@ -262,10 +259,7 @@ CommandLineOptionInfoList *qmp_query_command_line_opti= ons(bool has_option, info->parameters =3D query_option_descs(vm_config_groups[i]->desc); } - entry =3D g_malloc0(sizeof(*entry)); - entry->value =3D info; - entry->next =3D conf_list; - conf_list =3D entry; + QAPI_LIST_PREPEND(conf_list, info); } } =20 diff --git a/target/ppc/translate_init.c.inc b/target/ppc/translate_init.c.= inc index a4d0038828..3c05a17343 100644 --- a/target/ppc/translate_init.c.inc +++ b/target/ppc/translate_init.c.inc @@ -10566,7 +10566,6 @@ static void ppc_cpu_defs_entry(gpointer data, gpoin= ter user_data) ObjectClass *oc =3D data; CpuDefinitionInfoList **first =3D user_data; const char *typename; - CpuDefinitionInfoList *entry; CpuDefinitionInfo *info; =20 typename =3D object_class_get_name(oc); @@ -10574,10 +10573,7 @@ static void ppc_cpu_defs_entry(gpointer data, gpoi= nter user_data) info->name =3D g_strndup(typename, strlen(typename) - strlen(POWERPC_CPU_TYPE_SUFF= IX)); =20 - entry =3D g_malloc0(sizeof(*entry)); - entry->value =3D info; - entry->next =3D *first; - *first =3D entry; + QAPI_LIST_PREPEND(*first, info); } =20 CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) @@ -10593,7 +10589,6 @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Er= ror **errp) for (i =3D 0; ppc_cpu_aliases[i].alias !=3D NULL; i++) { PowerPCCPUAlias *alias =3D &ppc_cpu_aliases[i]; ObjectClass *oc; - CpuDefinitionInfoList *entry; CpuDefinitionInfo *info; =20 oc =3D ppc_cpu_class_by_name(alias->model); @@ -10605,10 +10600,7 @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(E= rror **errp) info->name =3D g_strdup(alias->alias); info->q_typename =3D g_strdup(object_class_get_name(oc)); =20 - entry =3D g_malloc0(sizeof(*entry)); - entry->value =3D info; - entry->next =3D cpu_list; - cpu_list =3D entry; + QAPI_LIST_PREPEND(cpu_list, info); } =20 return cpu_list; --=20 2.26.2 From nobody Thu May 16 15:04:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608375433; cv=none; d=zohomail.com; s=zohoarc; b=bWfQyGC7qxOVZKsQFvC3q1/TkyXlkAtOL+BPZbxayHuVkX/de67ncJiAceOfAAu6Ahdjb+9ozImtiiBu3Q1ExlbDSFvO2AuwyCRJ4W68muA7XsP3A+u1XTF2d3bd9f4QFevTBV1j18Sd9smMXxCStlnApkEBfCx3jiIPf46LYDM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608375433; 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=mLj1Wb1Z/FFpGLjsvjmSqxHr3jcfC4o/Kgc33fRcvio=; b=TEf74qFHBGB8fRcTLQ+xSu1xH3Pulr9yXAmdVVFNr7sJ1g1dY/fvinYbwbe+X+KG7FEBznFmVVjLLT1BTidW2Fs7zA2BkiU/5x10Te5SwwlPF76YEDOPW9vOi419W2FPJ4TIfxEpNX9fK4rhcYffH0i406lTD8+aTs9WtH74Vgo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1608375433034525.2914982549803; Sat, 19 Dec 2020 02:57:13 -0800 (PST) Received: from localhost ([::1]:41860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqZvD-0006Un-W7 for importer@patchew.org; Sat, 19 Dec 2020 05:57:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50516) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZtl-0004cM-4v for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:29753) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZti-0007Dt-SK for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:40 -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-207-YlTmajp1N1OICs--_ZDFBQ-1; Sat, 19 Dec 2020 05:55:35 -0500 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 0DFED800D53; Sat, 19 Dec 2020 10:55:34 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BEF7F10013C0; Sat, 19 Dec 2020 10:55:33 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 54C4811275D0; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375337; 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=mLj1Wb1Z/FFpGLjsvjmSqxHr3jcfC4o/Kgc33fRcvio=; b=LnxS20WVH3Gqtjh+04XPTw0GV+q4Uq1SUj+mDarfRmscIjlpKF5yQuc0R0Zd46LtNLIHaE D3xO4NkeXFvY/MYyOrDKi++OmiqXnPvxi6TcFyBZeRGGiVEjJllcy7PL5JmxgZpdh4Klfe S6Y3w0qmGkCDsLkTg2/2iYrlFY6HwMo= X-MC-Unique: YlTmajp1N1OICs--_ZDFBQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 04/33] tests/check-qjson: Don't skip funny QNumber to JSON conversions Date: Sat, 19 Dec 2020 11:55:03 +0100 Message-Id: <20201219105532.1734134-5-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H3=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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" simple_number() and float_number() convert from JSON to QNumber and back. simple_number() tests "-0", but skips the conversion back to JSON, because it yields "0", not "-0". Works as intended, so better cover it: don't skip, but expect the funny result. float_number() tests "-32.20e-10", but skips the conversion back to JSON, because it yields "-0". This is a known bug in qnum_to_string(), marked FIXME there. Cover the bug: don't skip, but expect the funny result. While there, switch from g_assert() to g_assert_cmpstr() & friends for friendlier test failures. Signed-off-by: Markus Armbruster Message-Id: <20201210161452.2813491-2-armbru@redhat.com> --- tests/check-qjson.c | 55 +++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/tests/check-qjson.c b/tests/check-qjson.c index 9a02079099..2a5852904a 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -793,37 +793,35 @@ static void utf8_string(void) =20 static void simple_number(void) { - int i; struct { const char *encoded; int64_t decoded; - int skip; + const char *reencoded; } test_cases[] =3D { { "0", 0 }, { "1234", 1234 }, { "1", 1 }, { "-32", -32 }, - { "-0", 0, .skip =3D 1 }, - { }, + { "-0", 0, "0" }, + {}, }; + int i; + QNum *qnum; + int64_t val; + QString *str; =20 for (i =3D 0; test_cases[i].encoded; i++) { - QNum *qnum; - int64_t val; - qnum =3D qobject_to(QNum, qobject_from_json(test_cases[i].encoded, &error_abort)); 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 - str =3D qobject_to_json(QOBJECT(qnum)); - g_assert(strcmp(qstring_get_str(str), test_cases[i].encoded) = =3D=3D 0); - qobject_unref(str); - } + str =3D qobject_to_json(QOBJECT(qnum)); + g_assert_cmpstr(qstring_get_str(str), =3D=3D, + test_cases[i].reencoded ?: test_cases[i].encoded); + qobject_unref(str); =20 qobject_unref(qnum); } @@ -874,35 +872,32 @@ static void large_number(void) =20 static void float_number(void) { - int i; struct { const char *encoded; double decoded; - int skip; + const char *reencoded; } test_cases[] =3D { { "32.43", 32.43 }, { "0.222", 0.222 }, { "-32.12313", -32.12313 }, - { "-32.20e-10", -32.20e-10, .skip =3D 1 }, - { }, + { "-32.20e-10", -32.20e-10, "-0" /* BUG */ }, + {}, }; + int i; + QNum *qnum; + QString *str; =20 for (i =3D 0; test_cases[i].encoded; i++) { - QObject *obj; - QNum *qnum; - - obj =3D qobject_from_json(test_cases[i].encoded, &error_abort); - qnum =3D qobject_to(QNum, obj); + qnum =3D qobject_to(QNum, + qobject_from_json(test_cases[i].encoded, + &error_abort)); g_assert(qnum); - g_assert(qnum_get_double(qnum) =3D=3D test_cases[i].decoded); + g_assert_cmpfloat(qnum_get_double(qnum), =3D=3D, test_cases[i].dec= oded); =20 - if (test_cases[i].skip =3D=3D 0) { - QString *str; - - str =3D qobject_to_json(obj); - g_assert(strcmp(qstring_get_str(str), test_cases[i].encoded) = =3D=3D 0); - qobject_unref(str); - } + str =3D qobject_to_json(QOBJECT(qnum)); + g_assert_cmpstr(qstring_get_str(str), =3D=3D, + test_cases[i].reencoded ?: test_cases[i].encoded); + qobject_unref(str); =20 qobject_unref(qnum); } --=20 2.26.2 From nobody Thu May 16 15:04:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608375540; cv=none; d=zohomail.com; s=zohoarc; b=f/sURXr4UtN6v4CNEngjjq/HZN8/E4hMUL26Azx2W3KfDBQRMSuPDtgA//7HjZeuYc8+OGfp0olMM9gVHPaFmTaI56HrVvusec+OKmaatOYQtBNGU+/a7EkIfUITiBvJzzRFA69PbWOFSvqy9vzghKM1o4wKYgBGnCnC4vnjHjg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608375540; 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=rF5fT1gZXKnfqiVY/qPcGkhvwCR4b3RUuHSyi4mpzr4=; b=n7Pvz0ASMOCsWuB4eqzr7mJeAS1yPzxLPmmrBl8qx/NlnhWugjeM+ek6ZXicClR1UTn98onG3vfi/0+wtnkftcYDSNyWEzUyBA9LtmRYSmvGFrVXAFQ7nFKPgjA6PHRX4PDE+skP22zDH3oKsgQKkHemD9MTMYQz3aqgSGW3N1c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1608375540736766.5116295411891; Sat, 19 Dec 2020 02:59:00 -0800 (PST) Received: from localhost ([::1]:50342 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqZwx-0001UF-Mv for importer@patchew.org; Sat, 19 Dec 2020 05:58:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50596) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZtm-0004eL-NU for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:42 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:41116) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtj-0007EM-L3 for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:42 -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-54-j6Q9ZV6uOtummZj8_zFjjw-1; Sat, 19 Dec 2020 05:55:36 -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 74E33180A086; Sat, 19 Dec 2020 10:55:35 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 470FB60C13; Sat, 19 Dec 2020 10:55:35 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5802311275D7; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375338; 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=rF5fT1gZXKnfqiVY/qPcGkhvwCR4b3RUuHSyi4mpzr4=; b=JGemrc7LezCBFLuLrvmP0eFixTbo82eYwN2RIshLMCDVPUrfocvrCApV0hhB3xDNTWSkH9 WS04cD15IxI0HFw9KlcHjfjYUj4hCtLpCaLtEMAan4X4MOp+MvGbxdpGCK8xsojCyCqh2a fMTvng5Bl4CxbbYXWYWHs5ugwou3zEo= X-MC-Unique: j6Q9ZV6uOtummZj8_zFjjw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 05/33] tests/check-qjson: Examine QNum more thoroughly Date: Sat, 19 Dec 2020 11:55:04 +0100 Message-Id: <20201219105532.1734134-6-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" simple_number() checks only qnum_get_try_int(). Also check qnum_get_try_uint() and qnum_get_double(). float_number() checks only qnum_get_double(). Also check qnum_get_try_int() and qnum_get_try_uint(). Signed-off-by: Markus Armbruster Message-Id: <20201210161452.2813491-3-armbru@redhat.com> --- tests/check-qjson.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/tests/check-qjson.c b/tests/check-qjson.c index 2a5852904a..6ab6b111b0 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -807,7 +807,8 @@ static void simple_number(void) }; int i; QNum *qnum; - int64_t val; + int64_t ival; + uint64_t uval; QString *str; =20 for (i =3D 0; test_cases[i].encoded; i++) { @@ -815,8 +816,16 @@ static void simple_number(void) qobject_from_json(test_cases[i].encoded, &error_abort)); g_assert(qnum); - g_assert(qnum_get_try_int(qnum, &val)); - g_assert_cmpint(val, =3D=3D, test_cases[i].decoded); + g_assert(qnum_get_try_int(qnum, &ival)); + g_assert_cmpint(ival, =3D=3D, test_cases[i].decoded); + if (test_cases[i].decoded >=3D 0) { + g_assert(qnum_get_try_uint(qnum, &uval)); + g_assert_cmpuint(uval, =3D=3D, (uint64_t)test_cases[i].decoded= ); + } else { + g_assert(!qnum_get_try_uint(qnum, &uval)); + } + g_assert_cmpfloat(qnum_get_double(qnum), =3D=3D, + (double)test_cases[i].decoded); =20 str =3D qobject_to_json(QOBJECT(qnum)); g_assert_cmpstr(qstring_get_str(str), =3D=3D, @@ -885,6 +894,8 @@ static void float_number(void) }; int i; QNum *qnum; + int64_t ival; + uint64_t uval; QString *str; =20 for (i =3D 0; test_cases[i].encoded; i++) { @@ -893,6 +904,8 @@ static void float_number(void) &error_abort)); g_assert(qnum); g_assert_cmpfloat(qnum_get_double(qnum), =3D=3D, test_cases[i].dec= oded); + g_assert(!qnum_get_try_int(qnum, &ival)); + g_assert(!qnum_get_try_uint(qnum, &uval)); =20 str =3D qobject_to_json(QOBJECT(qnum)); g_assert_cmpstr(qstring_get_str(str), =3D=3D, --=20 2.26.2 From nobody Thu May 16 15:04:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608375543; cv=none; d=zohomail.com; s=zohoarc; b=MfvXRwvNWIZjUNyY2ZiDO1Uubaf8MQAuDg2v3PleIeI8mY3NRZKORWmgEWm1Y8U/inyo+a1O49Gx1FLn7rMTx3uKpGxvtv9HIvvjVXior8ggfYG5N5/8iuM52b4CZQfe5uRa3JAlmFYfPLtX5f9zX2ZKKfsM90cSzJJmegiuqSY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608375543; 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=i+jmy7KhHeda8A+n3ltXuYMeceanMn5NQ9kZl2kMJtY=; b=iOm7Pf3vCBdKZQPZ9kpTGYL1WkBTMBn1jEotKjvXMqYs+dhoxqb1uVxFM/7pdeL+77hGoBkkA1eS0Gy8qmWbubH/ntuAThd+okeARNCyg4KrkKAJyBm+f2F4EkNwogkGWz0cczvYPeeCz3OkPEfD1FkVrYxzJvs4/fFgn1kyM2A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1608375543047742.5049340922013; Sat, 19 Dec 2020 02:59:03 -0800 (PST) Received: from localhost ([::1]:50658 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqZx0-0001bz-1n for importer@patchew.org; Sat, 19 Dec 2020 05:59:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50654) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZtp-0004iI-A7 for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:45 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:48742) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtj-0007EJ-NS for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:44 -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-466-ZGDFK7UeNSOsnZPZuzmI7A-1; Sat, 19 Dec 2020 05:55:36 -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 7616D10054FF; Sat, 19 Dec 2020 10:55:35 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 47A935D9C2; Sat, 19 Dec 2020 10:55:35 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5B41611275DA; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375338; 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=i+jmy7KhHeda8A+n3ltXuYMeceanMn5NQ9kZl2kMJtY=; b=QeXI9NsUxwGfrPA9znKl7JYDBrvFZQIga08gmtiFW9CQcgYmOzUguRw9GkxYtn7AVJnrcK KYBcKIbYOKfRMuJeRH9kzs7ufHm57APsgLLui1z38i2GiYoR2RVrqKb4UUbGfPmpLdlqdw m9jSCU4SEGg9yDUBws5GVKzSsapqqoY= X-MC-Unique: ZGDFK7UeNSOsnZPZuzmI7A-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 06/33] tests/check-qjson: Cover number 2^63 Date: Sat, 19 Dec 2020 11:55:05 +0100 Message-Id: <20201219105532.1734134-7-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Message-Id: <20201210161452.2813491-4-armbru@redhat.com> --- tests/check-qjson.c | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/tests/check-qjson.c b/tests/check-qjson.c index 6ab6b111b0..8cb8a40524 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -791,7 +791,7 @@ static void utf8_string(void) } } =20 -static void simple_number(void) +static void int_number(void) { struct { const char *encoded; @@ -836,6 +836,42 @@ static void simple_number(void) } } =20 +static void uint_number(void) +{ + struct { + const char *encoded; + uint64_t decoded; + const char *reencoded; + } test_cases[] =3D { + { "9223372036854775808", (uint64_t)1 << 63 }, + {}, + }; + int i; + QNum *qnum; + int64_t ival; + uint64_t uval; + QString *str; + + for (i =3D 0; test_cases[i].encoded; i++) { + qnum =3D qobject_to(QNum, + qobject_from_json(test_cases[i].encoded, + &error_abort)); + g_assert(qnum); + g_assert(qnum_get_try_uint(qnum, &uval)); + g_assert_cmpuint(uval, =3D=3D, test_cases[i].decoded); + g_assert(!qnum_get_try_int(qnum, &ival)); + g_assert_cmpfloat(qnum_get_double(qnum), =3D=3D, + (double)test_cases[i].decoded); + + str =3D qobject_to_json(QOBJECT(qnum)); + g_assert_cmpstr(qstring_get_str(str), =3D=3D, + test_cases[i].reencoded ?: test_cases[i].encoded); + qobject_unref(str); + + qobject_unref(qnum); + } +} + static void large_number(void) { const char *maxu64 =3D "18446744073709551615"; /* 2^64-1 */ @@ -1487,7 +1523,8 @@ int main(int argc, char **argv) g_test_add_func("/literals/string/quotes", string_with_quotes); 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/int", int_number); + g_test_add_func("/literals/number/uint", uint_number); g_test_add_func("/literals/number/large", large_number); g_test_add_func("/literals/number/float", float_number); =20 --=20 2.26.2 From nobody Thu May 16 15:04:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608375937; cv=none; d=zohomail.com; s=zohoarc; b=WfbmpC4LfvbnCwzNV75MV3hQgo3oWj7OnYA87ysM57hMg5Slu/44Em9Oml7CDp66r20e/ZvKLPv3yidY3aOwHdFYSFcb1VMqGMllco/EKhQUn+fCTFxV6kN9KU8airqtBnGVBfOp3IABQX4dNzW16SeLgyk9uwhSSqRMsv75C/U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608375937; 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=PVC8Oj2H6fV+VbT/OGKNv+gAq4Vc0BacxYpIeutFtuE=; b=j9Jedim+FOgVom3S45u5YSxFn6ATzpq/AdIN/yfU/xVR+HBcsuU4BW3bINGOxaD7hjJZsZpitz3UJk9VsZDSsqQjMQ+lB+SLoEMXlkBNBDAwXLtjz23CNC9BxUpnWb1wEO0i6Nu2Q2D3T3cUepi7aXNZUeExqhIsqH4ez8XBzCM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1608375937752395.4937849240106; Sat, 19 Dec 2020 03:05:37 -0800 (PST) Received: from localhost ([::1]:39362 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqa3F-0000HK-DN for importer@patchew.org; Sat, 19 Dec 2020 06:05:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50662) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZtp-0004ix-JZ for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:45 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:52765) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtj-0007Ec-OD for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:45 -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-261-pSQeqeH7OJSUmrO2K-fAuA-1; Sat, 19 Dec 2020 05:55:36 -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 7460051DB; Sat, 19 Dec 2020 10:55:35 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 471AD60C61; Sat, 19 Dec 2020 10:55:35 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5E95D11275DE; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375338; 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=PVC8Oj2H6fV+VbT/OGKNv+gAq4Vc0BacxYpIeutFtuE=; b=cTr9BH2nilzxM7hj1wivucyYHgXH5GnbpzcdEbIXdVymx/ORebFEPYAmFE57XU92rwsnNW dgGrr9HqXvzfzZgxKZDrYfINcdECd41AP8G52IZjfvaRraoct8mx9sXL0qRNeRd1pHnrnD cv8+55uDnOx0kGQCEWLm/8mrciwW4SI= X-MC-Unique: pSQeqeH7OJSUmrO2K-fAuA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 07/33] tests/check-qjson: Replace redundant large_number() Date: Sat, 19 Dec 2020 11:55:06 +0100 Message-Id: <20201219105532.1734134-8-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H3=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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Move one of large_number()'s three checks to uint_number(), and the other two to float_number(). Signed-off-by: Markus Armbruster Message-Id: <20201210161452.2813491-5-armbru@redhat.com> --- tests/check-qjson.c | 47 +++------------------------------------------ 1 file changed, 3 insertions(+), 44 deletions(-) diff --git a/tests/check-qjson.c b/tests/check-qjson.c index 8cb8a40524..98515b1fd6 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -844,6 +844,7 @@ static void uint_number(void) const char *reencoded; } test_cases[] =3D { { "9223372036854775808", (uint64_t)1 << 63 }, + { "18446744073709551615", UINT64_MAX }, {}, }; int i; @@ -872,49 +873,6 @@ static void uint_number(void) } } =20 -static void large_number(void) -{ - const char *maxu64 =3D "18446744073709551615"; /* 2^64-1 */ - const char *gtu64 =3D "18446744073709551616"; /* 2^64 */ - const char *lti64 =3D "-9223372036854775809"; /* -2^63 - 1 */ - QNum *qnum; - QString *str; - uint64_t val; - int64_t ival; - - qnum =3D qobject_to(QNum, qobject_from_json(maxu64, &error_abort)); - g_assert(qnum); - g_assert_cmpuint(qnum_get_uint(qnum), =3D=3D, 18446744073709551615U); - g_assert(!qnum_get_try_int(qnum, &ival)); - - str =3D qobject_to_json(QOBJECT(qnum)); - g_assert_cmpstr(qstring_get_str(str), =3D=3D, maxu64); - qobject_unref(str); - qobject_unref(qnum); - - qnum =3D qobject_to(QNum, qobject_from_json(gtu64, &error_abort)); - 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)); - - str =3D qobject_to_json(QOBJECT(qnum)); - g_assert_cmpstr(qstring_get_str(str), =3D=3D, gtu64); - qobject_unref(str); - qobject_unref(qnum); - - qnum =3D qobject_to(QNum, qobject_from_json(lti64, &error_abort)); - 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)); - - str =3D qobject_to_json(QOBJECT(qnum)); - g_assert_cmpstr(qstring_get_str(str), =3D=3D, "-9223372036854775808"); - qobject_unref(str); - qobject_unref(qnum); -} - static void float_number(void) { struct { @@ -926,6 +884,8 @@ static void float_number(void) { "0.222", 0.222 }, { "-32.12313", -32.12313 }, { "-32.20e-10", -32.20e-10, "-0" /* BUG */ }, + { "18446744073709551616", 0x1p64 }, + { "-9223372036854775809", -0x1p63, "-9223372036854775808" }, {}, }; int i; @@ -1525,7 +1485,6 @@ int main(int argc, char **argv) =20 g_test_add_func("/literals/number/int", int_number); g_test_add_func("/literals/number/uint", uint_number); - g_test_add_func("/literals/number/large", large_number); g_test_add_func("/literals/number/float", float_number); =20 g_test_add_func("/literals/keyword", keyword_literal); --=20 2.26.2 From nobody Thu May 16 15:04:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608375435; cv=none; d=zohomail.com; s=zohoarc; b=Zftn3d1DOwprNtLMbL30BRuYqsl+hh4pSULUwsOqE7Jyx84Tg/qjLyfmWkro2q+bqy4gMqdMXQwlPY2kB2J2G6Ykq1g/MwU9DYmiYCLA6KsEsW/tPorlmVuAHQ1BIV64gOzaMG13nISCEZWvnx0jps9Q0NAQG4TNYdAucrMiPS4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608375435; 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=MZLk6cmDJfqpjMmbqC7Hu0ZwipV1es0P2HlIXO6VP8s=; b=aTqmp1KFDHIukWU7TCdJjFL1h9BOuDvzdlWk6Z5GtckXUVXydeq33bC/A3ocNaCebnMmmpMC/uxL7/AeyHuSrMMk37nyss+6fTTr5baQ9t9bykce/HOq/ZTTcXzkT5gKs4afPesxUV1ReV+dlkgjO8rnqA6qP3OggmelhBrywrI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1608375435048590.1907351903377; Sat, 19 Dec 2020 02:57:15 -0800 (PST) Received: from localhost ([::1]:42144 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqZvF-0006cg-UR for importer@patchew.org; Sat, 19 Dec 2020 05:57:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50590) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZtm-0004dj-Af for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:42 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:27064) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtj-0007ET-GS for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:42 -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-195-9YzQ30zQMEu6Z9Xb1kATIQ-1; Sat, 19 Dec 2020 05:55:36 -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 771638015C3; Sat, 19 Dec 2020 10:55:35 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4A7CA6E51F; Sat, 19 Dec 2020 10:55:35 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6565411275E4; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375338; 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=MZLk6cmDJfqpjMmbqC7Hu0ZwipV1es0P2HlIXO6VP8s=; b=OZCSuH7dmMN2/55PZ5lDeDBtYKQCZkK4F4WzXSjRsZcy5nN5sZrBFp5hMQo5VmkObk+P74 Gq9BGJK1MgVomT9sz31BVwvTAaAA7OXdPABMGSDNTSkK/Mx9MMifFvSZ2f+inBSH7K0l3w 42liUjvra2KQquEfDI+JO1Hs/sPlsd8= X-MC-Unique: 9YzQ30zQMEu6Z9Xb1kATIQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 08/33] tests/check-qnum: Cover qnum_to_string() for "unround" argument Date: Sat, 19 Dec 2020 11:55:07 +0100 Message-Id: <20201219105532.1734134-9-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H3=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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" qnum_to_string() has a FIXME comment about rounding errors due to insufficient precision. Cover it: 2.718281828459045 gets converted to "2.718282". The next commit will fix it. Signed-off-by: Markus Armbruster Message-Id: <20201210161452.2813491-6-armbru@redhat.com> --- tests/check-qnum.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/check-qnum.c b/tests/check-qnum.c index 4105015872..a73809d021 100644 --- a/tests/check-qnum.c +++ b/tests/check-qnum.c @@ -150,6 +150,12 @@ static void qnum_to_string_test(void) g_assert_cmpstr(tmp, =3D=3D, "0.42"); g_free(tmp); qobject_unref(qn); + + qn =3D qnum_from_double(2.718281828459045); + tmp =3D qnum_to_string(qn); + g_assert_cmpstr(tmp, =3D=3D, "2.718282"); /* BUG */ + g_free(tmp); + qobject_unref(qn); } =20 int main(int argc, char **argv) --=20 2.26.2 From nobody Thu May 16 15:04:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608375748; cv=none; d=zohomail.com; s=zohoarc; b=V3DZyR5u8iwZDYO1Eobegh24KuXe7PnDNHWhdRHmjbi9rWRMaCNNSL1MFLi/IIhe4YCL0HG6AtanJ0e9/2zlphZBYM/YHHeZGyvojk6jh+H0o/28WUVv/MoaLc55K9++aAS1tvmgnmQT+8rdypOeyTHUn5C2HEAN2MHffoLbVwY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608375748; 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=rCtEO6UkdVoldCnYGM1ell4q8/Mgw7rPSKkWgSwaC+U=; b=GagkuomZlf3Oq3hYW5hQb/MOBqzqdLFQC9FNWmF2N5J03DvXKYXq2DnP9tD+Cua2p0TJ0MAhFhPo1yVQkyPgqVmtv3HUaCHlnUQbjcxQSWLRNo/xXYWNQ2Nnkzkf4b0WpfeDWNDVoD5VJJnZg9k1MVi2XXvG64EDaJmWCpwwopI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1608375748687954.6524830033313; Sat, 19 Dec 2020 03:02:28 -0800 (PST) Received: from localhost ([::1]:58944 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqa0I-00056n-Hg for importer@patchew.org; Sat, 19 Dec 2020 06:02:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50650) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZtp-0004hP-4l for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:45 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:33991) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtj-0007EH-Mi for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:43 -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-54-7CDGbBpaOjeKfHo_WXB8Fw-1; Sat, 19 Dec 2020 05:55:36 -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 A0934107ACE6; Sat, 19 Dec 2020 10:55:35 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4E3316A8F1; Sat, 19 Dec 2020 10:55:35 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6A36611275EC; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375338; 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=rCtEO6UkdVoldCnYGM1ell4q8/Mgw7rPSKkWgSwaC+U=; b=CQHSUHYzotyM7HJXKiYWoLOgtgoBNWCNPwBqF3A2BU0SRA6zkYbK+KVlUhFz4lHgIrhJdq RI/+P45O4kXRx0Dg3jgeWcy/zzhPVaboU+RgYH/JFgcdPj4L+WAzRikU75ZZkv0JHaTUjv 4pDlAEkmCf3LNp4ekWFtie/wnSQXuSY= X-MC-Unique: 7CDGbBpaOjeKfHo_WXB8Fw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 09/33] qobject: Fix qnum_to_string() to use sufficient precision Date: Sat, 19 Dec 2020 11:55:08 +0100 Message-Id: <20201219105532.1734134-10-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" We should serialize numbers to JSON so that they deserialize back to the same number. We fail to do so. The culprit is qnum_to_string(): it uses format %f with trailing '0' trimmed. Results in pretty output for "nice" numbers, but is prone to nasty rounding errors. For instance, numbers between 0 and 0.0000005 get flushed to zero. Where exactly the incorrect rounding can bite is tiresome to gauge. Here's my take. * In QMP output, type 'number': - query-blockstats value avg_rd_queue_depth - QMP query-migrate values mbps, cache-miss-rate, encoding-rate, busy-rate, compression-rate. Relatively harmless, I guess. * In tracing QMP input. Harmless. * In qemu-ga output, type 'number': guest-get-users value login-time. Harmless. * In output of HMP qom-get. Harmless. Not affected, because double values don't actually occur there (I think): * QMP output, type 'any': * qom-get value * qom-list, qom-list-properties value default-value * query-cpu-model-comparison, query-cpu-model-baseline, query-cpu-model-expansion value props. * qemu-img --output json output. * "json:" pseudo-filenames generated by bdrv_refresh_filename(). * The rbd block driver's "=3Dkeyvalue-pairs" hack. * In -object help on property default values. Aside: use of JSON feels inappropriate here. * Output of HMP qom-get. * Argument conversion to QemuOpts for qdev_device_add() and HMP with qemu_opts_from_qdict() QMP and HMP device_add, virtio-net failover primary creation, xen-usb "usb-host" creation, HMP netdev_add, object_add. * The uses of qobject_input_visitor_new_flat_confused() As far as I can tell, none of the visited types contain double values. * Dumping ImageInfoSpecific with dump_qobject() Fix by formatting with %.17g. 17 decimal digits always suffice for IEEE double. The change to expected test output illustrates the effect: the rounding errors are gone, but some seemingly "nice" numbers now get converted to not so nice strings, e.g. 0.42 to "0.41999999999999998". This is because 0.42 is not representable exactly in double. It's more accurate in this example than strictly necessary, though. If ugly accuracy bothers us, we can we can try using the least number of digits that still converts back to the same double. In this example, "0.42" would do. Signed-off-by: Markus Armbruster Message-Id: <20201210161452.2813491-7-armbru@redhat.com> --- qobject/qnum.c | 24 +++--------------------- tests/check-qjson.c | 8 ++++---- tests/check-qnum.c | 4 ++-- 3 files changed, 9 insertions(+), 27 deletions(-) diff --git a/qobject/qnum.c b/qobject/qnum.c index 7012fc57f2..bf1240ecec 100644 --- a/qobject/qnum.c +++ b/qobject/qnum.c @@ -161,37 +161,19 @@ double qnum_get_double(QNum *qn) =20 char *qnum_to_string(QNum *qn) { - char *buffer; - int len; - switch (qn->kind) { case QNUM_I64: return g_strdup_printf("%" PRId64, qn->u.i64); case QNUM_U64: return g_strdup_printf("%" PRIu64, qn->u.u64); case QNUM_DOUBLE: - /* FIXME: snprintf() is locale dependent; but JSON requires + /* FIXME: g_strdup_printf() is locale dependent; but JSON requires * numbers to be formatted as if in the C locale. Dependence * on C locale is a pervasive issue in QEMU. */ /* FIXME: This risks printing Inf or NaN, which are not valid * JSON values. */ - /* FIXME: the default precision of 6 for %f often causes - * 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); - len =3D strlen(buffer); - while (len > 0 && buffer[len - 1] =3D=3D '0') { - len--; - } - - if (len && buffer[len - 1] =3D=3D '.') { - buffer[len - 1] =3D 0; - } else { - buffer[len] =3D 0; - } - - return buffer; + /* 17 digits suffice for IEEE double */ + return g_strdup_printf("%.17g", qn->u.dbl); } =20 assert(0); diff --git a/tests/check-qjson.c b/tests/check-qjson.c index 98515b1fd6..ca8fb816e9 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -882,10 +882,10 @@ static void float_number(void) } test_cases[] =3D { { "32.43", 32.43 }, { "0.222", 0.222 }, - { "-32.12313", -32.12313 }, - { "-32.20e-10", -32.20e-10, "-0" /* BUG */ }, - { "18446744073709551616", 0x1p64 }, - { "-9223372036854775809", -0x1p63, "-9223372036854775808" }, + { "-32.12313", -32.12313, "-32.123130000000003" }, + { "-32.20e-10", -32.20e-10, "-3.22e-09" }, + { "18446744073709551616", 0x1p64, "1.8446744073709552e+19" }, + { "-9223372036854775809", -0x1p63, "-9.2233720368547758e+18" }, {}, }; int i; diff --git a/tests/check-qnum.c b/tests/check-qnum.c index a73809d021..b85fca2302 100644 --- a/tests/check-qnum.c +++ b/tests/check-qnum.c @@ -147,13 +147,13 @@ static void qnum_to_string_test(void) =20 qn =3D qnum_from_double(0.42); tmp =3D qnum_to_string(qn); - g_assert_cmpstr(tmp, =3D=3D, "0.42"); + g_assert_cmpstr(tmp, =3D=3D, "0.41999999999999998"); g_free(tmp); qobject_unref(qn); =20 qn =3D qnum_from_double(2.718281828459045); tmp =3D qnum_to_string(qn); - g_assert_cmpstr(tmp, =3D=3D, "2.718282"); /* BUG */ + g_assert_cmpstr(tmp, =3D=3D, "2.7182818284590451"); g_free(tmp); qobject_unref(qn); } --=20 2.26.2 From nobody Thu May 16 15:04:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608375517; cv=none; d=zohomail.com; s=zohoarc; b=XqOPWgFr9nGkjw+Sezj+jscgXtXVHm6SUnjNebc+/2sKnAqgN09jtgPqES2QEsZFmIuP69btGFXt/DSuFvzq8KGmLggPwTDUXvDaGHW0V5oO51QsNaMPds09Am9K8LfJ2Mdssdf0MojH9nq246mNVs8T/f4u0eQKzmU/zFPOEqE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608375517; 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=kpOJQvBq1coT6r2jJ+08PmeZ5F89iddMJf8yJY1qqAg=; b=hTiRzy/AhGo/KdlDPwQWT5Q2NS4b+Ut8NJleujRhDDfF93PJo64m4b/+bgf64kP4qMocnfcXJrGTj6kuw3maSrUfd0k4fTXiaJHD3PkXGiJggV0eE2cCeN37DgAj3G59EQO+cuiwQpBUaEaxUPmivar0HtUl6F8xMP5v+2Yo20U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1608375517125875.3986614217354; Sat, 19 Dec 2020 02:58:37 -0800 (PST) Received: from localhost ([::1]:48556 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqZwa-0000mL-3K for importer@patchew.org; Sat, 19 Dec 2020 05:58:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50588) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZtm-0004dc-6s for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:42 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:51099) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtj-0007EN-Ct for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:41 -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-221-k7O4dj0pP9m4b1V1H2orrA-1; Sat, 19 Dec 2020 05:55:36 -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 7E755180A089; Sat, 19 Dec 2020 10:55:35 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 51F2F6F98F; Sat, 19 Dec 2020 10:55:35 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6EEBD11275ED; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375338; 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=kpOJQvBq1coT6r2jJ+08PmeZ5F89iddMJf8yJY1qqAg=; b=YKeW73vK1zhjBxUkh1NXG3S2M2P49w1jE9+y/x5vN+UHsugzgqLEoUOD3Cuy0q4Qxngb/z b9RbpJWinARJruy1BNsm3aXeKxQqNc/rhiDm3FnJSf3by+aam+5+NBvHrihabxDeCBMo5T xh8ZYmGaSGd/dqjaIelB1nR5XZL8d6k= X-MC-Unique: k7O4dj0pP9m4b1V1H2orrA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 10/33] test-string-output-visitor: Cover "unround" number Date: Sat, 19 Dec 2020 11:55:09 +0100 Message-Id: <20201219105532.1734134-11-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H3=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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This demonstrates rounding error due to insufficient precision: double 3.1415926535897932 gets converted to JSON 3.141593. Signed-off-by: Markus Armbruster Message-Id: <20201210161452.2813491-8-armbru@redhat.com> --- tests/test-string-output-visitor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test-string-output-visitor.c b/tests/test-string-output-= visitor.c index 9f6581439a..cec20848ea 100644 --- a/tests/test-string-output-visitor.c +++ b/tests/test-string-output-visitor.c @@ -130,13 +130,13 @@ static void test_visitor_out_bool(TestOutputVisitorDa= ta *data, static void test_visitor_out_number(TestOutputVisitorData *data, const void *unused) { - double value =3D 3.14; + double value =3D 3.1415926535897932; char *str; =20 visit_type_number(data->ov, NULL, &value, &error_abort); =20 str =3D visitor_get(data); - g_assert_cmpstr(str, =3D=3D, "3.140000"); + g_assert_cmpstr(str, =3D=3D, "3.141593"); } =20 static void test_visitor_out_string(TestOutputVisitorData *data, --=20 2.26.2 From nobody Thu May 16 15:04:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608375703; cv=none; d=zohomail.com; s=zohoarc; b=VmMINgfEniYqkxO78Uxy79/SXjRIloBxDsXeG+ETogcQI27WgpQ0+QgEvqxO+ZM7DL4whbUTEfk83zpr7By1iX5K2SHgy02vyeRAPMDGeLJiVTbmBo2cAlC9wvgECGpua5ENa9Tnnn9vkAYiTduAYO1ATg67AM8I2T40aQivTNk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608375703; 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=vOPPEvGdRvMuw2quKrOVE7sPxJD3SHwa7zeZkOrTbzw=; b=DvITYaLlPDzjQJ5dNcmfdfn5eGnMg2mkuJaWs5ayF40G4mu3sl4o7iHB7hbAQT1wlnIVvOdDZAqldxPatg6JINMB539UxvIroYOHdp4TQ6nVvIMvEOb/c6UZR3YtPxxN3YGC9XX39eNERN7CyHLSgQKsCnyi/tagwu/8/8MvWFs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1608375703888969.3379862223381; Sat, 19 Dec 2020 03:01:43 -0800 (PST) Received: from localhost ([::1]:56898 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqZza-0004Fo-O3 for importer@patchew.org; Sat, 19 Dec 2020 06:01:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50642) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZtn-0004gH-IV for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:54440) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtj-0007EK-LV for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:43 -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-466-u4VOvFIyMYKQYSznvPUCOw-1; Sat, 19 Dec 2020 05:55:36 -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 921D7801AA3; Sat, 19 Dec 2020 10:55:35 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 65BDF60C62; Sat, 19 Dec 2020 10:55:35 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 739F111275F3; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375338; 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=vOPPEvGdRvMuw2quKrOVE7sPxJD3SHwa7zeZkOrTbzw=; b=MQvSpYH0bFFYMAxbWsFhkykPLvGpqz8WzUBmjaCkF5f9uKODsIOfSpzNoVSAcPOw66QhpN Q30u+yedN74Sdn0s2Cyn4WykPgpZKcrwhPOAxgMtDKRVd6gAlfR5bCD0p2LwHtrqdXmcte iJl57a4BXk+LRASanL3kijbyhXT42yY= X-MC-Unique: u4VOvFIyMYKQYSznvPUCOw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 11/33] string-output-visitor: Fix to use sufficient precision Date: Sat, 19 Dec 2020 11:55:10 +0100 Message-Id: <20201219105532.1734134-12-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The string output visitor should serialize numbers so that the string input visitor deserializes them back to the same number. It fails to do so. print_type_number() uses format %f. This is prone to nasty rounding errors. For instance, numbers between 0 and 0.0000005 get flushed to zero. We currently use this visitor only for HMP info migrate, info network, info qtree, and info memdev. No double values occur there as far as I can tell. Fix anyway by formatting with %.17g. 17 decimal digits always suffice for IEEE double. See also recent commit "qobject: Fix qnum_to_string() to use sufficient precision". Signed-off-by: Markus Armbruster Message-Id: <20201210161452.2813491-9-armbru@redhat.com> --- qapi/string-output-visitor.c | 2 +- tests/test-string-output-visitor.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/qapi/string-output-visitor.c b/qapi/string-output-visitor.c index b74aa4d44c..5506c933de 100644 --- a/qapi/string-output-visitor.c +++ b/qapi/string-output-visitor.c @@ -258,7 +258,7 @@ static bool print_type_number(Visitor *v, const char *n= ame, double *obj, Error **errp) { StringOutputVisitor *sov =3D to_sov(v); - string_output_set(sov, g_strdup_printf("%f", *obj)); + string_output_set(sov, g_strdup_printf("%.17g", *obj)); return true; } =20 diff --git a/tests/test-string-output-visitor.c b/tests/test-string-output-= visitor.c index cec20848ea..0dae04b960 100644 --- a/tests/test-string-output-visitor.c +++ b/tests/test-string-output-visitor.c @@ -136,7 +136,7 @@ static void test_visitor_out_number(TestOutputVisitorDa= ta *data, visit_type_number(data->ov, NULL, &value, &error_abort); =20 str =3D visitor_get(data); - g_assert_cmpstr(str, =3D=3D, "3.141593"); + g_assert_cmpstr(str, =3D=3D, "3.1415926535897931"); } =20 static void test_visitor_out_string(TestOutputVisitorData *data, --=20 2.26.2 From nobody Thu May 16 15:04:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608375540; cv=none; d=zohomail.com; s=zohoarc; b=F6D9Pt4ga7t7HdfYnp1rwUdOnepV5dHm07JFqv1BKCpLLi4mxyBTv4D6M2X5XHgvmA5uZmzcXmsAo6ACefIC5aqrc+f1W//tsZjlxlHMGzzNZ6gvQM9afbWvYHYJEwoOb61N2KsRoaplRjBzPWrAhL8kkO1YR0pOTYcM0SOrjV0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608375540; 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=nPIVjSxUGsDOCPCCiy6L+8h1RqgeJf+R/3CFuo4QFqc=; b=VUPCw0+mH6z3R1VJHYGElQnvHJC+ysh6089Di1mPmAJEC7IwerzpjC0y5yKXDvqcC+Lkt/PrpHvzx66xfIx0c1xB8dhhNrGy2+GRnAFxNpdxLFWAIVEFnRcFeU8jMiAKWjfmjAysTxDVNlT4YV7Y8bC/fRAvL85PVlx0RMpPdss= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1608375540566714.1531549874406; Sat, 19 Dec 2020 02:59:00 -0800 (PST) Received: from localhost ([::1]:50322 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqZwx-0001Tt-HM for importer@patchew.org; Sat, 19 Dec 2020 05:58:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50594) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZtm-0004e4-Hw for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:42 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:34260) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtj-0007EZ-I7 for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:42 -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-485-9x-8piyNMluzWHFHKXm6Lw-1; Sat, 19 Dec 2020 05:55:36 -0500 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 9AEF559; Sat, 19 Dec 2020 10:55:35 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6E48C10013C0; Sat, 19 Dec 2020 10:55:35 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 7873511275F5; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375338; 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=nPIVjSxUGsDOCPCCiy6L+8h1RqgeJf+R/3CFuo4QFqc=; b=atOyRx0DdOLv1BnRpKD9veUZBn5IcAWdiGmr57hyF8uNQSvDYwbXhyJ1EcHdE1bn4/FE3i ZUHa3jzac8hZA3eIu5JhnE0liu3TRPh2GZsw4Qapa+9g7qMhHU154oAhG06+rntJ8XVff9 JWd29KgIFakbv4QvN/liFPYLUrY3dnw= X-MC-Unique: 9x-8piyNMluzWHFHKXm6Lw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 12/33] test-visitor-serialization: Drop insufficient precision workaround Date: Sat, 19 Dec 2020 11:55:11 +0100 Message-Id: <20201219105532.1734134-13-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H3=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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Message-Id: <20201210161452.2813491-10-armbru@redhat.com> --- tests/test-visitor-serialization.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/tests/test-visitor-serialization.c b/tests/test-visitor-serial= ization.c index 12275e56d8..cf19924068 100644 --- a/tests/test-visitor-serialization.c +++ b/tests/test-visitor-serialization.c @@ -311,17 +311,7 @@ static void test_primitives(gconstpointer opaque) g_assert_cmpstr(pt->value.string, =3D=3D, pt_copy->value.string); g_free((char *)pt_copy->value.string); } else if (pt->type =3D=3D PTYPE_NUMBER) { - GString *double_expected =3D g_string_new(""); - GString *double_actual =3D g_string_new(""); - /* we serialize with %f for our reference visitors, so rather than= fuzzy - * floating math to test "equality", just compare the formatted va= lues - */ - g_string_printf(double_expected, "%.6f", pt->value.number); - g_string_printf(double_actual, "%.6f", pt_copy->value.number); - g_assert_cmpstr(double_actual->str, =3D=3D, double_expected->str); - - g_string_free(double_expected, true); - g_string_free(double_actual, true); + g_assert_cmpfloat(pt->value.number, =3D=3D, pt_copy->value.number); } else if (pt->type =3D=3D PTYPE_BOOLEAN) { g_assert_cmpint(!!pt->value.max, =3D=3D, !!pt->value.max); } else { @@ -703,10 +693,6 @@ static PrimitiveType pt_values[] =3D { .value.boolean =3D 0, }, /* number tests (double) */ - /* note: we format these to %.6f before comparing, since that's how - * we serialize them and it doesn't make sense to check precision - * beyond that. - */ { .description =3D "number_sanity1", .type =3D PTYPE_NUMBER, @@ -715,7 +701,7 @@ static PrimitiveType pt_values[] =3D { { .description =3D "number_sanity2", .type =3D PTYPE_NUMBER, - .value.number =3D 3.14159265, + .value.number =3D 3.141593, }, { .description =3D "number_min", --=20 2.26.2 From nobody Thu May 16 15:04:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608375936; cv=none; d=zohomail.com; s=zohoarc; b=CXfU6AlYL4ouWhKpT4//JR+SgBkAA3ZDI8DGtFkJsoKqPsZ/YCwq1zMSXcvbCRWU4Sl0lnJyvlm0ODa93VTXe00YInYrcCXCwau0REfBL1H8BeNdO7D59WwR3aPg/pOp9qUSBhIZPH5LvlnCMKnh1K3bjks2wIxJSI8UeR8djfc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608375936; 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=Ii4WQb618fIsVWU9QALhameaXEQIo8ubUzK6x31oRII=; b=kpbjucokDLU4eTIG2QZ5g+vd9oN2oeE20sa8JHjN8tmrMzmUyEqn+HAzrAfmfqleY4as0Onso6DVt1d10HUQJL+O53nWhpTYTsoDN1Ks36u5VkDUWzwnFstcwjBDzVhUtp9w5H5HNANiy3MiCsR8VaHzv44fxYqy0589R9yTMCg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1608375936057673.9201264412496; Sat, 19 Dec 2020 03:05:36 -0800 (PST) Received: from localhost ([::1]:39910 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqa3K-0000Vd-Tb for importer@patchew.org; Sat, 19 Dec 2020 06:05:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50694) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZtq-0004mg-UV for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:46 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:46971) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtl-0007Gb-7h for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:46 -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-69-Fdd0AZuzOyKAFvCP23Vgsw-1; Sat, 19 Dec 2020 05:55:37 -0500 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 DB68851B6; Sat, 19 Dec 2020 10:55:36 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ADDFE10013C0; Sat, 19 Dec 2020 10:55:36 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 818BD11275FF; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375340; 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=Ii4WQb618fIsVWU9QALhameaXEQIo8ubUzK6x31oRII=; b=Z8D9KJtSfsBP/mMkONqE6cYKhQqTgioQ4MihfMrtrkEn8dehFFgniK1E6gS+RYYmQsFxhv P2eHM8sQlAnFWybBXusci3UmyAqPHtisG0GFa3H+YtsZTco6n3rCooyzn5IzRzQhBEQfri DGD0xKsfP78SpVqBLHPU3LBg1C1FDls= X-MC-Unique: Fdd0AZuzOyKAFvCP23Vgsw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 13/33] test-visitor-serialization: Clean up test_primitives() Date: Sat, 19 Dec 2020 11:55:12 +0100 Message-Id: <20201219105532.1734134-14-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H3=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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" test_primitives() uses union member intmax_t max to compare the integer members. Unspecified behavior. Has worked fine for many years, though. Clean it up. Signed-off-by: Markus Armbruster Message-Id: <20201210161452.2813491-11-armbru@redhat.com> --- tests/test-visitor-serialization.c | 44 +++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/tests/test-visitor-serialization.c b/tests/test-visitor-serial= ization.c index cf19924068..dfe120a50d 100644 --- a/tests/test-visitor-serialization.c +++ b/tests/test-visitor-serialization.c @@ -55,7 +55,6 @@ typedef struct PrimitiveType { int16_t s16; int32_t s32; int64_t s64; - intmax_t max; } value; enum PrimitiveTypeKind type; const char *description; @@ -307,15 +306,46 @@ static void test_primitives(gconstpointer opaque) &error_abort); =20 g_assert(pt_copy !=3D NULL); - if (pt->type =3D=3D PTYPE_STRING) { + switch (pt->type) { + case PTYPE_STRING: g_assert_cmpstr(pt->value.string, =3D=3D, pt_copy->value.string); g_free((char *)pt_copy->value.string); - } else if (pt->type =3D=3D PTYPE_NUMBER) { + break; + case PTYPE_BOOLEAN: + g_assert_cmpint(pt->value.boolean, =3D=3D, pt->value.boolean); + break; + case PTYPE_NUMBER: g_assert_cmpfloat(pt->value.number, =3D=3D, pt_copy->value.number); - } else if (pt->type =3D=3D PTYPE_BOOLEAN) { - g_assert_cmpint(!!pt->value.max, =3D=3D, !!pt->value.max); - } else { - g_assert_cmpint(pt->value.max, =3D=3D, pt_copy->value.max); + break; + case PTYPE_INTEGER: + g_assert_cmpint(pt->value.integer, =3D=3D, pt_copy->value.integer); + break; + case PTYPE_U8: + g_assert_cmpuint(pt->value.u8, =3D=3D, pt_copy->value.u8); + break; + case PTYPE_U16: + g_assert_cmpuint(pt->value.u16, =3D=3D, pt_copy->value.u16); + break; + case PTYPE_U32: + g_assert_cmpuint(pt->value.u32, =3D=3D, pt_copy->value.u32); + break; + case PTYPE_U64: + g_assert_cmpuint(pt->value.u64, =3D=3D, pt_copy->value.u64); + break; + case PTYPE_S8: + g_assert_cmpint(pt->value.s8, =3D=3D, pt_copy->value.s8); + break; + case PTYPE_S16: + g_assert_cmpint(pt->value.s16, =3D=3D, pt_copy->value.s16); + break; + case PTYPE_S32: + g_assert_cmpint(pt->value.s32, =3D=3D, pt_copy->value.s32); + break; + case PTYPE_S64: + g_assert_cmpint(pt->value.s64, =3D=3D, pt_copy->value.s64); + break; + case PTYPE_EOL: + g_assert_not_reached(); } =20 ops->cleanup(serialize_data); --=20 2.26.2 From nobody Thu May 16 15:04:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608376188; cv=none; d=zohomail.com; s=zohoarc; b=KFrYjzlVuVVLEWb+fjFgpe7j1OP/nidGkOKlnwZvOLCjYUz8S1azyQ7yz0xGGC8J/R4wIfjE2yrge6mi6ZgyIdxYHGljsX30werSQ2cTniz9R+I6HZ/2sZ+Mo6Z2IanWgCBXwl39O3JYkei9/Ly8Zt6va6MLS39hMzUKLRvkcnM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608376188; 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=1KYwEpAPrt3ArSPA+Bhqpfo1OJ8m+fTgasqNMiqO+LQ=; b=P7ov4Ep8QKvnN5h426oLsacWLk55mRiJ5t7NqmEKoLKg8rG5Asa0Q/1KkTgDvLdIcMYeMgdYx5SCvBs5G8bp2Zdmb/YZ2WgG5WSBfGBgdP+kr97YCzJvWjaELCU7KqWm6bUWpMC0oM/zaETuyCYczrXwdgir6ARq3VTbZDuYM/0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1608376188637209.79442544602546; Sat, 19 Dec 2020 03:09:48 -0800 (PST) Received: from localhost ([::1]:56454 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqa7P-0007Fu-Hx for importer@patchew.org; Sat, 19 Dec 2020 06:09:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50840) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZtx-00057b-SM for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:45305) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtm-0007IG-V7 for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:53 -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-127-lff89r2gOFWkw44Jr6DFog-1; Sat, 19 Dec 2020 05:55:37 -0500 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 DBA64801A9D; Sat, 19 Dec 2020 10:55:36 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AE34610016FB; Sat, 19 Dec 2020 10:55:36 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 87940112688E; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375342; 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=1KYwEpAPrt3ArSPA+Bhqpfo1OJ8m+fTgasqNMiqO+LQ=; b=URZ6xTBpCI8sWu51lhFyn55nwX3PIZdTDhOQ7Ose6UBaszsFD0S7+lIaw0xA6sNGvgdUgl EsWFsTvb/sxwovKkcqN6RkQSxT8gNam37AovxZwls60gY5REoQJ91To8cq4XvuV6FXiWJ2 w5O2jIj3Vc/YLWnuW6VVngvKATob0Fo= X-MC-Unique: lff89r2gOFWkw44Jr6DFog-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 14/33] hmp: Simplify how qmp_human_monitor_command() gets output Date: Sat, 19 Dec 2020 11:55:13 +0100 Message-Id: <20201219105532.1734134-15-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H3=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: peter.maydell@linaro.org, "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Commit 48c043d0d1 "hmp: human-monitor-command: stop using the Memory chardev driver" left us "if string is non-empty, duplicate it, else duplicate the empty string". Meh. Duplicate it unconditionally. Cc: Dr. David Alan Gilbert Signed-off-by: Markus Armbruster Message-Id: <20201211171152.146877-2-armbru@redhat.com> Reviewed-by: Dr. David Alan Gilbert --- monitor/misc.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/monitor/misc.c b/monitor/misc.c index f2ee7cd77a..33d0dae2e8 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -136,11 +136,7 @@ char *qmp_human_monitor_command(const char *command_li= ne, bool has_cpu_index, handle_hmp_command(&hmp, command_line); =20 WITH_QEMU_LOCK_GUARD(&hmp.common.mon_lock) { - if (qstring_get_length(hmp.common.outbuf) > 0) { - output =3D g_strdup(qstring_get_str(hmp.common.outbuf)); - } else { - output =3D g_strdup(""); - } + output =3D g_strdup(qstring_get_str(hmp.common.outbuf)); } =20 out: --=20 2.26.2 From nobody Thu May 16 15:04:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608376069; cv=none; d=zohomail.com; s=zohoarc; b=hV7ltoKaKwriJT/EVUzSQzLZqFNOBSHbieTsZC7wtpXWfhsYH5wVSOsoWqR3X1k5QGjPDz3bkpoC7g60opaa14cmtNd6iUhh6Y+fWaozMPoVnhT2SlgryhvcQQWcplZfRzRayrIn26xWUpxbFhJhMxy7Ji7fEezIWAuQ+JsQZoE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608376069; 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=SqszXK3OLbu9tC4hbDtYV25ppD/DArFagYR6z5JaLtg=; b=GtW0oHl+7/bZ6UNG+9LBYm1OmandldFiJEocNstRRUHV4KnVo5g+bpDJGWkPoC+RabJ9ARzQTiLQQI2uzKramEPmd3Sz1P1dDZ/MEnuILpsJPQzTz30mY3hhCxIOAD6VmVMTcVJsbwXbqcI6vLC+YxFF0As4y4B72NZkv3F7BYc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1608376069444339.01537326310756; Sat, 19 Dec 2020 03:07:49 -0800 (PST) Received: from localhost ([::1]:47922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqa5U-0003my-BR for importer@patchew.org; Sat, 19 Dec 2020 06:07:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50740) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZts-0004rj-Nb for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:48 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:44799) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtk-0007GL-IE for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:48 -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-25-2J0NSGNlPUmxJG2lDJH4bA-1; Sat, 19 Dec 2020 05:55:37 -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 DDCF8800D53; Sat, 19 Dec 2020 10:55:36 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AE83F5D9C2; Sat, 19 Dec 2020 10:55:36 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 8C8D81126895; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375340; 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=SqszXK3OLbu9tC4hbDtYV25ppD/DArFagYR6z5JaLtg=; b=AkXYj153ceIkVT8cEbpTXe4KEHbo7L2bJpkxYgKX6JGW39XJRh3VTMOUpEIjSBUzh1ejhj pPkFTKpR3gexrTDJ57Q59DAXOufAGaCzDV1U0TmX/MzRMfSBXa7lOj1My59ai4jreeXxuD UOhsWcfcPjgxZ7fofDVnPTtHSDjUEsY= X-MC-Unique: 2J0NSGNlPUmxJG2lDJH4bA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 15/33] monitor: Use GString instead of QString for output buffer Date: Sat, 19 Dec 2020 11:55:14 +0100 Message-Id: <20201219105532.1734134-16-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 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: peter.maydell@linaro.org, "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" GString has a richer set of string operations than QString. It should be preferred to QString except where we need a QObject or reference counting. We don't here. Switch to GString, and put its richer interface to use. Cc: Dr. David Alan Gilbert Signed-off-by: Markus Armbruster Message-Id: <20201211171152.146877-3-armbru@redhat.com> Reviewed-by: Dr. David Alan Gilbert --- monitor/monitor-internal.h | 2 +- monitor/misc.c | 2 +- monitor/monitor.c | 20 ++++++++------------ 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index a6131554da..40903d6386 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -105,7 +105,7 @@ struct Monitor { * Members that are protected by the per-monitor lock */ QLIST_HEAD(, mon_fd_t) fds; - QString *outbuf; + GString *outbuf; guint out_watch; /* Read under either BQL or mon_lock, written with BQL+mon_lock. */ int mux_out; diff --git a/monitor/misc.c b/monitor/misc.c index 33d0dae2e8..10444b4e7a 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -136,7 +136,7 @@ char *qmp_human_monitor_command(const char *command_lin= e, bool has_cpu_index, handle_hmp_command(&hmp, command_line); =20 WITH_QEMU_LOCK_GUARD(&hmp.common.mon_lock) { - output =3D g_strdup(qstring_get_str(hmp.common.outbuf)); + output =3D g_strdup(hmp.common.outbuf->str); } =20 out: diff --git a/monitor/monitor.c b/monitor/monitor.c index 84222cd130..1e4a6b3f20 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -29,7 +29,6 @@ #include "qapi/qapi-emit-events.h" #include "qapi/qapi-visit-control.h" #include "qapi/qmp/qdict.h" -#include "qapi/qmp/qstring.h" #include "qemu/error-report.h" #include "qemu/option.h" #include "sysemu/qtest.h" @@ -181,22 +180,19 @@ static void monitor_flush_locked(Monitor *mon) return; } =20 - buf =3D qstring_get_str(mon->outbuf); - len =3D qstring_get_length(mon->outbuf); + buf =3D mon->outbuf->str; + len =3D mon->outbuf->len; =20 if (len && !mon->mux_out) { rc =3D qemu_chr_fe_write(&mon->chr, (const uint8_t *) buf, len); if ((rc < 0 && errno !=3D EAGAIN) || (rc =3D=3D len)) { /* all flushed or error */ - qobject_unref(mon->outbuf); - mon->outbuf =3D qstring_new(); + g_string_truncate(mon->outbuf, 0); return; } if (rc > 0) { /* partial write */ - QString *tmp =3D qstring_from_str(buf + rc); - qobject_unref(mon->outbuf); - mon->outbuf =3D tmp; + g_string_erase(mon->outbuf, 0, rc); } if (mon->out_watch =3D=3D 0) { mon->out_watch =3D @@ -223,9 +219,9 @@ int monitor_puts(Monitor *mon, const char *str) for (i =3D 0; str[i]; i++) { c =3D str[i]; if (c =3D=3D '\n') { - qstring_append_chr(mon->outbuf, '\r'); + g_string_append_c(mon->outbuf, '\r'); } - qstring_append_chr(mon->outbuf, c); + g_string_append_c(mon->outbuf, c); if (c =3D=3D '\n') { monitor_flush_locked(mon); } @@ -602,7 +598,7 @@ void monitor_data_init(Monitor *mon, bool is_qmp, bool = skip_flush, } qemu_mutex_init(&mon->mon_lock); mon->is_qmp =3D is_qmp; - mon->outbuf =3D qstring_new(); + mon->outbuf =3D g_string_new(NULL); mon->skip_flush =3D skip_flush; mon->use_io_thread =3D use_io_thread; } @@ -616,7 +612,7 @@ void monitor_data_destroy(Monitor *mon) } else { readline_free(container_of(mon, MonitorHMP, common)->rs); } - qobject_unref(mon->outbuf); + g_string_free(mon->outbuf, true); qemu_mutex_destroy(&mon->mon_lock); } =20 --=20 2.26.2 From nobody Thu May 16 15:04:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608375736; cv=none; d=zohomail.com; s=zohoarc; b=JGE5qIQgelxwhAQ4J95iiZDe+kn+izxYeU4fFCF2SSUolt7AtUFn2Dr09QmhA1lHmghl1AdXQyWQrdsYMtc3vrcoWvCrn5TVmLNnxhND/Ihckg/YxDmxXJpjgHWTSRGzdiC38N6QWUEP4Houcef/ZQBR1QbWZiIJqm8KtmeehEQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608375736; 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=CSR8pLDsCVa+LOllTgMzAE5XMpBg9MNk2R2Ap0rd4Jo=; b=D5I4lnzSosT/OKZklBDdWKUhAdvp4kMm+N+pA6iG4FmZ9kvZNHkvbDOSwx7ZB66IMrYs85qYrs7BPdJFSRdNRGE2yf1JTDKEf5RSOy+PqyuMgIXyviLyDS8eiNqoqIGF/cGSTC9wtxJNOcGb2ESJE5E84WUhM2v5iWhnJVS7PgU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1608375736673396.82638151119795; Sat, 19 Dec 2020 03:02:16 -0800 (PST) Received: from localhost ([::1]:58804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqa07-00053B-Gc for importer@patchew.org; Sat, 19 Dec 2020 06:02:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50690) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZtq-0004mB-Om for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:46 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:39087) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtl-0007GT-1F for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:46 -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-68-aW5r6wddOp6QRHQ8_tQa9Q-1; Sat, 19 Dec 2020 05:55:38 -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 0E47B800D55; Sat, 19 Dec 2020 10:55:37 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AFC6457; Sat, 19 Dec 2020 10:55:36 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 916811126898; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375340; 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=CSR8pLDsCVa+LOllTgMzAE5XMpBg9MNk2R2Ap0rd4Jo=; b=hisIbMOskWTx0nwqSxHHR4FptIg5Hp4bPeENfTzZKzrjXcrhLEHb9AwwZcKD/tQgztqLl5 to3mhbcQqzV1Hzfk4D6NfmQOZkwWLgy2JnHnIRKNqQSNg+Y4AnV6RqZAwAzRhH5fhhyyan kF1RFPlP17wLhUiDv6CzEaOlaPjHiNE= X-MC-Unique: aW5r6wddOp6QRHQ8_tQa9Q-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 16/33] qobject: Make qobject_to_json_pretty() take a pretty argument Date: Sat, 19 Dec 2020 11:55:15 +0100 Message-Id: <20201219105532.1734134-17-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Message-Id: <20201211171152.146877-4-armbru@redhat.com> --- include/qapi/qmp/qjson.h | 2 +- monitor/qmp.c | 2 +- qemu-img.c | 8 ++++---- qobject/qjson.c | 28 +++++++++++----------------- qom/qom-hmp-cmds.c | 2 +- tests/qtest/libqtest.c | 2 +- 6 files changed, 19 insertions(+), 25 deletions(-) diff --git a/include/qapi/qmp/qjson.h b/include/qapi/qmp/qjson.h index 5ebbe5a118..82f4534f16 100644 --- a/include/qapi/qmp/qjson.h +++ b/include/qapi/qmp/qjson.h @@ -26,6 +26,6 @@ QDict *qdict_from_jsonf_nofail(const char *string, ...) GCC_FMT_ATTR(1, 2); =20 QString *qobject_to_json(const QObject *obj); -QString *qobject_to_json_pretty(const QObject *obj); +QString *qobject_to_json_pretty(const QObject *obj, bool pretty); =20 #endif /* QJSON_H */ diff --git a/monitor/qmp.c b/monitor/qmp.c index b42f8c6af3..1197c50b20 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -112,7 +112,7 @@ void qmp_send_response(MonitorQMP *mon, const QDict *rs= p) const QObject *data =3D QOBJECT(rsp); QString *json; =20 - json =3D mon->pretty ? qobject_to_json_pretty(data) : qobject_to_json(= data); + json =3D qobject_to_json_pretty(data, mon->pretty); assert(json !=3D NULL); =20 qstring_append_chr(json, '\n'); diff --git a/qemu-img.c b/qemu-img.c index d599659c7f..1a59dfd3f3 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -633,7 +633,7 @@ static void dump_json_image_check(ImageCheck *check, bo= ol quiet) =20 visit_type_ImageCheck(v, NULL, &check, &error_abort); visit_complete(v, &obj); - str =3D qobject_to_json_pretty(obj); + str =3D qobject_to_json_pretty(obj, true); assert(str !=3D NULL); qprintf(quiet, "%s\n", qstring_get_str(str)); qobject_unref(obj); @@ -2795,7 +2795,7 @@ static void dump_json_image_info_list(ImageInfoList *= list) =20 visit_type_ImageInfoList(v, NULL, &list, &error_abort); visit_complete(v, &obj); - str =3D qobject_to_json_pretty(obj); + str =3D qobject_to_json_pretty(obj, true); assert(str !=3D NULL); printf("%s\n", qstring_get_str(str)); qobject_unref(obj); @@ -2811,7 +2811,7 @@ static void dump_json_image_info(ImageInfo *info) =20 visit_type_ImageInfo(v, NULL, &info, &error_abort); visit_complete(v, &obj); - str =3D qobject_to_json_pretty(obj); + str =3D qobject_to_json_pretty(obj, true); assert(str !=3D NULL); printf("%s\n", qstring_get_str(str)); qobject_unref(obj); @@ -5242,7 +5242,7 @@ static void dump_json_block_measure_info(BlockMeasure= Info *info) =20 visit_type_BlockMeasureInfo(v, NULL, &info, &error_abort); visit_complete(v, &obj); - str =3D qobject_to_json_pretty(obj); + str =3D qobject_to_json_pretty(obj, true); assert(str !=3D NULL); printf("%s\n", qstring_get_str(str)); qobject_unref(obj); diff --git a/qobject/qjson.c b/qobject/qjson.c index f1f2c69704..523a4ab8de 100644 --- a/qobject/qjson.c +++ b/qobject/qjson.c @@ -149,8 +149,6 @@ QDict *qdict_from_jsonf_nofail(const char *string, ...) return qdict; } =20 -static void to_json(const QObject *obj, QString *str, int pretty, int inde= nt); - static void json_pretty_newline(QString *str, bool pretty, int indent) { int i; @@ -163,7 +161,7 @@ static void json_pretty_newline(QString *str, bool pret= ty, int indent) } } =20 -static void to_json(const QObject *obj, QString *str, int pretty, int inde= nt) +static void to_json(const QObject *obj, QString *str, bool pretty, int ind= ent) { switch (qobject_type(obj)) { case QTYPE_QNULL: @@ -294,20 +292,16 @@ static void to_json(const QObject *obj, QString *str,= int pretty, int indent) } } =20 +QString *qobject_to_json_pretty(const QObject *obj, bool pretty) +{ + QString *str =3D qstring_new(); + + to_json(obj, str, pretty, 0); + + return str; +} + QString *qobject_to_json(const QObject *obj) { - QString *str =3D qstring_new(); - - to_json(obj, str, 0, 0); - - return str; -} - -QString *qobject_to_json_pretty(const QObject *obj) -{ - QString *str =3D qstring_new(); - - to_json(obj, str, 1, 0); - - return str; + return qobject_to_json_pretty(obj, false); } diff --git a/qom/qom-hmp-cmds.c b/qom/qom-hmp-cmds.c index 8861a109d5..6b96dbe906 100644 --- a/qom/qom-hmp-cmds.c +++ b/qom/qom-hmp-cmds.c @@ -78,7 +78,7 @@ void hmp_qom_get(Monitor *mon, const QDict *qdict) QObject *obj =3D qmp_qom_get(path, property, &err); =20 if (err =3D=3D NULL) { - QString *str =3D qobject_to_json_pretty(obj); + QString *str =3D qobject_to_json_pretty(obj, true); monitor_printf(mon, "%s\n", qstring_get_str(str)); qobject_unref(str); } diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index e49f3a1e45..213fa4f8fe 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -1197,7 +1197,7 @@ void qtest_qmp_assert_success(QTestState *qts, const = char *fmt, ...) =20 g_assert(response); if (!qdict_haskey(response, "return")) { - QString *s =3D qobject_to_json_pretty(QOBJECT(response)); + QString *s =3D qobject_to_json_pretty(QOBJECT(response), true); g_test_message("%s", qstring_get_str(s)); qobject_unref(s); } --=20 2.26.2 From nobody Thu May 16 15:04:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608376643; cv=none; d=zohomail.com; s=zohoarc; b=JGx7LJiHH5pv45r1C1KYL67kaZfgi8BKz9JcaqYRyxLpqtC63Jx3qxv/xgru/GX4E+Dbon6hRgqxRVE0JxDOx0C5XJRvH0J+GMlwbHQA6cypaXTfcY8ywuHuxHh8WXf2dAeeW7BvX2Ffptz2uEP3rlu/NfOEfUnuVCNlODx7sPw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608376643; 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=7Hs3PGoZh0v0zR7IwkDHO5aktik6Neq5GXl8cVdPi9U=; b=kayFTVLRQ9jxI800R5YE47T8eOqrd0yMADzuXXO9LPy1y26AeN1Ytb0ZKaU3F1ZdYGs21Vwm9xBKuy6KNNOVvQtLmz+A6LSC4l+4dPUVEzTVWaVMrQb58h3iQmc/O0oRMbja840bNBVYZLDqVGOcAqakWHRkNnSvOKLv50nOCng= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1608376643457208.10941294930478; Sat, 19 Dec 2020 03:17:23 -0800 (PST) Received: from localhost ([::1]:49908 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqaEk-00081i-AI for importer@patchew.org; Sat, 19 Dec 2020 06:17:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50870) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZtz-0005Du-J7 for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:55 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:60588) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtn-0007IQ-91 for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:55 -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-127-9U8obTYMMh6JZO1JIh-NtQ-1; Sat, 19 Dec 2020 05:55:38 -0500 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 16B9A8015C6; Sat, 19 Dec 2020 10:55:37 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B63392DACE; Sat, 19 Dec 2020 10:55:36 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 967161126899; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375342; 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=7Hs3PGoZh0v0zR7IwkDHO5aktik6Neq5GXl8cVdPi9U=; b=GqXJyFLsWu3OCilCp/JEZ26JVoNh1+5D3VzHTgbjcmjZ/sOObDXDsleGpWyRL/5R4MoJg5 t4RVC2gAijKSZQHlxOsN+QUvGmj+DFe2HlAUOGkW0wQUx28wDvLocTjUXbgwiO2asWFGX+ ZcsbLRVK0jtfPRAtCMVjxjlJGWY9XC8= X-MC-Unique: 9U8obTYMMh6JZO1JIh-NtQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 17/33] qobject: Use GString instead of QString to accumulate JSON Date: Sat, 19 Dec 2020 11:55:16 +0100 Message-Id: <20201219105532.1734134-18-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H3=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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" QString supports modifying its string, but it's quite limited: you can only append. The remaining callers use it for building an initial string, never for modifying it later. Use of GString for building the initial string is actually more convenient here. Change qobject_to_json() & friends to do that. Once all such uses are replaced this way, QString can become immutable. Signed-off-by: Markus Armbruster Message-Id: <20201211171152.146877-5-armbru@redhat.com> --- include/qapi/qmp/qstring.h | 1 + qobject/qjson.c | 85 +++++++++++++++++--------------------- qobject/qstring.c | 19 +++++++++ 3 files changed, 58 insertions(+), 47 deletions(-) diff --git a/include/qapi/qmp/qstring.h b/include/qapi/qmp/qstring.h index e2e356e5e7..ae7698d6c7 100644 --- a/include/qapi/qmp/qstring.h +++ b/include/qapi/qmp/qstring.h @@ -25,6 +25,7 @@ struct QString { QString *qstring_new(void); QString *qstring_from_str(const char *str); QString *qstring_from_substr(const char *str, size_t start, size_t end); +QString *qstring_from_gstring(GString *gstr); size_t qstring_get_length(const QString *qstring); const char *qstring_get_str(const QString *qstring); const char *qstring_get_try_str(const QString *qstring); diff --git a/qobject/qjson.c b/qobject/qjson.c index 523a4ab8de..e7100a539c 100644 --- a/qobject/qjson.c +++ b/qobject/qjson.c @@ -149,28 +149,23 @@ QDict *qdict_from_jsonf_nofail(const char *string, ..= .) return qdict; } =20 -static void json_pretty_newline(QString *str, bool pretty, int indent) +static void json_pretty_newline(GString *accu, bool pretty, int indent) { - int i; - if (pretty) { - qstring_append(str, "\n"); - for (i =3D 0; i < indent; i++) { - qstring_append(str, " "); - } + g_string_append_printf(accu, "\n%*s", indent * 4, ""); } } =20 -static void to_json(const QObject *obj, QString *str, bool pretty, int ind= ent) +static void to_json(const QObject *obj, GString *accu, bool pretty, int in= dent) { switch (qobject_type(obj)) { case QTYPE_QNULL: - qstring_append(str, "null"); + g_string_append(accu, "null"); break; case QTYPE_QNUM: { QNum *val =3D qobject_to(QNum, obj); char *buffer =3D qnum_to_string(val); - qstring_append(str, buffer); + g_string_append(accu, buffer); g_free(buffer); break; } @@ -178,35 +173,34 @@ static void to_json(const QObject *obj, QString *str,= bool pretty, int indent) QString *val =3D qobject_to(QString, obj); const char *ptr; int cp; - char buf[16]; char *end; =20 ptr =3D qstring_get_str(val); - qstring_append(str, "\""); + g_string_append_c(accu, '"'); =20 for (; *ptr; ptr =3D end) { cp =3D mod_utf8_codepoint(ptr, 6, &end); switch (cp) { case '\"': - qstring_append(str, "\\\""); + g_string_append(accu, "\\\""); break; case '\\': - qstring_append(str, "\\\\"); + g_string_append(accu, "\\\\"); break; case '\b': - qstring_append(str, "\\b"); + g_string_append(accu, "\\b"); break; case '\f': - qstring_append(str, "\\f"); + g_string_append(accu, "\\f"); break; case '\n': - qstring_append(str, "\\n"); + g_string_append(accu, "\\n"); break; case '\r': - qstring_append(str, "\\r"); + g_string_append(accu, "\\r"); break; case '\t': - qstring_append(str, "\\t"); + g_string_append(accu, "\\t"); break; default: if (cp < 0) { @@ -214,20 +208,18 @@ static void to_json(const QObject *obj, QString *str,= bool pretty, int indent) } if (cp > 0xFFFF) { /* beyond BMP; need a surrogate pair */ - snprintf(buf, sizeof(buf), "\\u%04X\\u%04X", - 0xD800 + ((cp - 0x10000) >> 10), - 0xDC00 + ((cp - 0x10000) & 0x3FF)); + g_string_append_printf(accu, "\\u%04X\\u%04X", + 0xD800 + ((cp - 0x10000) >> 10), + 0xDC00 + ((cp - 0x10000) & 0x3F= F)); } else if (cp < 0x20 || cp >=3D 0x7F) { - snprintf(buf, sizeof(buf), "\\u%04X", cp); + g_string_append_printf(accu, "\\u%04X", cp); } else { - buf[0] =3D cp; - buf[1] =3D 0; + g_string_append_c(accu, cp); } - qstring_append(str, buf); } }; =20 - qstring_append(str, "\""); + g_string_append_c(accu, '"'); break; } case QTYPE_QDICT: { @@ -237,25 +229,25 @@ static void to_json(const QObject *obj, QString *str,= bool pretty, int indent) const QDictEntry *entry; QString *qkey; =20 - qstring_append(str, "{"); + g_string_append_c(accu, '{'); =20 for (entry =3D qdict_first(val); entry; entry =3D qdict_next(val, entry)) { - qstring_append(str, sep); - json_pretty_newline(str, pretty, indent + 1); + g_string_append(accu, sep); + json_pretty_newline(accu, pretty, indent + 1); =20 qkey =3D qstring_from_str(qdict_entry_key(entry)); - to_json(QOBJECT(qkey), str, pretty, indent + 1); + to_json(QOBJECT(qkey), accu, pretty, indent + 1); qobject_unref(qkey); =20 - qstring_append(str, ": "); - to_json(qdict_entry_value(entry), str, pretty, indent + 1); + g_string_append(accu, ": "); + to_json(qdict_entry_value(entry), accu, pretty, indent + 1); sep =3D comma; } =20 - json_pretty_newline(str, pretty, indent); - qstring_append(str, "}"); + json_pretty_newline(accu, pretty, indent); + g_string_append_c(accu, '}'); break; } case QTYPE_QLIST: { @@ -264,26 +256,26 @@ static void to_json(const QObject *obj, QString *str,= bool pretty, int indent) const char *sep =3D ""; QListEntry *entry; =20 - qstring_append(str, "["); + g_string_append_c(accu, '['); =20 QLIST_FOREACH_ENTRY(val, entry) { - qstring_append(str, sep); - json_pretty_newline(str, pretty, indent + 1); - to_json(qlist_entry_obj(entry), str, pretty, indent + 1); + g_string_append(accu, sep); + json_pretty_newline(accu, pretty, indent + 1); + to_json(qlist_entry_obj(entry), accu, pretty, indent + 1); sep =3D comma; } =20 - json_pretty_newline(str, pretty, indent); - qstring_append(str, "]"); + json_pretty_newline(accu, pretty, indent); + g_string_append_c(accu, ']'); break; } case QTYPE_QBOOL: { QBool *val =3D qobject_to(QBool, obj); =20 if (qbool_get_bool(val)) { - qstring_append(str, "true"); + g_string_append(accu, "true"); } else { - qstring_append(str, "false"); + g_string_append(accu, "false"); } break; } @@ -294,11 +286,10 @@ static void to_json(const QObject *obj, QString *str,= bool pretty, int indent) =20 QString *qobject_to_json_pretty(const QObject *obj, bool pretty) { - QString *str =3D qstring_new(); + GString *accu =3D g_string_new(NULL); =20 - to_json(obj, str, pretty, 0); - - return str; + to_json(obj, accu, pretty, 0); + return qstring_from_gstring(accu); } =20 QString *qobject_to_json(const QObject *obj) diff --git a/qobject/qstring.c b/qobject/qstring.c index b66a2c35f2..af7c18ca73 100644 --- a/qobject/qstring.c +++ b/qobject/qstring.c @@ -66,6 +66,25 @@ QString *qstring_from_str(const char *str) return qstring_from_substr(str, 0, strlen(str)); } =20 +/** + * qstring_from_gstring(): Convert a GString to a QString + * + * Return strong reference. + */ + +QString *qstring_from_gstring(GString *gstr) +{ + QString *qstring; + + qstring =3D g_malloc(sizeof(*qstring)); + qobject_init(QOBJECT(qstring), QTYPE_QSTRING); + qstring->length =3D gstr->len; + qstring->capacity =3D gstr->allocated_len; + qstring->string =3D g_string_free(gstr, false); + return qstring; +} + + static void capacity_increase(QString *qstring, size_t len) { if (qstring->capacity < (qstring->length + len)) { --=20 2.26.2 From nobody Thu May 16 15:04:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608376486; cv=none; d=zohomail.com; s=zohoarc; b=aogwbM1aZSlTUyus4cZzaty/BpaGFKJ2AtZPuDkqt8Jl0IiCCZY0/TwuDCqCp6uhni1EeZ/e7GFNTSwybbn8yaru1qlIlvUa9Ta9bKzZI4zKanxQRVQwSKvnlkU/ZNQfjSxgP0aTG5wD9gSb24nNXIcs3iQ6yrGaZtHuCGkoN3I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608376486; 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=SIpzOs0Qi4hAUrYR57wbXh4KnjXI7OZjtx3Q89JwTyM=; b=Xj8KfZ5oUnwPbEz3cd+Jqpq10hMC11P0t8ylHX/cdbtN6ALVy45ejVQ3ujIYUdnL32qqC8WqRN8M/mnJQ1GcFMDXhROlPZzMt0+9FDl8+xZIsR1mKy1wOllQe1/60GRWd3slIf+XWewgLw3aF2u4q1+QsuyRZVaV1W7YSrg6uDw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1608376486191626.8250641662197; Sat, 19 Dec 2020 03:14:46 -0800 (PST) Received: from localhost ([::1]:43742 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqaCC-0005M2-Tj for importer@patchew.org; Sat, 19 Dec 2020 06:14:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50848) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZty-00058a-6o for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:28648) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtl-0007Hc-Ku for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:53 -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-491-7dj6eS17NteZhXet5EroBg-1; Sat, 19 Dec 2020 05:55:38 -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 3C47C107ACF7; Sat, 19 Dec 2020 10:55:37 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B734B5884C; Sat, 19 Dec 2020 10:55:36 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 9BD1E112689A; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375340; 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=SIpzOs0Qi4hAUrYR57wbXh4KnjXI7OZjtx3Q89JwTyM=; b=ErrlxzUyS5H+ei4yYaEsl00aLY8rA+9esunDPHmPUey02LPr1UWUoaSzF67rMQy21CCnG2 Jdx/nyNMac2VwDl4hYJ2pG2Rzv3WLZCo1mDikC4rvgboWFufiDFM6UYBTrbzBxSEF6QbiG xEhIzUlHLMS/BIcbuTkGYlUwuVxEvOI= X-MC-Unique: 7dj6eS17NteZhXet5EroBg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 18/33] qobject: Change qobject_to_json()'s value to GString Date: Sat, 19 Dec 2020 11:55:17 +0100 Message-Id: <20201219105532.1734134-19-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H3=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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" qobject_to_json() and qobject_to_json_pretty() build a GString, then covert it to QString. Just one of the callers actually needs a QString: qemu_rbd_parse_filename(). A few others need a string they can modify: qmp_send_response(), qga's send_response(), to_json_str(), and qmp_fd_vsend_fds(). The remainder just need a string. Change qobject_to_json() and qobject_to_json_pretty() to return the GString. qemu_rbd_parse_filename() now has to convert to QString. All others save a QString temporary. to_json_str() actually becomes a bit simpler, because GString provides more convenient modification functions. Signed-off-by: Markus Armbruster Message-Id: <20201211171152.146877-6-armbru@redhat.com> --- include/qapi/qmp/qjson.h | 4 +-- block.c | 6 ++-- block/rbd.c | 2 +- monitor/qmp.c | 14 ++++---- qemu-img.c | 25 +++++++------ qga/main.c | 22 ++++-------- qobject/qjson.c | 6 ++-- qom/object_interfaces.c | 4 +-- qom/qom-hmp-cmds.c | 7 ++-- tests/check-qjson.c | 56 ++++++++++++++---------------- tests/qtest/libqtest.c | 20 +++++------ tests/test-visitor-serialization.c | 6 ++-- 12 files changed, 79 insertions(+), 93 deletions(-) diff --git a/include/qapi/qmp/qjson.h b/include/qapi/qmp/qjson.h index 82f4534f16..593b40b4e0 100644 --- a/include/qapi/qmp/qjson.h +++ b/include/qapi/qmp/qjson.h @@ -25,7 +25,7 @@ QDict *qdict_from_vjsonf_nofail(const char *string, va_li= st ap) QDict *qdict_from_jsonf_nofail(const char *string, ...) GCC_FMT_ATTR(1, 2); =20 -QString *qobject_to_json(const QObject *obj); -QString *qobject_to_json_pretty(const QObject *obj, bool pretty); +GString *qobject_to_json(const QObject *obj); +GString *qobject_to_json_pretty(const QObject *obj, bool pretty); =20 #endif /* QJSON_H */ diff --git a/block.c b/block.c index 8f177504d4..09d4c6bd25 100644 --- a/block.c +++ b/block.c @@ -6995,13 +6995,13 @@ void bdrv_refresh_filename(BlockDriverState *bs) if (bs->exact_filename[0]) { pstrcpy(bs->filename, sizeof(bs->filename), bs->exact_filename); } else { - QString *json =3D qobject_to_json(QOBJECT(bs->full_open_options)); + GString *json =3D qobject_to_json(QOBJECT(bs->full_open_options)); if (snprintf(bs->filename, sizeof(bs->filename), "json:%s", - qstring_get_str(json)) >=3D sizeof(bs->filename)) { + json->str) >=3D sizeof(bs->filename)) { /* Give user a hint if we truncated things. */ strcpy(bs->filename + sizeof(bs->filename) - 4, "..."); } - qobject_unref(json); + g_string_free(json, true); } } =20 diff --git a/block/rbd.c b/block/rbd.c index 9bd2bce716..9071a00e3f 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -232,7 +232,7 @@ static void qemu_rbd_parse_filename(const char *filenam= e, QDict *options, =20 if (keypairs) { qdict_put(options, "=3Dkeyvalue-pairs", - qobject_to_json(QOBJECT(keypairs))); + qstring_from_gstring(qobject_to_json(QOBJECT(keypairs)))= ); } =20 done: diff --git a/monitor/qmp.c b/monitor/qmp.c index 1197c50b20..374bb4b81c 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -110,15 +110,15 @@ static void monitor_qmp_cleanup_queue_and_resume(Moni= torQMP *mon) void qmp_send_response(MonitorQMP *mon, const QDict *rsp) { const QObject *data =3D QOBJECT(rsp); - QString *json; + GString *json; =20 json =3D qobject_to_json_pretty(data, mon->pretty); assert(json !=3D NULL); =20 - qstring_append_chr(json, '\n'); - monitor_puts(&mon->common, qstring_get_str(json)); + g_string_append_c(json, '\n'); + monitor_puts(&mon->common, json->str); =20 - qobject_unref(json); + g_string_free(json, true); } =20 /* @@ -320,9 +320,9 @@ static void handle_qmp_command(void *opaque, QObject *r= eq, Error *err) } /* else will fail qmp_dispatch() */ =20 if (req && trace_event_get_state_backends(TRACE_HANDLE_QMP_COMMAND)) { - QString *req_json =3D qobject_to_json(req); - trace_handle_qmp_command(mon, qstring_get_str(req_json)); - qobject_unref(req_json); + GString *req_json =3D qobject_to_json(req); + trace_handle_qmp_command(mon, req_json->str); + g_string_free(req_json, true); } =20 if (qdict && qmp_is_oob(qdict)) { diff --git a/qemu-img.c b/qemu-img.c index 1a59dfd3f3..8597d069af 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -33,7 +33,6 @@ #include "qapi/qobject-output-visitor.h" #include "qapi/qmp/qjson.h" #include "qapi/qmp/qdict.h" -#include "qapi/qmp/qstring.h" #include "qemu/cutils.h" #include "qemu/config-file.h" #include "qemu/option.h" @@ -627,7 +626,7 @@ fail: =20 static void dump_json_image_check(ImageCheck *check, bool quiet) { - QString *str; + GString *str; QObject *obj; Visitor *v =3D qobject_output_visitor_new(&obj); =20 @@ -635,10 +634,10 @@ static void dump_json_image_check(ImageCheck *check, = bool quiet) visit_complete(v, &obj); str =3D qobject_to_json_pretty(obj, true); assert(str !=3D NULL); - qprintf(quiet, "%s\n", qstring_get_str(str)); + qprintf(quiet, "%s\n", str->str); qobject_unref(obj); visit_free(v); - qobject_unref(str); + g_string_free(str, true); } =20 static void dump_human_image_check(ImageCheck *check, bool quiet) @@ -2789,7 +2788,7 @@ static void dump_snapshots(BlockDriverState *bs) =20 static void dump_json_image_info_list(ImageInfoList *list) { - QString *str; + GString *str; QObject *obj; Visitor *v =3D qobject_output_visitor_new(&obj); =20 @@ -2797,15 +2796,15 @@ static void dump_json_image_info_list(ImageInfoList= *list) visit_complete(v, &obj); str =3D qobject_to_json_pretty(obj, true); assert(str !=3D NULL); - printf("%s\n", qstring_get_str(str)); + printf("%s\n", str->str); qobject_unref(obj); visit_free(v); - qobject_unref(str); + g_string_free(str, true); } =20 static void dump_json_image_info(ImageInfo *info) { - QString *str; + GString *str; QObject *obj; Visitor *v =3D qobject_output_visitor_new(&obj); =20 @@ -2813,10 +2812,10 @@ static void dump_json_image_info(ImageInfo *info) visit_complete(v, &obj); str =3D qobject_to_json_pretty(obj, true); assert(str !=3D NULL); - printf("%s\n", qstring_get_str(str)); + printf("%s\n", str->str); qobject_unref(obj); visit_free(v); - qobject_unref(str); + g_string_free(str, true); } =20 static void dump_human_image_info_list(ImageInfoList *list) @@ -5236,7 +5235,7 @@ out: =20 static void dump_json_block_measure_info(BlockMeasureInfo *info) { - QString *str; + GString *str; QObject *obj; Visitor *v =3D qobject_output_visitor_new(&obj); =20 @@ -5244,10 +5243,10 @@ static void dump_json_block_measure_info(BlockMeasu= reInfo *info) visit_complete(v, &obj); str =3D qobject_to_json_pretty(obj, true); assert(str !=3D NULL); - printf("%s\n", qstring_get_str(str)); + printf("%s\n", str->str); qobject_unref(obj); visit_free(v); - qobject_unref(str); + g_string_free(str, true); } =20 static int img_measure(int argc, char **argv) diff --git a/qga/main.c b/qga/main.c index dea6a3aa64..e7f8f3b161 100644 --- a/qga/main.c +++ b/qga/main.c @@ -22,7 +22,6 @@ #include "qapi/qmp/json-parser.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qjson.h" -#include "qapi/qmp/qstring.h" #include "guest-agent-core.h" #include "qga-qapi-init-commands.h" #include "qapi/qmp/qerror.h" @@ -528,8 +527,7 @@ fail: =20 static int send_response(GAState *s, const QDict *rsp) { - const char *buf; - QString *payload_qstr, *response_qstr; + GString *response; GIOStatus status; =20 g_assert(s->channel); @@ -538,25 +536,19 @@ static int send_response(GAState *s, const QDict *rsp) return 0; } =20 - payload_qstr =3D qobject_to_json(QOBJECT(rsp)); - if (!payload_qstr) { + response =3D qobject_to_json(QOBJECT(rsp)); + if (!response) { return -EINVAL; } =20 if (s->delimit_response) { s->delimit_response =3D false; - response_qstr =3D qstring_new(); - qstring_append_chr(response_qstr, QGA_SENTINEL_BYTE); - qstring_append(response_qstr, qstring_get_str(payload_qstr)); - qobject_unref(payload_qstr); - } else { - response_qstr =3D payload_qstr; + g_string_prepend_c(response, QGA_SENTINEL_BYTE); } =20 - qstring_append_chr(response_qstr, '\n'); - buf =3D qstring_get_str(response_qstr); - status =3D ga_channel_write_all(s->channel, buf, strlen(buf)); - qobject_unref(response_qstr); + g_string_append_c(response, '\n'); + status =3D ga_channel_write_all(s->channel, response->str, response->l= en); + g_string_free(response, true); if (status !=3D G_IO_STATUS_NORMAL) { return -EIO; } diff --git a/qobject/qjson.c b/qobject/qjson.c index e7100a539c..2f690c1816 100644 --- a/qobject/qjson.c +++ b/qobject/qjson.c @@ -284,15 +284,15 @@ static void to_json(const QObject *obj, GString *accu= , bool pretty, int indent) } } =20 -QString *qobject_to_json_pretty(const QObject *obj, bool pretty) +GString *qobject_to_json_pretty(const QObject *obj, bool pretty) { GString *accu =3D g_string_new(NULL); =20 to_json(obj, accu, pretty, 0); - return qstring_from_gstring(accu); + return accu; } =20 -QString *qobject_to_json(const QObject *obj) +GString *qobject_to_json(const QObject *obj) { return qobject_to_json_pretty(obj, false); } diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c index ed896fe764..1e9ad6f08a 100644 --- a/qom/object_interfaces.c +++ b/qom/object_interfaces.c @@ -5,7 +5,6 @@ #include "qapi/qmp/qdict.h" #include "qapi/qmp/qerror.h" #include "qapi/qmp/qjson.h" -#include "qapi/qmp/qstring.h" #include "qapi/qobject-input-visitor.h" #include "qom/object_interfaces.h" #include "qemu/help_option.h" @@ -207,7 +206,8 @@ char *object_property_help(const char *name, const char= *type, g_string_append(str, description); } if (defval) { - g_autofree char *def_json =3D qstring_free(qobject_to_json(defval)= , TRUE); + g_autofree char *def_json =3D g_string_free(qobject_to_json(defval= ), + true); g_string_append_printf(str, " (default: %s)", def_json); } =20 diff --git a/qom/qom-hmp-cmds.c b/qom/qom-hmp-cmds.c index 6b96dbe906..453fbfeabc 100644 --- a/qom/qom-hmp-cmds.c +++ b/qom/qom-hmp-cmds.c @@ -13,7 +13,6 @@ #include "qapi/qapi-commands-qom.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qjson.h" -#include "qapi/qmp/qstring.h" #include "qom/object.h" =20 void hmp_qom_list(Monitor *mon, const QDict *qdict) @@ -78,9 +77,9 @@ void hmp_qom_get(Monitor *mon, const QDict *qdict) QObject *obj =3D qmp_qom_get(path, property, &err); =20 if (err =3D=3D NULL) { - QString *str =3D qobject_to_json_pretty(obj, true); - monitor_printf(mon, "%s\n", qstring_get_str(str)); - qobject_unref(str); + GString *str =3D qobject_to_json_pretty(obj, true); + monitor_printf(mon, "%s\n", str->str); + g_string_free(str, true); } =20 qobject_unref(obj); diff --git a/tests/check-qjson.c b/tests/check-qjson.c index ca8fb816e9..337add0838 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -35,17 +35,15 @@ static QString *from_json_str(const char *jstr, bool si= ngle, Error **errp) =20 static char *to_json_str(QString *str) { - QString *json =3D qobject_to_json(QOBJECT(str)); - char *jstr; + GString *json =3D qobject_to_json(QOBJECT(str)); =20 if (!json) { return NULL; } /* peel off double quotes */ - jstr =3D g_strndup(qstring_get_str(json) + 1, - qstring_get_length(json) - 2); - qobject_unref(json); - return jstr; + g_string_truncate(json, json->len - 1); + g_string_erase(json, 0, 1); + return g_string_free(json, false); } =20 static void escaped_string(void) @@ -809,7 +807,7 @@ static void int_number(void) QNum *qnum; int64_t ival; uint64_t uval; - QString *str; + GString *str; =20 for (i =3D 0; test_cases[i].encoded; i++) { qnum =3D qobject_to(QNum, @@ -828,9 +826,9 @@ static void int_number(void) (double)test_cases[i].decoded); =20 str =3D qobject_to_json(QOBJECT(qnum)); - g_assert_cmpstr(qstring_get_str(str), =3D=3D, + g_assert_cmpstr(str->str, =3D=3D, test_cases[i].reencoded ?: test_cases[i].encoded); - qobject_unref(str); + g_string_free(str, true); =20 qobject_unref(qnum); } @@ -851,7 +849,7 @@ static void uint_number(void) QNum *qnum; int64_t ival; uint64_t uval; - QString *str; + GString *str; =20 for (i =3D 0; test_cases[i].encoded; i++) { qnum =3D qobject_to(QNum, @@ -865,9 +863,9 @@ static void uint_number(void) (double)test_cases[i].decoded); =20 str =3D qobject_to_json(QOBJECT(qnum)); - g_assert_cmpstr(qstring_get_str(str), =3D=3D, + g_assert_cmpstr(str->str, =3D=3D, test_cases[i].reencoded ?: test_cases[i].encoded); - qobject_unref(str); + g_string_free(str, true); =20 qobject_unref(qnum); } @@ -892,7 +890,7 @@ static void float_number(void) QNum *qnum; int64_t ival; uint64_t uval; - QString *str; + GString *str; =20 for (i =3D 0; test_cases[i].encoded; i++) { qnum =3D qobject_to(QNum, @@ -904,9 +902,9 @@ static void float_number(void) g_assert(!qnum_get_try_uint(qnum, &uval)); =20 str =3D qobject_to_json(QOBJECT(qnum)); - g_assert_cmpstr(qstring_get_str(str), =3D=3D, + g_assert_cmpstr(str->str, =3D=3D, test_cases[i].reencoded ?: test_cases[i].encoded); - qobject_unref(str); + g_string_free(str, true); =20 qobject_unref(qnum); } @@ -917,7 +915,7 @@ static void keyword_literal(void) QObject *obj; QBool *qbool; QNull *null; - QString *str; + GString *str; =20 obj =3D qobject_from_json("true", &error_abort); qbool =3D qobject_to(QBool, obj); @@ -925,8 +923,8 @@ static void keyword_literal(void) g_assert(qbool_get_bool(qbool) =3D=3D true); =20 str =3D qobject_to_json(obj); - g_assert(strcmp(qstring_get_str(str), "true") =3D=3D 0); - qobject_unref(str); + g_assert_cmpstr(str->str, =3D=3D, "true"); + g_string_free(str, true); =20 qobject_unref(qbool); =20 @@ -936,8 +934,8 @@ static void keyword_literal(void) g_assert(qbool_get_bool(qbool) =3D=3D false); =20 str =3D qobject_to_json(obj); - g_assert(strcmp(qstring_get_str(str), "false") =3D=3D 0); - qobject_unref(str); + g_assert_cmpstr(str->str, =3D=3D, "false"); + g_string_free(str, true); =20 qobject_unref(qbool); =20 @@ -1087,7 +1085,7 @@ static void simple_dict(void) =20 for (i =3D 0; test_cases[i].encoded; i++) { QObject *obj; - QString *str; + GString *str; =20 obj =3D qobject_from_json(test_cases[i].encoded, &error_abort); g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj)); @@ -1095,10 +1093,10 @@ static void simple_dict(void) str =3D qobject_to_json(obj); qobject_unref(obj); =20 - obj =3D qobject_from_json(qstring_get_str(str), &error_abort); + obj =3D qobject_from_json(str->str, &error_abort); g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj)); qobject_unref(obj); - qobject_unref(str); + g_string_free(str, true); } } =20 @@ -1196,7 +1194,7 @@ static void simple_list(void) =20 for (i =3D 0; test_cases[i].encoded; i++) { QObject *obj; - QString *str; + GString *str; =20 obj =3D qobject_from_json(test_cases[i].encoded, &error_abort); g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj)); @@ -1204,10 +1202,10 @@ static void simple_list(void) str =3D qobject_to_json(obj); qobject_unref(obj); =20 - obj =3D qobject_from_json(qstring_get_str(str), &error_abort); + obj =3D qobject_from_json(str->str, &error_abort); g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj)); qobject_unref(obj); - qobject_unref(str); + g_string_free(str, true); } } =20 @@ -1258,7 +1256,7 @@ static void simple_whitespace(void) =20 for (i =3D 0; test_cases[i].encoded; i++) { QObject *obj; - QString *str; + GString *str; =20 obj =3D qobject_from_json(test_cases[i].encoded, &error_abort); g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj)); @@ -1266,11 +1264,11 @@ static void simple_whitespace(void) str =3D qobject_to_json(obj); qobject_unref(obj); =20 - obj =3D qobject_from_json(qstring_get_str(str), &error_abort); + obj =3D qobject_from_json(str->str, &error_abort); g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj)); =20 qobject_unref(obj); - qobject_unref(str); + g_string_free(str, true); } } =20 diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index 213fa4f8fe..8e93b0a707 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -652,27 +652,25 @@ void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_nu= m, /* No need to send anything for an empty QObject. */ if (qobj) { int log =3D getenv("QTEST_LOG") !=3D NULL; - QString *qstr =3D qobject_to_json(qobj); - const char *str; + GString *str =3D qobject_to_json(qobj); =20 /* * BUG: QMP doesn't react to input until it sees a newline, an * object, or an array. Work-around: give it a newline. */ - qstring_append_chr(qstr, '\n'); - str =3D qstring_get_str(qstr); + g_string_append_c(str, '\n'); =20 if (log) { - fprintf(stderr, "%s", str); + fprintf(stderr, "%s", str->str); } /* Send QMP request */ if (fds && fds_num > 0) { - socket_send_fds(fd, fds, fds_num, str, qstring_get_length(qstr= )); + socket_send_fds(fd, fds, fds_num, str->str, str->len); } else { - socket_send(fd, str, qstring_get_length(qstr)); + socket_send(fd, str->str, str->len); } =20 - qobject_unref(qstr); + g_string_free(str, true); qobject_unref(qobj); } } @@ -1197,9 +1195,9 @@ void qtest_qmp_assert_success(QTestState *qts, const = char *fmt, ...) =20 g_assert(response); if (!qdict_haskey(response, "return")) { - QString *s =3D qobject_to_json_pretty(QOBJECT(response), true); - g_test_message("%s", qstring_get_str(s)); - qobject_unref(s); + GString *s =3D qobject_to_json_pretty(QOBJECT(response), true); + g_test_message("%s", s->str); + g_string_free(s, true); } g_assert(qdict_haskey(response, "return")); qobject_unref(response); diff --git a/tests/test-visitor-serialization.c b/tests/test-visitor-serial= ization.c index dfe120a50d..4629958647 100644 --- a/tests/test-visitor-serialization.c +++ b/tests/test-visitor-serialization.c @@ -957,15 +957,15 @@ static void qmp_deserialize(void **native_out, void *= datap, VisitorFunc visit, Error **errp) { QmpSerializeData *d =3D datap; - QString *output_json; + GString *output_json; QObject *obj_orig, *obj; =20 visit_complete(d->qov, &d->obj); obj_orig =3D d->obj; output_json =3D qobject_to_json(obj_orig); - obj =3D qobject_from_json(qstring_get_str(output_json), &error_abort); + obj =3D qobject_from_json(output_json->str, &error_abort); =20 - qobject_unref(output_json); + g_string_free(output_json, true); d->qiv =3D qobject_input_visitor_new(obj); qobject_unref(obj_orig); qobject_unref(obj); --=20 2.26.2 From nobody Thu May 16 15:04:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608376065; cv=none; d=zohomail.com; s=zohoarc; b=BD39jPQ+avGyalw5frrCnht90yr0797UopJl6wzWq4xQPa0ACpEmohLWjYElWSKsAgZITaygVtRCSpGBTB5ka2rrFB0wiwUHbdiqztEs00UBBrGxDEB8AYONhwpn974WzjMdfY0a3lm7o2pCxXtKrZbd80kBIzZ7soIAgNIecks= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608376065; 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=/d3mzP8nvBbMA3ku1d3EdmHDICO8fDbwDwYwndxAmlI=; b=HnhsGLBI6Ezf3k/WdrVEfNWJmm9cRWTkh49+jhmiDfqbfXNb10K5Vxa/j6B808T9aZ4U+yizSWI4+9/Tk6kf8GRGReJ/05nYDVq16tMqFbigV9uyY5UNFVYpCZSTf4WZV2qBFJBpAFjzkW7qsnoipApdLy5P3u1oLHMDSO3DAIQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1608376065501510.3886052203013; Sat, 19 Dec 2020 03:07:45 -0800 (PST) Received: from localhost ([::1]:47794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqa5O-0003ju-5c for importer@patchew.org; Sat, 19 Dec 2020 06:07:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50706) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZtr-0004on-Lc for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:47 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:32307) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtl-0007Go-A8 for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:47 -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-127--slwTxFWN3WNIEPIS3RKhg-1; Sat, 19 Dec 2020 05:55:38 -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 E9D8051E2; Sat, 19 Dec 2020 10:55:36 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BD90671D53; Sat, 19 Dec 2020 10:55:36 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id A0BC311268A1; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375340; 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=/d3mzP8nvBbMA3ku1d3EdmHDICO8fDbwDwYwndxAmlI=; b=iB3JprR4b+pP68gF0cWPzdh6EQ3xtFUSPGeyaW3QHPpVoNJ6q3ZI02P2ZZpcUvNZKkNz2w 55uPTjeSRz/1MFDaoLgDHF/TuCUOhWai2oZi9wbXfNk6+ABFq1NOUh8s/f0yHe9I68QLra j0M3bUZvENmws7VNpUAx4bUCj38tjKg= X-MC-Unique: -slwTxFWN3WNIEPIS3RKhg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 19/33] Revert "qstring: add qstring_free()" Date: Sat, 19 Dec 2020 11:55:18 +0100 Message-Id: <20201219105532.1734134-20-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H3=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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This reverts commit 164c374b75f87c6765a705c4418ab7005a2d356f. A free function for a reference-counted object is in bad taste. Fortunately, this one is now also unused. Drop it. Signed-off-by: Markus Armbruster Message-Id: <20201211171152.146877-7-armbru@redhat.com> --- include/qapi/qmp/qstring.h | 1 - qobject/qstring.c | 27 +++++---------------------- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/include/qapi/qmp/qstring.h b/include/qapi/qmp/qstring.h index ae7698d6c7..ae5b4b44d2 100644 --- a/include/qapi/qmp/qstring.h +++ b/include/qapi/qmp/qstring.h @@ -34,7 +34,6 @@ void qstring_append_int(QString *qstring, int64_t value); void qstring_append(QString *qstring, const char *str); void qstring_append_chr(QString *qstring, int c); bool qstring_is_equal(const QObject *x, const QObject *y); -char *qstring_free(QString *qstring, bool return_str); void qstring_destroy_obj(QObject *obj); =20 #endif /* QSTRING_H */ diff --git a/qobject/qstring.c b/qobject/qstring.c index af7c18ca73..c1891beda0 100644 --- a/qobject/qstring.c +++ b/qobject/qstring.c @@ -168,33 +168,16 @@ bool qstring_is_equal(const QObject *x, const QObject= *y) qobject_to(QString, y)->string); } =20 -/** - * qstring_free(): Free the memory allocated by a QString object - * - * Return: if @return_str, return the underlying string, to be - * g_free(), otherwise NULL is returned. - */ -char *qstring_free(QString *qstring, bool return_str) -{ - char *rv =3D NULL; - - if (return_str) { - rv =3D qstring->string; - } else { - g_free(qstring->string); - } - - g_free(qstring); - - return rv; -} - /** * qstring_destroy_obj(): Free all memory allocated by a QString * object */ void qstring_destroy_obj(QObject *obj) { + QString *qs; + assert(obj !=3D NULL); - qstring_free(qobject_to(QString, obj), FALSE); + qs =3D qobject_to(QString, obj); + g_free(qs->string); + g_free(qs); } --=20 2.26.2 From nobody Thu May 16 15:04:34 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=1608376185; cv=none; d=zohomail.com; s=zohoarc; b=VT92za/mx1xD4asYmd9kZXGOVT+GrAA9sIJK0LQGlN7gnkh9jKgYdcunleJ735AQ96+LszCNEBZ9NEjDAspructt5Yl+I6GL/g+9Igolnqu1+WW+FXKymDDxLAjI343f0k0Q3ZjLmdh+09kkGXIq73JKedpFsySu8kvkpZzD2OM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608376185; 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=M7Mbkx49VnsZZPTjzSq3CtgEnaNIXUwF1DNyuy1pL44=; b=U4/X521Fy7WvRzDgZXxNcLOoYNXCAZgMhIwQU0bH0NqJt9sdr1OqhQrWwQ1EM2iWTrJgFkiin5ANPVJcQp/QYxr20uDJRC61QPHQUWW8wnb3nz3t05TZCz9GHeN1LuAfbnJpgs/pWl/v/GaMa4NkPZMovU0PJpEUwQMrwaohVps= 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 1608376185899658.7274157882848; Sat, 19 Dec 2020 03:09:45 -0800 (PST) Received: from localhost ([::1]:56154 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqa7M-00078U-NC for importer@patchew.org; Sat, 19 Dec 2020 06:09:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50774) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZtu-0004xl-Lf for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:30800) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtl-0007HL-KZ for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:50 -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-50-2A5GdPL_MXeKza7WQDWePg-1; Sat, 19 Dec 2020 05:55:38 -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 23ABB180A097; Sat, 19 Dec 2020 10:55:37 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C4AAB5D9D7; Sat, 19 Dec 2020 10:55:36 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id A5AC011268A2; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375340; 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=M7Mbkx49VnsZZPTjzSq3CtgEnaNIXUwF1DNyuy1pL44=; b=Z/Lz9+cr7zlOyQbV4mP8kDq6XzkAHpMVBto7ue/e0tuL0l24kifmVkD4DyD3cPmf13Kv+1 AT1WqWbSopsmaiwGFaEKETtaUNHwMFj8yOU/+YGTnQI3H9A3W9jv4Wa0ZwBVn9rTh0oI4z 0SGpVGpUdW3o/KJMR320EzJ6suA6PIs= X-MC-Unique: 2A5GdPL_MXeKza7WQDWePg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 20/33] hw/rdma: Replace QList by GQueue Date: Sat, 19 Dec 2020 11:55:19 +0100 Message-Id: <20201219105532.1734134-21-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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: peter.maydell@linaro.org, Yuval Shaia 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" RdmaProtectedQList provides a thread-safe queue of int64_t on top of a QList. rdma_protected_qlist_destroy() calls qlist_destroy_obj() directly. qlist_destroy_obj() is actually for use by qobject_destroy() only. The next commit will make that obvious. The minimal fix would be calling qobject_unref() instead. But QList is actually a bad fit here. It's designed for representing JSON arrays. We're better off with a GQueue here. Replace. Cc: Yuval Shaia Cc: Marcel Apfelbaum Signed-off-by: Markus Armbruster Message-Id: <20201211171152.146877-8-armbru@redhat.com> --- hw/rdma/rdma_backend_defs.h | 2 +- hw/rdma/rdma_utils.h | 15 ++++++++------- hw/rdma/rdma_backend.c | 10 +++++----- hw/rdma/rdma_utils.c | 29 ++++++++++++++++------------- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/hw/rdma/rdma_backend_defs.h b/hw/rdma/rdma_backend_defs.h index 0b55be3503..4e6c0ad695 100644 --- a/hw/rdma/rdma_backend_defs.h +++ b/hw/rdma/rdma_backend_defs.h @@ -43,7 +43,7 @@ typedef struct RdmaBackendDev { struct ibv_context *context; struct ibv_comp_channel *channel; uint8_t port_num; - RdmaProtectedQList recv_mads_list; + RdmaProtectedGQueue recv_mads_list; RdmaCmMux rdmacm_mux; } RdmaBackendDev; =20 diff --git a/hw/rdma/rdma_utils.h b/hw/rdma/rdma_utils.h index e7babe96cb..9fd0efd940 100644 --- a/hw/rdma/rdma_utils.h +++ b/hw/rdma/rdma_utils.h @@ -28,10 +28,10 @@ #define rdma_info_report(fmt, ...) \ info_report("%s: " fmt, "rdma", ## __VA_ARGS__) =20 -typedef struct RdmaProtectedQList { +typedef struct RdmaProtectedGQueue { QemuMutex lock; - QList *list; -} RdmaProtectedQList; + GQueue *list; +} RdmaProtectedGQueue; =20 typedef struct RdmaProtectedGSList { QemuMutex lock; @@ -40,10 +40,11 @@ typedef struct RdmaProtectedGSList { =20 void *rdma_pci_dma_map(PCIDevice *dev, dma_addr_t addr, dma_addr_t plen); void rdma_pci_dma_unmap(PCIDevice *dev, void *buffer, dma_addr_t len); -void rdma_protected_qlist_init(RdmaProtectedQList *list); -void rdma_protected_qlist_destroy(RdmaProtectedQList *list); -void rdma_protected_qlist_append_int64(RdmaProtectedQList *list, int64_t v= alue); -int64_t rdma_protected_qlist_pop_int64(RdmaProtectedQList *list); +void rdma_protected_gqueue_init(RdmaProtectedGQueue *list); +void rdma_protected_gqueue_destroy(RdmaProtectedGQueue *list); +void rdma_protected_gqueue_append_int64(RdmaProtectedGQueue *list, + int64_t value); +int64_t rdma_protected_gqueue_pop_int64(RdmaProtectedGQueue *list); void rdma_protected_gslist_init(RdmaProtectedGSList *list); void rdma_protected_gslist_destroy(RdmaProtectedGSList *list); void rdma_protected_gslist_append_int32(RdmaProtectedGSList *list, diff --git a/hw/rdma/rdma_backend.c b/hw/rdma/rdma_backend.c index 5de010b1fa..6dcdfbbbe2 100644 --- a/hw/rdma/rdma_backend.c +++ b/hw/rdma/rdma_backend.c @@ -78,7 +78,7 @@ static void clean_recv_mads(RdmaBackendDev *backend_dev) unsigned long cqe_ctx_id; =20 do { - cqe_ctx_id =3D rdma_protected_qlist_pop_int64(&backend_dev-> + cqe_ctx_id =3D rdma_protected_gqueue_pop_int64(&backend_dev-> recv_mads_list); if (cqe_ctx_id !=3D -ENOENT) { qatomic_inc(&backend_dev->rdma_dev_res->stats.missing_cqe); @@ -597,7 +597,7 @@ static unsigned int save_mad_recv_buffer(RdmaBackendDev= *backend_dev, bctx->up_ctx =3D ctx; bctx->sge =3D *sge; =20 - rdma_protected_qlist_append_int64(&backend_dev->recv_mads_list, bctx_i= d); + rdma_protected_gqueue_append_int64(&backend_dev->recv_mads_list, bctx_= id); =20 return 0; } @@ -1111,7 +1111,7 @@ static void process_incoming_mad_req(RdmaBackendDev *= backend_dev, =20 trace_mad_message("recv", msg->umad.mad, msg->umad_len); =20 - cqe_ctx_id =3D rdma_protected_qlist_pop_int64(&backend_dev->recv_mads_= list); + cqe_ctx_id =3D rdma_protected_gqueue_pop_int64(&backend_dev->recv_mads= _list); if (cqe_ctx_id =3D=3D -ENOENT) { rdma_warn_report("No more free MADs buffers, waiting for a while"); sleep(THR_POLL_TO); @@ -1185,7 +1185,7 @@ static int mad_init(RdmaBackendDev *backend_dev, Char= Backend *mad_chr_be) return -EIO; } =20 - rdma_protected_qlist_init(&backend_dev->recv_mads_list); + rdma_protected_gqueue_init(&backend_dev->recv_mads_list); =20 enable_rdmacm_mux_async(backend_dev); =20 @@ -1205,7 +1205,7 @@ static void mad_fini(RdmaBackendDev *backend_dev) { disable_rdmacm_mux_async(backend_dev); qemu_chr_fe_disconnect(backend_dev->rdmacm_mux.chr_be); - rdma_protected_qlist_destroy(&backend_dev->recv_mads_list); + rdma_protected_gqueue_destroy(&backend_dev->recv_mads_list); } =20 int rdma_backend_get_gid_index(RdmaBackendDev *backend_dev, diff --git a/hw/rdma/rdma_utils.c b/hw/rdma/rdma_utils.c index 698ed4716c..98df58f689 100644 --- a/hw/rdma/rdma_utils.c +++ b/hw/rdma/rdma_utils.c @@ -14,8 +14,6 @@ */ =20 #include "qemu/osdep.h" -#include "qapi/qmp/qlist.h" -#include "qapi/qmp/qnum.h" #include "trace.h" #include "rdma_utils.h" =20 @@ -54,41 +52,46 @@ void rdma_pci_dma_unmap(PCIDevice *dev, void *buffer, d= ma_addr_t len) } } =20 -void rdma_protected_qlist_init(RdmaProtectedQList *list) +void rdma_protected_gqueue_init(RdmaProtectedGQueue *list) { qemu_mutex_init(&list->lock); - list->list =3D qlist_new(); + list->list =3D g_queue_new(); } =20 -void rdma_protected_qlist_destroy(RdmaProtectedQList *list) +void rdma_protected_gqueue_destroy(RdmaProtectedGQueue *list) { if (list->list) { - qlist_destroy_obj(QOBJECT(list->list)); + g_queue_free_full(list->list, g_free); qemu_mutex_destroy(&list->lock); list->list =3D NULL; } } =20 -void rdma_protected_qlist_append_int64(RdmaProtectedQList *list, int64_t v= alue) +void rdma_protected_gqueue_append_int64(RdmaProtectedGQueue *list, + int64_t value) { qemu_mutex_lock(&list->lock); - qlist_append_int(list->list, value); + g_queue_push_tail(list->list, g_memdup(&value, sizeof(value))); qemu_mutex_unlock(&list->lock); } =20 -int64_t rdma_protected_qlist_pop_int64(RdmaProtectedQList *list) +int64_t rdma_protected_gqueue_pop_int64(RdmaProtectedGQueue *list) { - QObject *obj; + int64_t *valp; + int64_t val; =20 qemu_mutex_lock(&list->lock); - obj =3D qlist_pop(list->list); + + valp =3D g_queue_pop_head(list->list); qemu_mutex_unlock(&list->lock); =20 - if (!obj) { + if (!valp) { return -ENOENT; } =20 - return qnum_get_uint(qobject_to(QNum, obj)); + val =3D *valp; + g_free(valp); + return val; } =20 void rdma_protected_gslist_init(RdmaProtectedGSList *list) --=20 2.26.2 From nobody Thu May 16 15:04:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608376645; cv=none; d=zohomail.com; s=zohoarc; b=TvjC2FTk4zBrEdLy1hFoigaN3q9Fzu7lVIGXjBDZreNZqP1UYis299yyAOc2KFE6DhonDMtWLBwznTb/IYou7z6MucAEAvEJZB0SQkWgwXBvWwKzbHbigfyf3W0XqJEw2BAVyp9bVNQ0hv7/4EUt8MEUMxSH3v/GbaetFBlV50A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608376645; 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=lRD6uFJd0VXDs5x/i8afxBfXsoy7XklAaqM9TAjeGkY=; b=O5iYyr3O2xOdJoJFOYi9Jwyq6IH45jVtJMO7Z6H5C16BusqOibiLbX5/Z4cM4YvfBVT7r4YCeqReJeisD8x4OxASdxDkDbnAgeJM29dp3uov3zi8NrDMyhGgpYeJ66JAYpS3SnmlmvnS7t3qESI4pcmx/OiL+r9LZAQN4ry0GpE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 160837664570350.97972507319446; Sat, 19 Dec 2020 03:17:25 -0800 (PST) Received: from localhost ([::1]:50058 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqaEm-00085R-I0 for importer@patchew.org; Sat, 19 Dec 2020 06:17:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50834) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZtx-00056s-Gm for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:36190) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtl-0007HY-Me for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:53 -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-109-fgwB4SEKO06No4mVhHnI9g-1; Sat, 19 Dec 2020 05:55:38 -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 2912451E4; Sat, 19 Dec 2020 10:55:37 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CAE546E51F; Sat, 19 Dec 2020 10:55:36 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id AA92B11268B3; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375340; 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=lRD6uFJd0VXDs5x/i8afxBfXsoy7XklAaqM9TAjeGkY=; b=i0UJOXsi7taleHNQPgk5UhLduQ4ylTbc0kAwGKheXKF2307TxiKZze4E0tucLtb+Wtcx8g 0zDQJYChhSALtF6tpv/92lq4jrh7uGvpRS6vviTrVOjxL6S5+C5JR+1eNiyzjiPjTt95Tp pWbz9fSN+jRjc++cFAe6RfJrlQJSKP8= X-MC-Unique: fgwB4SEKO06No4mVhHnI9g-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 21/33] qobject: Move internals to qobject-internal.h Date: Sat, 19 Dec 2020 11:55:20 +0100 Message-Id: <20201219105532.1734134-22-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H3=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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Message-Id: <20201211171152.146877-9-armbru@redhat.com> --- include/qapi/qmp/qbool.h | 2 -- include/qapi/qmp/qdict.h | 2 -- include/qapi/qmp/qlist.h | 2 -- include/qapi/qmp/qnull.h | 2 -- include/qapi/qmp/qnum.h | 3 --- include/qapi/qmp/qobject.h | 9 +-------- include/qapi/qmp/qstring.h | 2 -- qobject/qobject-internal.h | 39 ++++++++++++++++++++++++++++++++++++++ qobject/qbool.c | 1 + qobject/qdict.c | 1 + qobject/qlist.c | 1 + qobject/qnull.c | 1 + qobject/qnum.c | 1 + qobject/qobject.c | 1 + qobject/qstring.c | 1 + 15 files changed, 47 insertions(+), 21 deletions(-) create mode 100644 qobject/qobject-internal.h diff --git a/include/qapi/qmp/qbool.h b/include/qapi/qmp/qbool.h index 5f61e38e64..2f888d1057 100644 --- a/include/qapi/qmp/qbool.h +++ b/include/qapi/qmp/qbool.h @@ -23,7 +23,5 @@ struct QBool { =20 QBool *qbool_from_bool(bool value); bool qbool_get_bool(const QBool *qb); -bool qbool_is_equal(const QObject *x, const QObject *y); -void qbool_destroy_obj(QObject *obj); =20 #endif /* QBOOL_H */ diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h index da942347a7..9934539c1b 100644 --- a/include/qapi/qmp/qdict.h +++ b/include/qapi/qmp/qdict.h @@ -39,10 +39,8 @@ void qdict_put_obj(QDict *qdict, const char *key, QObjec= t *value); void qdict_del(QDict *qdict, const char *key); int qdict_haskey(const QDict *qdict, const char *key); QObject *qdict_get(const QDict *qdict, const char *key); -bool qdict_is_equal(const QObject *x, const QObject *y); const QDictEntry *qdict_first(const QDict *qdict); const QDictEntry *qdict_next(const QDict *qdict, const QDictEntry *entry); -void qdict_destroy_obj(QObject *obj); =20 /* Helper to qdict_put_obj(), accepts any object */ #define qdict_put(qdict, key, obj) \ diff --git a/include/qapi/qmp/qlist.h b/include/qapi/qmp/qlist.h index 595b7943e1..06e98ad5f4 100644 --- a/include/qapi/qmp/qlist.h +++ b/include/qapi/qmp/qlist.h @@ -51,8 +51,6 @@ QObject *qlist_pop(QList *qlist); QObject *qlist_peek(QList *qlist); int qlist_empty(const QList *qlist); size_t qlist_size(const QList *qlist); -bool qlist_is_equal(const QObject *x, const QObject *y); -void qlist_destroy_obj(QObject *obj); =20 static inline const QListEntry *qlist_first(const QList *qlist) { diff --git a/include/qapi/qmp/qnull.h b/include/qapi/qmp/qnull.h index c1426882c5..e84ecceedb 100644 --- a/include/qapi/qmp/qnull.h +++ b/include/qapi/qmp/qnull.h @@ -26,6 +26,4 @@ static inline QNull *qnull(void) return qobject_ref(&qnull_); } =20 -bool qnull_is_equal(const QObject *x, const QObject *y); - #endif /* QNULL_H */ diff --git a/include/qapi/qmp/qnum.h b/include/qapi/qmp/qnum.h index bbae0a5ec8..7f84e20bfb 100644 --- a/include/qapi/qmp/qnum.h +++ b/include/qapi/qmp/qnum.h @@ -68,7 +68,4 @@ double qnum_get_double(QNum *qn); =20 char *qnum_to_string(QNum *qn); =20 -bool qnum_is_equal(const QObject *x, const QObject *y); -void qnum_destroy_obj(QObject *obj); - #endif /* QNUM_H */ diff --git a/include/qapi/qmp/qobject.h b/include/qapi/qmp/qobject.h index fcfd549220..9003b71fd3 100644 --- a/include/qapi/qmp/qobject.h +++ b/include/qapi/qmp/qobject.h @@ -64,14 +64,6 @@ QEMU_BUILD_BUG_MSG(QTYPE__MAX !=3D 7, #define qobject_to(type, obj) \ ((type *)qobject_check_type(obj, glue(QTYPE_CAST_TO_, type))) =20 -/* Initialize an object to default values */ -static inline void qobject_init(QObject *obj, QType type) -{ - assert(QTYPE_NONE < type && type < QTYPE__MAX); - obj->base.refcnt =3D 1; - obj->base.type =3D type; -} - static inline void qobject_ref_impl(QObject *obj) { if (obj) { @@ -90,6 +82,7 @@ bool qobject_is_equal(const QObject *x, const QObject *y); =20 /** * qobject_destroy(): Free resources used by the object + * For use via qobject_unref() only! */ void qobject_destroy(QObject *obj); =20 diff --git a/include/qapi/qmp/qstring.h b/include/qapi/qmp/qstring.h index ae5b4b44d2..e4ac761a22 100644 --- a/include/qapi/qmp/qstring.h +++ b/include/qapi/qmp/qstring.h @@ -33,7 +33,5 @@ const char *qobject_get_try_str(const QObject *qstring); void qstring_append_int(QString *qstring, int64_t value); void qstring_append(QString *qstring, const char *str); void qstring_append_chr(QString *qstring, int c); -bool qstring_is_equal(const QObject *x, const QObject *y); -void qstring_destroy_obj(QObject *obj); =20 #endif /* QSTRING_H */ diff --git a/qobject/qobject-internal.h b/qobject/qobject-internal.h new file mode 100644 index 0000000000..b310c8e1b5 --- /dev/null +++ b/qobject/qobject-internal.h @@ -0,0 +1,39 @@ +/* + * QObject internals + * + * Copyright (C) 2015 Red Hat, Inc. + * + * 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. + */ + +#ifndef QOBJECT_INTERNAL_H +#define QOBJECT_INTERNAL_H + +#include "qapi/qmp/qobject.h" + +static inline void qobject_init(QObject *obj, QType type) +{ + assert(QTYPE_NONE < type && type < QTYPE__MAX); + obj->base.refcnt =3D 1; + obj->base.type =3D type; +} + +void qbool_destroy_obj(QObject *obj); +bool qbool_is_equal(const QObject *x, const QObject *y); + +void qdict_destroy_obj(QObject *obj); +bool qdict_is_equal(const QObject *x, const QObject *y); + +void qlist_destroy_obj(QObject *obj); +bool qlist_is_equal(const QObject *x, const QObject *y); + +bool qnull_is_equal(const QObject *x, const QObject *y); + +void qnum_destroy_obj(QObject *obj); +bool qnum_is_equal(const QObject *x, const QObject *y); + +void qstring_destroy_obj(QObject *obj); +bool qstring_is_equal(const QObject *x, const QObject *y); + +#endif diff --git a/qobject/qbool.c b/qobject/qbool.c index 06dfc43498..16a600abb9 100644 --- a/qobject/qbool.c +++ b/qobject/qbool.c @@ -13,6 +13,7 @@ =20 #include "qemu/osdep.h" #include "qapi/qmp/qbool.h" +#include "qobject-internal.h" =20 /** * qbool_from_bool(): Create a new QBool from a bool diff --git a/qobject/qdict.c b/qobject/qdict.c index 1079bd3f6f..d84443391e 100644 --- a/qobject/qdict.c +++ b/qobject/qdict.c @@ -16,6 +16,7 @@ #include "qapi/qmp/qbool.h" #include "qapi/qmp/qnull.h" #include "qapi/qmp/qstring.h" +#include "qobject-internal.h" =20 /** * qdict_new(): Create a new QDict diff --git a/qobject/qlist.c b/qobject/qlist.c index 1be95367d1..60562a1f52 100644 --- a/qobject/qlist.c +++ b/qobject/qlist.c @@ -17,6 +17,7 @@ #include "qapi/qmp/qnum.h" #include "qapi/qmp/qstring.h" #include "qemu/queue.h" +#include "qobject-internal.h" =20 /** * qlist_new(): Create a new QList diff --git a/qobject/qnull.c b/qobject/qnull.c index 00870a1824..b26b368219 100644 --- a/qobject/qnull.c +++ b/qobject/qnull.c @@ -12,6 +12,7 @@ =20 #include "qemu/osdep.h" #include "qapi/qmp/qnull.h" +#include "qobject-internal.h" =20 QNull qnull_ =3D { .base =3D { diff --git a/qobject/qnum.c b/qobject/qnum.c index bf1240ecec..35ba41e61c 100644 --- a/qobject/qnum.c +++ b/qobject/qnum.c @@ -14,6 +14,7 @@ =20 #include "qemu/osdep.h" #include "qapi/qmp/qnum.h" +#include "qobject-internal.h" =20 /** * qnum_from_int(): Create a new QNum from an int64_t diff --git a/qobject/qobject.c b/qobject/qobject.c index 878dd76e79..d7077b8f2a 100644 --- a/qobject/qobject.c +++ b/qobject/qobject.c @@ -14,6 +14,7 @@ #include "qapi/qmp/qdict.h" #include "qapi/qmp/qlist.h" #include "qapi/qmp/qstring.h" +#include "qobject-internal.h" =20 QEMU_BUILD_BUG_MSG( offsetof(QNull, base) !=3D 0 || diff --git a/qobject/qstring.c b/qobject/qstring.c index c1891beda0..d6724bd4e5 100644 --- a/qobject/qstring.c +++ b/qobject/qstring.c @@ -12,6 +12,7 @@ =20 #include "qemu/osdep.h" #include "qapi/qmp/qstring.h" +#include "qobject-internal.h" =20 /** * qstring_new(): Create a new empty QString --=20 2.26.2 From nobody Thu May 16 15:04:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608376342; cv=none; d=zohomail.com; s=zohoarc; b=dW6S3lJPfvu9UPZ72Y6cweE27of6HO3o5W5t8J+J4RDCzO4PcL3gmfH0vlbdE4xf/zYTa0EAopYigMlvPHWx0MYwERrNVVyDlbbrJtNl6BrT37APfX9lA1R/bIaFXPuIQCHDqrGP/CYHkYGqGM71OvN9ox9wiFfVwxICcLjnEO8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608376342; 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=KFCz47ncNaV5cvTc1pS6Z0mHftz1LnQegjB8Up+Zu60=; b=EcU27WkCN+zBFl+ziD57CpfMxs3epeES9qDN6d0DLvBjA4Bg7L9Zw0c2e9cI0UaPrB7XpEpQyyGlS4brgn7g5MpoTOHw+JnrwL3hRqPQetdU3VvLQ0RFsb492VQTkXfr1mn1rqUqstZ07mqpv8I2xApmQPsaj+FyduZwv2TQsTQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1608376342218372.6941225386753; Sat, 19 Dec 2020 03:12:22 -0800 (PST) Received: from localhost ([::1]:36478 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqa9t-0002LH-2d for importer@patchew.org; Sat, 19 Dec 2020 06:12:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50766) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZtu-0004ve-1m for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:21317) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtl-0007Gh-Hx for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:49 -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-88-yp4uDy9PPhCBaYVB2vHNvQ-1; Sat, 19 Dec 2020 05:55:37 -0500 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 052BF180A095; Sat, 19 Dec 2020 10:55:37 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CB2AE10016FE; Sat, 19 Dec 2020 10:55:36 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id AF5A111268B4; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375340; 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=KFCz47ncNaV5cvTc1pS6Z0mHftz1LnQegjB8Up+Zu60=; b=hoh1O7itrNyCi3B0PnCrrWXGUiqmfZxtAvFOY3d1nrM2sVW4iKcycDuvGRWGkoo9PLbLSN ccoOF5Zw2+656E8S7UAJjjtT+u9Ec5NT52zHd7Qkybao7gNIdP4JPOCGhU29uMs2kzbsgs KVzrqWQseM/DcHRpEWKeQyv4DOwbQAQ= X-MC-Unique: yp4uDy9PPhCBaYVB2vHNvQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 22/33] qmp: Fix tracing of non-string command IDs Date: Sat, 19 Dec 2020 11:55:21 +0100 Message-Id: <20201219105532.1734134-23-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Tracepoints monitor_qmp_cmd_in_band and monitor_qmp_cmd_out_of_band (commit cf869d5317 "qmp: support out-of-band (oob) execution") treat non-string "id" like absent "id". Fix that. Signed-off-by: Markus Armbruster Message-Id: <20201211171152.146877-10-armbru@redhat.com> --- monitor/qmp.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/monitor/qmp.c b/monitor/qmp.c index 374bb4b81c..8f91af32be 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -31,7 +31,6 @@ #include "qapi/qmp/qdict.h" #include "qapi/qmp/qjson.h" #include "qapi/qmp/qlist.h" -#include "qapi/qmp/qstring.h" #include "trace.h" =20 struct QMPRequest { @@ -276,9 +275,15 @@ void coroutine_fn monitor_qmp_dispatcher_co(void *data) mon->qmp_requests->length =3D=3D QMP_REQ_QUEUE_LEN_MAX - 1; qemu_mutex_unlock(&mon->qmp_queue_lock); if (req_obj->req) { - QDict *qdict =3D qobject_to(QDict, req_obj->req); - QObject *id =3D qdict ? qdict_get(qdict, "id") : NULL; - trace_monitor_qmp_cmd_in_band(qobject_get_try_str(id) ?: ""); + if (trace_event_get_state(TRACE_MONITOR_QMP_CMD_IN_BAND)) { + QDict *qdict =3D qobject_to(QDict, req_obj->req); + QObject *id =3D qdict ? qdict_get(qdict, "id") : NULL; + GString *id_json; + + id_json =3D id ? qobject_to_json(id) : g_string_new(NULL); + trace_monitor_qmp_cmd_in_band(id_json->str); + g_string_free(id_json, true); + } monitor_qmp_dispatch(mon, req_obj->req); } else { assert(req_obj->err); @@ -308,17 +313,11 @@ void coroutine_fn monitor_qmp_dispatcher_co(void *dat= a) static void handle_qmp_command(void *opaque, QObject *req, Error *err) { MonitorQMP *mon =3D opaque; - QObject *id =3D NULL; - QDict *qdict; + QDict *qdict =3D qobject_to(QDict, req); QMPRequest *req_obj; =20 assert(!req !=3D !err); =20 - qdict =3D qobject_to(QDict, req); - if (qdict) { - id =3D qdict_get(qdict, "id"); - } /* else will fail qmp_dispatch() */ - if (req && trace_event_get_state_backends(TRACE_HANDLE_QMP_COMMAND)) { GString *req_json =3D qobject_to_json(req); trace_handle_qmp_command(mon, req_json->str); @@ -327,7 +326,14 @@ static void handle_qmp_command(void *opaque, QObject *= req, Error *err) =20 if (qdict && qmp_is_oob(qdict)) { /* OOB commands are executed immediately */ - trace_monitor_qmp_cmd_out_of_band(qobject_get_try_str(id) ?: ""); + if (trace_event_get_state(TRACE_MONITOR_QMP_CMD_OUT_OF_BAND)) { + QObject *id =3D qdict_get(qdict, "id"); + GString *id_json; + + id_json =3D id ? qobject_to_json(id) : g_string_new(NULL); + trace_monitor_qmp_cmd_out_of_band(id_json->str); + g_string_free(id_json, true); + } monitor_qmp_dispatch(mon, req); qobject_unref(req); return; --=20 2.26.2 From nobody Thu May 16 15:04:34 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=1608376071; cv=none; d=zohomail.com; s=zohoarc; b=G0XYrSadtPMbmxZ4hE81+/ifR9hGKiIOBAvP5K/fpMwXbIPzvHDqqy1mk+zt2qL2P+oigWQkENfzLrpb3wnvXBqq+cwkP68WqKiFTa5wkdKTPT22AXKgcT2W3YO73Sp3mm671pMZ4LlSfO7q+jx4pfRuoCHS1ovzrDNZ5ShTHWY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608376071; 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=ArWYvOkOsSQfEDSh3eobi/mm1FjGc5gzHUQcz8x7llc=; b=YJ/JS5UZJLJ9ZE+05OrTgwcQfjFIPoVSHgnoTApzyHmj5s0XkwiM05juOrovPnq505ypsqQ3U1Pklxvxst21+BI6+rG+NMEVZBAARvXxaEQ1H5IwSBWpKPIzHfJg8i8hMhgW3KemmceRpAT/sMeaXxTgaTBdd1wAw0tMkCsmV1M= 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 1608376071887334.4955714691798; Sat, 19 Dec 2020 03:07:51 -0800 (PST) Received: from localhost ([::1]:48328 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqa5W-0003ww-OT for importer@patchew.org; Sat, 19 Dec 2020 06:07:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50800) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZtv-00050j-Ls for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:51 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:29840) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtl-0007HU-MU for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:51 -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-50-tJc24Hh1Mtq61FvGISPTDQ-1; Sat, 19 Dec 2020 05:55:38 -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 354348015CE; Sat, 19 Dec 2020 10:55:37 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D0D7877701; Sat, 19 Dec 2020 10:55:36 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id B418D11268B9; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375340; 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=ArWYvOkOsSQfEDSh3eobi/mm1FjGc5gzHUQcz8x7llc=; b=ZhzjpuNv4DdjgqvXUbHLXwzI73RZ/Yih8IK2S9IhxjqDywkgVXd2ZknjDrq/Ea9DLiV/O+ DW8tIUp/Wy4l77z/H+grQFeGto66GZOb4EoACbjR0xDzYzCGmZMh7G/YxhpEy90FOd33Xl PjX90Moz2MrqAxEmH1zVXArxUTbXB6A= X-MC-Unique: tJc24Hh1Mtq61FvGISPTDQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 23/33] block: Avoid qobject_get_try_str() Date: Sat, 19 Dec 2020 11:55:22 +0100 Message-Id: <20201219105532.1734134-24-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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=unavailable 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: Kevin Wolf , peter.maydell@linaro.org, Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Max Reitz 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" I'm about to remove qobject_get_try_str(). Use qstring_get_str() instead. Safe because the argument is known to be a QString here. Cc: Kevin Wolf Cc: Max Reitz Cc: qemu-block@nongnu.org Signed-off-by: Markus Armbruster Message-Id: <20201211171152.146877-11-armbru@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy --- block.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index 09d4c6bd25..934d1bcc8f 100644 --- a/block.c +++ b/block.c @@ -4021,7 +4021,7 @@ static int bdrv_reopen_parse_backing(BDRVReopenState = *reopen_state, new_backing_bs =3D NULL; break; case QTYPE_QSTRING: - str =3D qobject_get_try_str(value); + str =3D qstring_get_str(qobject_to(QString, value)); new_backing_bs =3D bdrv_lookup_bs(NULL, str, errp); if (new_backing_bs =3D=3D NULL) { return -EINVAL; @@ -4284,8 +4284,8 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state= , BlockReopenQueue *queue, } =20 if (child) { - const char *str =3D qobject_get_try_str(new); - if (!strcmp(child->bs->node_name, str)) { + if (!strcmp(child->bs->node_name, + qstring_get_str(qobject_to(QString, new)))= ) { continue; /* Found child with this name, skip opti= on */ } } --=20 2.26.2 From nobody Thu May 16 15:04:34 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=1608376745; cv=none; d=zohomail.com; s=zohoarc; b=bGOfHxw67MZHslxwm/7DLvYIUMvmdW0Rgs3OtxxTHPjupbYRntCRYFSQvA/xMRdzHGC5qzbWAn0xcH0+TUamFWZ1HXQntfhAWz2NAuhMRH1t3H5dTFUoPufm+cKDSyGe8WPb/PintyeiLibGKqDng+f3I3jaEYnbCs1QDaiTOkc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608376745; 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=TKn58zkxqk1EeoQRUU0MaGsaJJ+I/4c1ZDLkT/Mn5uA=; b=ZXbion+9ns95DdVQy7DNGg0WsxJWxR9xQM7G/QKMR+mmIs/nk1XK3hLRy/pghDRnrTzU0EqwXMhs9D4tnptWOJlgWkvxhexckjFz35t0B5Xt6YZ51Y0f4oLrxLzmUOO0is6ylvTPjUdoTE9X5BOOrryJHpFDYpFHNM+mKCVGkF0= 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 1608376745379621.2660388899054; Sat, 19 Dec 2020 03:19:05 -0800 (PST) Received: from localhost ([::1]:56168 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqaGO-00026W-Bg for importer@patchew.org; Sat, 19 Dec 2020 06:19:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50918) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZu3-0005Q4-IS for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:59 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:49858) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtk-0007GN-RA for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:59 -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-68-4kM3Vc3QNgaTtjWs__VdYA-1; Sat, 19 Dec 2020 05:55:38 -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 12275107ACF5; Sat, 19 Dec 2020 10:55:37 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D3BD12CC9C; Sat, 19 Dec 2020 10:55:36 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id B8EAB1126833; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375340; 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=TKn58zkxqk1EeoQRUU0MaGsaJJ+I/4c1ZDLkT/Mn5uA=; b=afvQY8tdrUtTVTjXgLD/yqAiBa3j+eeFK9HAPZCBHseETPDB0OUuqGpFUgtj8oVogxh0be 2iOFhasct7EJnXzNYWkTQE/kZSp4V+ihg5Mjy1TRNwMnURzuGDoovjVB944O0PVC7PUF9/ r5fNpB0NDFdJ03UyPtrGa2TdqGcAL+I= X-MC-Unique: 4kM3Vc3QNgaTtjWs__VdYA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 24/33] Revert "qobject: let object_property_get_str() use new API" Date: Sat, 19 Dec 2020 11:55:23 +0100 Message-Id: <20201219105532.1734134-25-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: peter.maydell@linaro.org, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eduardo Habkost , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Commit aafb21a0b9 "qobject: let object_property_get_str() use new API" isn't much of a simplification. Not worth having object_property_get_str() differ from the other object_property_get_FOO(). Revert. This reverts commit aafb21a0b9cea5fa0fe52e68111bb6bd13837a02. Cc: Paolo Bonzini Cc: Daniel P. Berrang=C3=A9 Cc: Eduardo Habkost Signed-off-by: Markus Armbruster Message-Id: <20201211171152.146877-12-armbru@redhat.com> Reviewed-by: Eduardo Habkost --- qom/object.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/qom/object.c b/qom/object.c index f2ae6e6b2a..5cd43fe366 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1415,15 +1415,18 @@ char *object_property_get_str(Object *obj, const ch= ar *name, Error **errp) { QObject *ret =3D object_property_get_qobject(obj, name, errp); + QString *qstring; char *retval; =20 if (!ret) { return NULL; } - - retval =3D g_strdup(qobject_get_try_str(ret)); - if (!retval) { + qstring =3D qobject_to(QString, ret); + if (!qstring) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name, "string"); + retval =3D NULL; + } else { + retval =3D g_strdup(qstring_get_str(qstring)); } =20 qobject_unref(ret); --=20 2.26.2 From nobody Thu May 16 15:04:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608376488; cv=none; d=zohomail.com; s=zohoarc; b=gJa8g/lDlSlI9iqOH2ott5q0kRtmQD6G0Dv5FltBSAyLwN67l3Hb6/7uw83W+SVH/2ce3SrKDHSJaMueVvOoscaeIekJCOmIMXPoZo9bsv+SMH87ajwrlSZtkAZTxPNlD5DnaGPC0u4tOlnDoKuEsCxmC6jtlr7uzg38+FMiG5A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608376488; 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=+yhqNMXyMBdF4Umsr/lTtPXNo5s4KL9qTswNA2mLacs=; b=HwnaApnxwK0xXQB/PEGTCP8vESJ63212BbG33ULRkOkVo2sx8IG+ubaRgE1ikAPWsyHDe7JUyfZenrf8STSrnEOandtxRopJK5rAsxdtw/NpZGgDgEzhrAtMgW//VDO5LQ2lLNfyddaWP/a5EbXOVBb89U2W2kOJ/Ff7skN7XUU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 160837648829892.00437231860622; Sat, 19 Dec 2020 03:14:48 -0800 (PST) Received: from localhost ([::1]:43938 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqaCF-0005R6-6N for importer@patchew.org; Sat, 19 Dec 2020 06:14:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50770) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZtu-0004wa-9s for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:40891) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtl-0007H9-G2 for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:49 -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-112-IZAzAEViNrCBH5UqOysN3Q-1; Sat, 19 Dec 2020 05:55:38 -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 0E91E801A9E; Sat, 19 Dec 2020 10:55:37 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D607260C61; Sat, 19 Dec 2020 10:55:36 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id BD8E8112683F; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375340; 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=+yhqNMXyMBdF4Umsr/lTtPXNo5s4KL9qTswNA2mLacs=; b=A2HWOqc52CWC3/T2JP4FbXxhLbf9wX1W9BP2Vfh++a0KtZaqABSKHgWoguGVwL3LInYEBe FKUt3rJbsS0P4UX+TYrWPirI9AUGv3hL6xUnjU3KscqboLYpBGXUBPBiWwkcYRjkqLr2Kk VNgRa5es2zRNNVtkx1g3fCdZ+HRB/V4= X-MC-Unique: IZAzAEViNrCBH5UqOysN3Q-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 25/33] qobject: Drop qobject_get_try_str() Date: Sat, 19 Dec 2020 11:55:24 +0100 Message-Id: <20201219105532.1734134-26-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Message-Id: <20201211171152.146877-13-armbru@redhat.com> --- include/qapi/qmp/qstring.h | 1 - qobject/qstring.c | 11 ----------- 2 files changed, 12 deletions(-) diff --git a/include/qapi/qmp/qstring.h b/include/qapi/qmp/qstring.h index e4ac761a22..56034dae54 100644 --- a/include/qapi/qmp/qstring.h +++ b/include/qapi/qmp/qstring.h @@ -29,7 +29,6 @@ QString *qstring_from_gstring(GString *gstr); size_t qstring_get_length(const QString *qstring); const char *qstring_get_str(const QString *qstring); const char *qstring_get_try_str(const QString *qstring); -const char *qobject_get_try_str(const QObject *qstring); void qstring_append_int(QString *qstring, int64_t value); void qstring_append(QString *qstring, const char *str); void qstring_append_chr(QString *qstring, int c); diff --git a/qobject/qstring.c b/qobject/qstring.c index d6724bd4e5..cfe3f3bf00 100644 --- a/qobject/qstring.c +++ b/qobject/qstring.c @@ -149,17 +149,6 @@ const char *qstring_get_try_str(const QString *qstring) return qstring ? qstring_get_str(qstring) : NULL; } =20 -/** - * qobject_get_try_str(): Return a pointer to the corresponding string - * - * NOTE: the string will only be returned if the object is valid, and - * its type is QString, otherwise NULL is returned. - */ -const char *qobject_get_try_str(const QObject *qstring) -{ - return qstring_get_try_str(qobject_to(QString, qstring)); -} - /** * qstring_is_equal(): Test whether the two QStrings are equal */ --=20 2.26.2 From nobody Thu May 16 15:04:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608375925; cv=none; d=zohomail.com; s=zohoarc; b=F4mVTWTDqwXQr2JPvLMKyymQNge1a2sPK7ZQQncmzgE6wQlKbwnZAgwWBqW9BPDxag/AvyFBqUTIbpDQe9i6lV7wYhvzjFs9oLor8KM69kGqAWXNzIeEt3mXVF6j90fqHGnDIlP+9tGagkRNBrtXZnvaBRuDfhu79RKZqVY+8Js= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608375925; 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=SllfA2N6rUeiGlBN0XXzFzmBSwlJl7y67Ae4fWix+Zs=; b=FuqI7lDbJU7ne5hlWLSogr2I/rn8dgs/wBuVgKdCiBwgQKodAvglQ8UYJRlbjkvzbF3+5j3O2jN1z6soKsxdZOaDP6LQqo/Lq6AuVYSPaTpo/ASuG+E2DIqKq1zGi75yy6p7Hsy7LJEYE03225Irq5LsuvjPARDc3xFqcKiObNc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1608375925178257.50376089770907; Sat, 19 Dec 2020 03:05:25 -0800 (PST) Received: from localhost ([::1]:38806 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqa3A-0008TY-1B for importer@patchew.org; Sat, 19 Dec 2020 06:05:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50738) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZts-0004qx-D2 for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:48 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:54907) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtl-0007Gx-Ef for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:48 -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-68-9FUwyJhFM5GYmjwDQLj6SQ-1; Sat, 19 Dec 2020 05:55:38 -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 12750180A096; Sat, 19 Dec 2020 10:55:37 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D9AAB5D769; Sat, 19 Dec 2020 10:55:36 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id C25491125643; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375340; 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=SllfA2N6rUeiGlBN0XXzFzmBSwlJl7y67Ae4fWix+Zs=; b=IJsykYtcS2v3aVob6NK8H4M78hWqkIdmtXEw5GtqnzRj9fZJ0cewqUZ5VUrJ45S5rxnBXZ JGouxkqxOo/HzrN5ISwsO65EwTNLqOhP1fEX00bGJ72faAZULeRgoHXarzDH/1NQ6y3V34 AtoWz2l/xL1nTD1HQIPtcu+xX3W5yKE= X-MC-Unique: 9FUwyJhFM5GYmjwDQLj6SQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 26/33] qobject: Drop qstring_get_try_str() Date: Sat, 19 Dec 2020 11:55:25 +0100 Message-Id: <20201219105532.1734134-27-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" No users left outside tests/, and the ones in tests/ can just as well use qstring_get_str(). Do that, and drop the function. Signed-off-by: Markus Armbruster Message-Id: <20201211171152.146877-14-armbru@redhat.com> --- include/qapi/qmp/qstring.h | 1 - qobject/qstring.c | 10 ---------- tests/check-qjson.c | 11 +++++------ 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/include/qapi/qmp/qstring.h b/include/qapi/qmp/qstring.h index 56034dae54..53567db6c0 100644 --- a/include/qapi/qmp/qstring.h +++ b/include/qapi/qmp/qstring.h @@ -28,7 +28,6 @@ QString *qstring_from_substr(const char *str, size_t star= t, size_t end); QString *qstring_from_gstring(GString *gstr); size_t qstring_get_length(const QString *qstring); const char *qstring_get_str(const QString *qstring); -const char *qstring_get_try_str(const QString *qstring); void qstring_append_int(QString *qstring, int64_t value); void qstring_append(QString *qstring, const char *str); void qstring_append_chr(QString *qstring, int c); diff --git a/qobject/qstring.c b/qobject/qstring.c index cfe3f3bf00..ea86d80cf0 100644 --- a/qobject/qstring.c +++ b/qobject/qstring.c @@ -139,16 +139,6 @@ const char *qstring_get_str(const QString *qstring) return qstring->string; } =20 -/** - * qstring_get_try_str(): Return a pointer to the stored string - * - * NOTE: will return NULL if qstring is not provided. - */ -const char *qstring_get_try_str(const QString *qstring) -{ - return qstring ? qstring_get_str(qstring) : NULL; -} - /** * qstring_is_equal(): Test whether the two QStrings are equal */ diff --git a/tests/check-qjson.c b/tests/check-qjson.c index 337add0838..c845f91d43 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -89,7 +89,7 @@ static void escaped_string(void) for (j =3D 0; j < 2; j++) { if (test_cases[i].utf8_out) { cstr =3D from_json_str(test_cases[i].json_in, j, &error_ab= ort); - g_assert_cmpstr(qstring_get_try_str(cstr), + g_assert_cmpstr(qstring_get_str(cstr), =3D=3D, test_cases[i].utf8_out); if (!test_cases[i].skip) { jstr =3D to_json_str(cstr); @@ -751,7 +751,7 @@ static void utf8_string(void) /* Parse @json_in, expect @utf8_out */ if (utf8_out) { str =3D from_json_str(json_in, j, &error_abort); - g_assert_cmpstr(qstring_get_try_str(str), =3D=3D, utf8_out= ); + g_assert_cmpstr(qstring_get_str(str), =3D=3D, utf8_out); qobject_unref(str); } else { str =3D from_json_str(json_in, j, NULL); @@ -782,7 +782,7 @@ static void utf8_string(void) /* Parse @json_out right back, unless it has replacements */ if (!strstr(json_out, "\\uFFFD")) { str =3D from_json_str(json_out, j, &error_abort); - g_assert_cmpstr(qstring_get_try_str(str), =3D=3D, utf8_in); + g_assert_cmpstr(qstring_get_str(str), =3D=3D, utf8_in); qobject_unref(str); } } @@ -1021,9 +1021,8 @@ static void interpolation_valid(void) =20 /* string */ =20 - qstr =3D qobject_to(QString, - qobject_from_jsonf_nofail("%s", value_s)); - g_assert_cmpstr(qstring_get_try_str(qstr), =3D=3D, value_s); + qstr =3D qobject_to(QString, qobject_from_jsonf_nofail("%s", value_s)); + g_assert_cmpstr(qstring_get_str(qstr), =3D=3D, value_s); qobject_unref(qstr); =20 /* object */ --=20 2.26.2 From nobody Thu May 16 15:04:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608376065; cv=none; d=zohomail.com; s=zohoarc; b=bnmXIgnyndBcNUWr1Ft6paggJxz7EdaZ4SrUASVsV/tzkYPsoskhtNHXPy5mFmXHn18hWFCMQC6+S+oD+MJsTQgnV8Xs/V/RaBzoV0hnnYO6VBDKSbIRj4LAs2TZD027ThtH6elm97r225mJ1U7fwAIp7iEkgb0qGXHqis0ISA4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608376065; 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=8+TIx5BUivhcBaDYs/Fddcv8Oasy9cn6EtQxoHAhUek=; b=TQKDGs9LAqAceZGVIfxb3R2HF2q7Sfs6C7nKqBRAkDSmsdoQh+9p1RM7ZHIwv9BezD49hjmTYJd+OFYIgGGpy8chN64dx30/puTgLjeTy4HwrA+aIAPUXYHMU5gtiAu6mEFsgELyq3oLsDqwx5RwI36nX93Gsod8nwiqh4jH02c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1608376065541163.3987308489801; Sat, 19 Dec 2020 03:07:45 -0800 (PST) Received: from localhost ([::1]:47864 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqa5Q-0003lZ-5G for importer@patchew.org; Sat, 19 Dec 2020 06:07:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50818) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZtw-00053n-EN for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:52 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:53603) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtl-0007Hm-U0 for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:52 -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-122-OselJvTyNGeW_EOPnTpG_w-1; Sat, 19 Dec 2020 05:55:38 -0500 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 39561107ACF6; Sat, 19 Dec 2020 10:55:37 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DA88750DD3; Sat, 19 Dec 2020 10:55:36 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id C74371125648; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375341; 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=8+TIx5BUivhcBaDYs/Fddcv8Oasy9cn6EtQxoHAhUek=; b=jC1SimSBlI8rRpZTrCRny2Gspocp3M+ZBvyg4+cz++h0FMfD047jyG91tGuHHuPP+7LqAk j9+bKlDINNDF9vDQk8Ko0VVERllUrpDor8Y8jgaZZY+36FVLRRAFP7aTV7nWSmKxV44R+O oATH66blsy+7yAKdX4uUQLFuZQOmM2c= X-MC-Unique: OselJvTyNGeW_EOPnTpG_w-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 27/33] qobject: Factor quoted_str() out of to_json() Date: Sat, 19 Dec 2020 11:55:26 +0100 Message-Id: <20201219105532.1734134-28-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Message-Id: <20201211171152.146877-15-armbru@redhat.com> --- qobject/qjson.c | 110 ++++++++++++++++++++++++------------------------ 1 file changed, 54 insertions(+), 56 deletions(-) diff --git a/qobject/qjson.c b/qobject/qjson.c index 2f690c1816..962214f5a7 100644 --- a/qobject/qjson.c +++ b/qobject/qjson.c @@ -156,6 +156,58 @@ static void json_pretty_newline(GString *accu, bool pr= etty, int indent) } } =20 +static void quoted_str(const char *str, GString *accu) +{ + const char *ptr; + int cp; + char *end; + + g_string_append_c(accu, '"'); + + for (ptr =3D str; *ptr; ptr =3D end) { + cp =3D mod_utf8_codepoint(ptr, 6, &end); + switch (cp) { + case '\"': + g_string_append(accu, "\\\""); + break; + case '\\': + g_string_append(accu, "\\\\"); + break; + case '\b': + g_string_append(accu, "\\b"); + break; + case '\f': + g_string_append(accu, "\\f"); + break; + case '\n': + g_string_append(accu, "\\n"); + break; + case '\r': + g_string_append(accu, "\\r"); + break; + case '\t': + g_string_append(accu, "\\t"); + break; + default: + if (cp < 0) { + cp =3D 0xFFFD; /* replacement character */ + } + if (cp > 0xFFFF) { + /* beyond BMP; need a surrogate pair */ + g_string_append_printf(accu, "\\u%04X\\u%04X", + 0xD800 + ((cp - 0x10000) >> 10), + 0xDC00 + ((cp - 0x10000) & 0x3FF)); + } else if (cp < 0x20 || cp >=3D 0x7F) { + g_string_append_printf(accu, "\\u%04X", cp); + } else { + g_string_append_c(accu, cp); + } + } + }; + + g_string_append_c(accu, '"'); +} + static void to_json(const QObject *obj, GString *accu, bool pretty, int in= dent) { switch (qobject_type(obj)) { @@ -170,56 +222,7 @@ static void to_json(const QObject *obj, GString *accu,= bool pretty, int indent) break; } case QTYPE_QSTRING: { - QString *val =3D qobject_to(QString, obj); - const char *ptr; - int cp; - char *end; - - ptr =3D qstring_get_str(val); - g_string_append_c(accu, '"'); - - for (; *ptr; ptr =3D end) { - cp =3D mod_utf8_codepoint(ptr, 6, &end); - switch (cp) { - case '\"': - g_string_append(accu, "\\\""); - break; - case '\\': - g_string_append(accu, "\\\\"); - break; - case '\b': - g_string_append(accu, "\\b"); - break; - case '\f': - g_string_append(accu, "\\f"); - break; - case '\n': - g_string_append(accu, "\\n"); - break; - case '\r': - g_string_append(accu, "\\r"); - break; - case '\t': - g_string_append(accu, "\\t"); - break; - default: - if (cp < 0) { - cp =3D 0xFFFD; /* replacement character */ - } - if (cp > 0xFFFF) { - /* beyond BMP; need a surrogate pair */ - g_string_append_printf(accu, "\\u%04X\\u%04X", - 0xD800 + ((cp - 0x10000) >> 10), - 0xDC00 + ((cp - 0x10000) & 0x3F= F)); - } else if (cp < 0x20 || cp >=3D 0x7F) { - g_string_append_printf(accu, "\\u%04X", cp); - } else { - g_string_append_c(accu, cp); - } - } - }; - - g_string_append_c(accu, '"'); + quoted_str(qstring_get_str(qobject_to(QString, obj)), accu); break; } case QTYPE_QDICT: { @@ -227,7 +230,6 @@ static void to_json(const QObject *obj, GString *accu, = bool pretty, int indent) const char *comma =3D pretty ? "," : ", "; const char *sep =3D ""; const QDictEntry *entry; - QString *qkey; =20 g_string_append_c(accu, '{'); =20 @@ -236,11 +238,7 @@ static void to_json(const QObject *obj, GString *accu,= bool pretty, int indent) entry =3D qdict_next(val, entry)) { g_string_append(accu, sep); json_pretty_newline(accu, pretty, indent + 1); - - qkey =3D qstring_from_str(qdict_entry_key(entry)); - to_json(QOBJECT(qkey), accu, pretty, indent + 1); - qobject_unref(qkey); - + quoted_str(qdict_entry_key(entry), accu); g_string_append(accu, ": "); to_json(qdict_entry_value(entry), accu, pretty, indent + 1); sep =3D comma; --=20 2.26.2 From nobody Thu May 16 15:04:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608376188; cv=none; d=zohomail.com; s=zohoarc; b=b8/XeBU/x7MUANwc/H9oqfXBZxJXz0zbzT5mw2iUVFqeEyud2OFKm9rFHqOMZCHRqj4e++Z12wVW9OAtnXxW7BlhmbGPuDHjX3DkX+OVwJN7mKxHqBP8W+RUskyxVdW4mP1tDeJyxNpV03ysKTo8Qv9HGw06BMhKxXWTCNUdklA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608376188; 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=zRXFFeI5pV1pyhLSA6cKFOOfp52+WoAm8StU4ehr1+4=; b=asBxidyNHzeWnZql1W0iyVRRRnR9LGc7nANGnYz8tV0HkURBHlRHKPb+qvlPUqUaa0XWrh0szxJpWI6ejCvx7l49PLC6y10UEZQv7vmW4GzQeBtrNNZIrCq8hohe5YRt6IjA7YqlzDY6OMgyxbPGQPvyNYJB0Uq+DAszfNHgFF8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1608376188663910.9218143052319; Sat, 19 Dec 2020 03:09:48 -0800 (PST) Received: from localhost ([::1]:56434 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqa7P-0007FQ-Hf for importer@patchew.org; Sat, 19 Dec 2020 06:09:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50750) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZtt-0004t4-B4 for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:49 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:48132) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtl-0007H6-D4 for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:49 -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-137-d0avpLmKONOaG64Jxg0rqw-1; Sat, 19 Dec 2020 05:55:38 -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 63B8651E6; Sat, 19 Dec 2020 10:55:37 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DF31360C62; Sat, 19 Dec 2020 10:55:36 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id CCA401125649; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375340; 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=zRXFFeI5pV1pyhLSA6cKFOOfp52+WoAm8StU4ehr1+4=; b=PBIMLWbrMYjpO87tn+M1XZJPfYpcWp/0aLfbbhyaBBFa6kiyelQen8vpy5oZRH1tguQYrA 6SxQ+UwKhORAV+6ld9UfFIH62hehCvtzvqAoGiiPMTFa9/yPio4+iEWjcTiN5s/SK/X5n2 bGVuJ4VXVW4H2uMNQSzHpXjQIfLe4MY= X-MC-Unique: d0avpLmKONOaG64Jxg0rqw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 28/33] qobject: Factor JSON writer out of qobject_to_json() Date: Sat, 19 Dec 2020 11:55:27 +0100 Message-Id: <20201219105532.1734134-29-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H3=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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" We have two JSON writers written in C: qobject/qjson.c provides qobject_to_json(), and migration/qjson.c provides a more low level imperative interface. They don't share code. The latter tacitly limits numbers to int64_t, and strings contents to characters that don't need escaping. Factor out qobject_to_json()'s JSON writer as qobject/json-writer.c. Straightforward, except for numbers: since the writer is to be independent of QObject, it can't use qnum_to_string(). Open-code it instead. This is actually an improvement of sorts, because it liberates qnum_to_string() from JSON's needs: its JSON-related FIXMEs move to the JSON writer, where they belong. The next commit will replace migration/qjson.c. Signed-off-by: Markus Armbruster Message-Id: <20201211171152.146877-16-armbru@redhat.com> --- include/qapi/qmp/json-writer.h | 37 +++++ qobject/json-writer.c | 247 +++++++++++++++++++++++++++++++++ qobject/qjson.c | 125 +++++------------ qobject/qnum.c | 5 - qobject/meson.build | 5 +- 5 files changed, 318 insertions(+), 101 deletions(-) create mode 100644 include/qapi/qmp/json-writer.h create mode 100644 qobject/json-writer.c diff --git a/include/qapi/qmp/json-writer.h b/include/qapi/qmp/json-writer.h new file mode 100644 index 0000000000..708d129018 --- /dev/null +++ b/include/qapi/qmp/json-writer.h @@ -0,0 +1,37 @@ +/* + * JSON Writer + * + * Copyright (c) 2020 Red Hat Inc. + * + * Authors: + * Markus Armbruster + * + * 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. + * + */ + +#ifndef JSON_WRITER_H +#define JSON_WRITER_H + +typedef struct JSONWriter JSONWriter; + +JSONWriter *json_writer_new(bool pretty); +const char *json_writer_get(JSONWriter *); +GString *json_writer_get_and_free(JSONWriter *); +void json_writer_free(JSONWriter *); + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(JSONWriter, json_writer_free) + +void json_writer_start_object(JSONWriter *, const char *name); +void json_writer_end_object(JSONWriter *); +void json_writer_start_array(JSONWriter *, const char *name); +void json_writer_end_array(JSONWriter *); +void json_writer_bool(JSONWriter *, const char *name, bool val); +void json_writer_null(JSONWriter *, const char *name); +void json_writer_int64(JSONWriter *, const char *name, int64_t val); +void json_writer_uint64(JSONWriter *, const char *name, uint64_t val); +void json_writer_double(JSONWriter *, const char *name, double val); +void json_writer_str(JSONWriter *, const char *name, const char *str); + +#endif diff --git a/qobject/json-writer.c b/qobject/json-writer.c new file mode 100644 index 0000000000..309a31d57a --- /dev/null +++ b/qobject/json-writer.c @@ -0,0 +1,247 @@ +/* + * JSON Writer + * + * Copyright IBM, Corp. 2009 + * Copyright (c) 2010-2020 Red Hat Inc. + * + * Authors: + * Anthony Liguori + * Markus Armbruster + * + * 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. + * + */ + +#include "qemu/osdep.h" +#include "qapi/qmp/json-writer.h" +#include "qemu/unicode.h" + +struct JSONWriter { + bool pretty; + bool need_comma; + GString *contents; + GByteArray *container_is_array; +}; + +JSONWriter *json_writer_new(bool pretty) +{ + JSONWriter *writer =3D g_new(JSONWriter, 1); + + writer->pretty =3D pretty; + writer->need_comma =3D false; + writer->contents =3D g_string_new(NULL); + writer->container_is_array =3D g_byte_array_new(); + return writer; +} + +const char *json_writer_get(JSONWriter *writer) +{ + g_assert(!writer->container_is_array->len); + return writer->contents->str; +} + +GString *json_writer_get_and_free(JSONWriter *writer) +{ + GString *contents =3D writer->contents; + + writer->contents =3D NULL; + g_byte_array_free(writer->container_is_array, true); + g_free(writer); + return contents; +} + +void json_writer_free(JSONWriter *writer) +{ + if (writer) { + g_string_free(json_writer_get_and_free(writer), true); + } +} + +static void enter_container(JSONWriter *writer, bool is_array) +{ + unsigned depth =3D writer->container_is_array->len; + + g_byte_array_set_size(writer->container_is_array, depth + 1); + writer->container_is_array->data[depth] =3D is_array; + writer->need_comma =3D false; +} + +static void leave_container(JSONWriter *writer, bool is_array) +{ + unsigned depth =3D writer->container_is_array->len; + + assert(depth); + assert(writer->container_is_array->data[depth - 1] =3D=3D is_array); + g_byte_array_set_size(writer->container_is_array, depth - 1); + writer->need_comma =3D true; +} + +static bool in_object(JSONWriter *writer) +{ + unsigned depth =3D writer->container_is_array->len; + + return depth && !writer->container_is_array->data[depth - 1]; +} + +static void pretty_newline(JSONWriter *writer) +{ + if (writer->pretty) { + g_string_append_printf(writer->contents, "\n%*s", + writer->container_is_array->len * 4, ""); + } +} + +static void pretty_newline_or_space(JSONWriter *writer) +{ + if (writer->pretty) { + g_string_append_printf(writer->contents, "\n%*s", + writer->container_is_array->len * 4, ""); + } else { + g_string_append_c(writer->contents, ' '); + } +} + +static void quoted_str(JSONWriter *writer, const char *str) +{ + const char *ptr; + char *end; + int cp; + + g_string_append_c(writer->contents, '"'); + + for (ptr =3D str; *ptr; ptr =3D end) { + cp =3D mod_utf8_codepoint(ptr, 6, &end); + switch (cp) { + case '\"': + g_string_append(writer->contents, "\\\""); + break; + case '\\': + g_string_append(writer->contents, "\\\\"); + break; + case '\b': + g_string_append(writer->contents, "\\b"); + break; + case '\f': + g_string_append(writer->contents, "\\f"); + break; + case '\n': + g_string_append(writer->contents, "\\n"); + break; + case '\r': + g_string_append(writer->contents, "\\r"); + break; + case '\t': + g_string_append(writer->contents, "\\t"); + break; + default: + if (cp < 0) { + cp =3D 0xFFFD; /* replacement character */ + } + if (cp > 0xFFFF) { + /* beyond BMP; need a surrogate pair */ + g_string_append_printf(writer->contents, "\\u%04X\\u%04X", + 0xD800 + ((cp - 0x10000) >> 10), + 0xDC00 + ((cp - 0x10000) & 0x3FF)); + } else if (cp < 0x20 || cp >=3D 0x7F) { + g_string_append_printf(writer->contents, "\\u%04X", cp); + } else { + g_string_append_c(writer->contents, cp); + } + } + }; + + g_string_append_c(writer->contents, '"'); +} + +static void maybe_comma_name(JSONWriter *writer, const char *name) +{ + if (writer->need_comma) { + g_string_append_c(writer->contents, ','); + pretty_newline_or_space(writer); + } else { + if (writer->contents->len) { + pretty_newline(writer); + } + writer->need_comma =3D true; + } + + if (in_object(writer)) { + quoted_str(writer, name); + g_string_append(writer->contents, ": "); + } +} + +void json_writer_start_object(JSONWriter *writer, const char *name) +{ + maybe_comma_name(writer, name); + g_string_append_c(writer->contents, '{'); + enter_container(writer, false); +} + +void json_writer_end_object(JSONWriter *writer) +{ + leave_container(writer, false); + pretty_newline(writer); + g_string_append_c(writer->contents, '}'); +} + +void json_writer_start_array(JSONWriter *writer, const char *name) +{ + maybe_comma_name(writer, name); + g_string_append_c(writer->contents, '['); + enter_container(writer, true); +} + +void json_writer_end_array(JSONWriter *writer) +{ + leave_container(writer, true); + pretty_newline(writer); + g_string_append_c(writer->contents, ']'); +} + +void json_writer_bool(JSONWriter *writer, const char *name, bool val) +{ + maybe_comma_name(writer, name); + g_string_append(writer->contents, val ? "true" : "false"); +} + +void json_writer_null(JSONWriter *writer, const char *name) +{ + maybe_comma_name(writer, name); + g_string_append(writer->contents, "null"); +} + +void json_writer_int64(JSONWriter *writer, const char *name, int64_t val) +{ + maybe_comma_name(writer, name); + g_string_append_printf(writer->contents, "%" PRId64, val); +} + +void json_writer_uint64(JSONWriter *writer, const char *name, uint64_t val) +{ + maybe_comma_name(writer, name); + g_string_append_printf(writer->contents, "%" PRIu64, val); +} + +void json_writer_double(JSONWriter *writer, const char *name, double val) +{ + maybe_comma_name(writer, name); + + /* + * FIXME: g_string_append_printf() is locale dependent; but JSON + * requires numbers to be formatted as if in the C locale. + * Dependence on C locale is a pervasive issue in QEMU. + */ + /* + * FIXME: This risks printing Inf or NaN, which are not valid + * JSON values. + */ + g_string_append_printf(writer->contents, "%.17g", val); +} + +void json_writer_str(JSONWriter *writer, const char *name, const char *str) +{ + maybe_comma_name(writer, name); + quoted_str(writer, str); +} diff --git a/qobject/qjson.c b/qobject/qjson.c index 962214f5a7..bcc376e626 100644 --- a/qobject/qjson.c +++ b/qobject/qjson.c @@ -14,13 +14,13 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "qapi/qmp/json-parser.h" +#include "qapi/qmp/json-writer.h" #include "qapi/qmp/qjson.h" #include "qapi/qmp/qbool.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qlist.h" #include "qapi/qmp/qnum.h" #include "qapi/qmp/qstring.h" -#include "qemu/unicode.h" =20 typedef struct JSONParsingState { @@ -149,132 +149,69 @@ QDict *qdict_from_jsonf_nofail(const char *string, .= ..) return qdict; } =20 -static void json_pretty_newline(GString *accu, bool pretty, int indent) -{ - if (pretty) { - g_string_append_printf(accu, "\n%*s", indent * 4, ""); - } -} - -static void quoted_str(const char *str, GString *accu) -{ - const char *ptr; - int cp; - char *end; - - g_string_append_c(accu, '"'); - - for (ptr =3D str; *ptr; ptr =3D end) { - cp =3D mod_utf8_codepoint(ptr, 6, &end); - switch (cp) { - case '\"': - g_string_append(accu, "\\\""); - break; - case '\\': - g_string_append(accu, "\\\\"); - break; - case '\b': - g_string_append(accu, "\\b"); - break; - case '\f': - g_string_append(accu, "\\f"); - break; - case '\n': - g_string_append(accu, "\\n"); - break; - case '\r': - g_string_append(accu, "\\r"); - break; - case '\t': - g_string_append(accu, "\\t"); - break; - default: - if (cp < 0) { - cp =3D 0xFFFD; /* replacement character */ - } - if (cp > 0xFFFF) { - /* beyond BMP; need a surrogate pair */ - g_string_append_printf(accu, "\\u%04X\\u%04X", - 0xD800 + ((cp - 0x10000) >> 10), - 0xDC00 + ((cp - 0x10000) & 0x3FF)); - } else if (cp < 0x20 || cp >=3D 0x7F) { - g_string_append_printf(accu, "\\u%04X", cp); - } else { - g_string_append_c(accu, cp); - } - } - }; - - g_string_append_c(accu, '"'); -} - -static void to_json(const QObject *obj, GString *accu, bool pretty, int in= dent) +static void to_json(JSONWriter *writer, const char *name, + const QObject *obj) { switch (qobject_type(obj)) { case QTYPE_QNULL: - g_string_append(accu, "null"); + json_writer_null(writer, name); break; case QTYPE_QNUM: { QNum *val =3D qobject_to(QNum, obj); - char *buffer =3D qnum_to_string(val); - g_string_append(accu, buffer); - g_free(buffer); + + switch (val->kind) { + case QNUM_I64: + json_writer_int64(writer, name, val->u.i64); + break; + case QNUM_U64: + json_writer_uint64(writer, name, val->u.u64); + break; + case QNUM_DOUBLE: + json_writer_double(writer, name, val->u.dbl); + break; + default: + abort(); + } break; } case QTYPE_QSTRING: { - quoted_str(qstring_get_str(qobject_to(QString, obj)), accu); + QString *val =3D qobject_to(QString, obj); + + json_writer_str(writer, name, qstring_get_str(val)); break; } case QTYPE_QDICT: { QDict *val =3D qobject_to(QDict, obj); - const char *comma =3D pretty ? "," : ", "; - const char *sep =3D ""; const QDictEntry *entry; =20 - g_string_append_c(accu, '{'); + json_writer_start_object(writer, name); =20 for (entry =3D qdict_first(val); entry; entry =3D qdict_next(val, entry)) { - g_string_append(accu, sep); - json_pretty_newline(accu, pretty, indent + 1); - quoted_str(qdict_entry_key(entry), accu); - g_string_append(accu, ": "); - to_json(qdict_entry_value(entry), accu, pretty, indent + 1); - sep =3D comma; + to_json(writer, qdict_entry_key(entry), qdict_entry_value(entr= y)); } =20 - json_pretty_newline(accu, pretty, indent); - g_string_append_c(accu, '}'); + json_writer_end_object(writer); break; } case QTYPE_QLIST: { QList *val =3D qobject_to(QList, obj); - const char *comma =3D pretty ? "," : ", "; - const char *sep =3D ""; QListEntry *entry; =20 - g_string_append_c(accu, '['); + json_writer_start_array(writer, name); =20 QLIST_FOREACH_ENTRY(val, entry) { - g_string_append(accu, sep); - json_pretty_newline(accu, pretty, indent + 1); - to_json(qlist_entry_obj(entry), accu, pretty, indent + 1); - sep =3D comma; + to_json(writer, NULL, qlist_entry_obj(entry)); } =20 - json_pretty_newline(accu, pretty, indent); - g_string_append_c(accu, ']'); + json_writer_end_array(writer); break; } case QTYPE_QBOOL: { QBool *val =3D qobject_to(QBool, obj); =20 - if (qbool_get_bool(val)) { - g_string_append(accu, "true"); - } else { - g_string_append(accu, "false"); - } + json_writer_bool(writer, name, qbool_get_bool(val)); break; } default: @@ -284,10 +221,10 @@ static void to_json(const QObject *obj, GString *accu= , bool pretty, int indent) =20 GString *qobject_to_json_pretty(const QObject *obj, bool pretty) { - GString *accu =3D g_string_new(NULL); + JSONWriter *writer =3D json_writer_new(pretty); =20 - to_json(obj, accu, pretty, 0); - return accu; + to_json(writer, NULL, obj); + return json_writer_get_and_free(writer); } =20 GString *qobject_to_json(const QObject *obj) diff --git a/qobject/qnum.c b/qobject/qnum.c index 35ba41e61c..5dd66938dd 100644 --- a/qobject/qnum.c +++ b/qobject/qnum.c @@ -168,11 +168,6 @@ char *qnum_to_string(QNum *qn) case QNUM_U64: return g_strdup_printf("%" PRIu64, qn->u.u64); case QNUM_DOUBLE: - /* FIXME: g_strdup_printf() is locale dependent; but JSON requires - * numbers to be formatted as if in the C locale. Dependence - * on C locale is a pervasive issue in QEMU. */ - /* FIXME: This risks printing Inf or NaN, which are not valid - * JSON values. */ /* 17 digits suffice for IEEE double */ return g_strdup_printf("%.17g", qn->u.dbl); } diff --git a/qobject/meson.build b/qobject/meson.build index bb63c06b63..4683a852a2 100644 --- a/qobject/meson.build +++ b/qobject/meson.build @@ -1,3 +1,4 @@ -util_ss.add(files('qnull.c', 'qnum.c', 'qstring.c', 'qdict.c', 'qlist.c', = 'qbool.c', - 'qlit.c', 'qjson.c', 'qobject.c', 'json-lexer.c', 'json-streamer.c', 'js= on-parser.c', +util_ss.add(files('qnull.c', 'qnum.c', 'qstring.c', 'qdict.c', + 'qlist.c', 'qbool.c', 'qlit.c', 'qjson.c', 'qobject.c', + 'json-writer.c', 'json-lexer.c', 'json-streamer.c', 'json-parser.c', 'block-qdict.c')) --=20 2.26.2 From nobody Thu May 16 15:04:34 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=1608376746; cv=none; d=zohomail.com; s=zohoarc; b=d/2FWqxvJ4MM1E/W6dr9bJIRcU8vf+BmlSsh8POSmCLBPk8yppoR/4hoNLHPn2dM7iMR1xm6q2XQOZ6DqEIgasiGJZEc44/zZShhxScja9FE3b1xxRRv/gqyEvk7sPyx7M+FpxobKzUXQwc5naEttotLyFlNLnnE10z/hy6mUA0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608376746; 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=SMa7gcKR2ofIUXs+v5tSllk8qRUjFgGJqhUEEx8IYag=; b=kZcUGbaR726uXROV2tmQ4Z24g0h3H+4H8LA8xnkRjwIZRWdi6N0aDPup22OAYF+nza/0OVHCLE6iGXgNd/6jk3P/R9pM6pOgXSyNFN118PCRf0JpWotfiqKHPn5YHqG7gPMk4xYs6wL3oaYcTcSrgE7VCqocYgygmSNcNowPFcw= 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 1608376746555500.7491002491482; Sat, 19 Dec 2020 03:19:06 -0800 (PST) Received: from localhost ([::1]:56136 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqaGP-00025n-9F for importer@patchew.org; Sat, 19 Dec 2020 06:19:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50902) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZu2-0005Lu-0S for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:45074) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtn-0007IP-8L for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:57 -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-164-EtX8R8vsP4Gyx6WoVE12WA-1; Sat, 19 Dec 2020 05:55:39 -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 C3B76180A094; Sat, 19 Dec 2020 10:55:38 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 20E315D769; Sat, 19 Dec 2020 10:55:38 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id D2C87112564A; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375342; 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=SMa7gcKR2ofIUXs+v5tSllk8qRUjFgGJqhUEEx8IYag=; b=Br/lHabb9XPdfhu9Sy1XeAlnl4Vf5Vnyir323jXGx15LFBEF3lw0RSRDtrD76xo/rI46gk DN5SZiL9Vl6vnauQ7otIL9D1n6QNj+dnIRWzcUED9lRCHCfyufvz4vS3rwNapLDS4Bt5Hj WB2ppynvdVwFBs+7RS2mU30dXa2gJhs= X-MC-Unique: EtX8R8vsP4Gyx6WoVE12WA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 29/33] migration: Replace migration's JSON writer by the general one Date: Sat, 19 Dec 2020 11:55:28 +0100 Message-Id: <20201219105532.1734134-30-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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: peter.maydell@linaro.org, "Dr . David Alan Gilbert" , Juan Quintela 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" Commit 8118f0950f "migration: Append JSON description of migration stream" needs a JSON writer. The existing qobject_to_json() wasn't a good fit, because it requires building a QObject to convert. Instead, migration got its very own JSON writer, in commit 190c882ce2 "QJSON: Add JSON writer". It tacitly limits numbers to int64_t, and strings contents to characters that don't need escaping, unlike qobject_to_json(). The previous commit factored the JSON writer out of qobject_to_json(). Replace migration's JSON writer by it. Cc: Juan Quintela Cc: Dr. David Alan Gilbert Signed-off-by: Markus Armbruster Message-Id: <20201211171152.146877-17-armbru@redhat.com> Reviewed-by: Dr. David Alan Gilbert --- include/migration/vmstate.h | 7 +- include/qapi/qmp/json-writer.h | 2 - include/qemu/typedefs.h | 4 +- migration/qjson.h | 29 --------- hw/display/virtio-gpu.c | 2 +- hw/intc/s390_flic_kvm.c | 2 +- hw/nvram/eeprom93xx.c | 2 +- hw/nvram/fw_cfg.c | 2 +- hw/pci/msix.c | 2 +- hw/pci/pci.c | 4 +- hw/pci/shpc.c | 2 +- hw/rtc/twl92230.c | 2 +- hw/scsi/scsi-bus.c | 2 +- hw/usb/redirect.c | 7 +- hw/virtio/virtio.c | 4 +- migration/qjson.c | 114 --------------------------------- migration/savevm.c | 53 +++++++-------- migration/vmstate-types.c | 38 +++++------ migration/vmstate.c | 52 +++++++-------- target/alpha/machine.c | 2 +- target/arm/machine.c | 6 +- target/avr/machine.c | 4 +- target/hppa/machine.c | 4 +- target/microblaze/machine.c | 2 +- target/mips/machine.c | 4 +- target/openrisc/machine.c | 2 +- target/ppc/machine.c | 10 +-- target/sparc/machine.c | 2 +- migration/meson.build | 1 - 29 files changed, 114 insertions(+), 253 deletions(-) delete mode 100644 migration/qjson.h delete mode 100644 migration/qjson.c diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 4d71dc8fba..075ee80096 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -43,7 +43,7 @@ struct VMStateInfo { const char *name; int (*get)(QEMUFile *f, void *pv, size_t size, const VMStateField *fie= ld); int (*put)(QEMUFile *f, void *pv, size_t size, const VMStateField *fie= ld, - QJSON *vmdesc); + JSONWriter *vmdesc); }; =20 enum VMStateFlags { @@ -1169,9 +1169,10 @@ extern const VMStateInfo vmstate_info_qlist; int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, void *opaque, int version_id); int vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, - void *opaque, QJSON *vmdesc); + void *opaque, JSONWriter *vmdesc); int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd, - void *opaque, QJSON *vmdesc, int version_id); + void *opaque, JSONWriter *vmdesc, + int version_id); =20 bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque); =20 diff --git a/include/qapi/qmp/json-writer.h b/include/qapi/qmp/json-writer.h index 708d129018..b70ba64077 100644 --- a/include/qapi/qmp/json-writer.h +++ b/include/qapi/qmp/json-writer.h @@ -14,8 +14,6 @@ #ifndef JSON_WRITER_H #define JSON_WRITER_H =20 -typedef struct JSONWriter JSONWriter; - JSONWriter *json_writer_new(bool pretty); const char *json_writer_get(JSONWriter *); GString *json_writer_get_and_free(JSONWriter *); diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index 6281eae3b5..976b529dfb 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -57,8 +57,8 @@ typedef struct IOMMUMemoryRegion IOMMUMemoryRegion; typedef struct ISABus ISABus; typedef struct ISADevice ISADevice; typedef struct IsaDma IsaDma; +typedef struct JSONWriter JSONWriter; typedef struct MACAddr MACAddr; -typedef struct ReservedRegion ReservedRegion; typedef struct MachineClass MachineClass; typedef struct MachineState MachineState; typedef struct MemoryListener MemoryListener; @@ -107,7 +107,6 @@ typedef struct QEMUSGList QEMUSGList; typedef struct QemuSpin QemuSpin; typedef struct QEMUTimer QEMUTimer; typedef struct QEMUTimerListGroup QEMUTimerListGroup; -typedef struct QJSON QJSON; typedef struct QList QList; typedef struct QNull QNull; typedef struct QNum QNum; @@ -115,6 +114,7 @@ typedef struct QObject QObject; typedef struct QString QString; typedef struct RAMBlock RAMBlock; typedef struct Range Range; +typedef struct ReservedRegion ReservedRegion; typedef struct SavedIOTLB SavedIOTLB; typedef struct SHPCDevice SHPCDevice; typedef struct SSIBus SSIBus; diff --git a/migration/qjson.h b/migration/qjson.h deleted file mode 100644 index 1786bb5864..0000000000 --- a/migration/qjson.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * QEMU JSON writer - * - * Copyright Alexander Graf - * - * Authors: - * Alexander Graf - * - * 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. - * - */ -#ifndef QEMU_QJSON_H -#define QEMU_QJSON_H - -QJSON *qjson_new(void); -void qjson_destroy(QJSON *json); -void json_prop_str(QJSON *json, const char *name, const char *str); -void json_prop_int(QJSON *json, const char *name, int64_t val); -void json_end_array(QJSON *json); -void json_start_array(QJSON *json, const char *name); -void json_end_object(QJSON *json); -void json_start_object(QJSON *json, const char *name); -const char *qjson_get_str(QJSON *json); -void qjson_finish(QJSON *json); - -G_DEFINE_AUTOPTR_CLEANUP_FUNC(QJSON, qjson_destroy) - -#endif /* QEMU_QJSON_H */ diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index f3b71fa9c7..0e833a462b 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -970,7 +970,7 @@ static const VMStateDescription vmstate_virtio_gpu_scan= outs =3D { }; =20 static int virtio_gpu_save(QEMUFile *f, void *opaque, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { VirtIOGPU *g =3D opaque; struct virtio_gpu_simple_resource *res; diff --git a/hw/intc/s390_flic_kvm.c b/hw/intc/s390_flic_kvm.c index 35d91afa55..b3fb9f8395 100644 --- a/hw/intc/s390_flic_kvm.c +++ b/hw/intc/s390_flic_kvm.c @@ -386,7 +386,7 @@ static void kvm_s390_release_adapter_routes(S390FLICSta= te *fs, * reached */ static int kvm_flic_save(QEMUFile *f, void *opaque, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { KVMS390FLICState *flic =3D opaque; int len =3D FLIC_SAVE_INITIAL_SIZE; diff --git a/hw/nvram/eeprom93xx.c b/hw/nvram/eeprom93xx.c index ca6f591c84..a1b9c78844 100644 --- a/hw/nvram/eeprom93xx.c +++ b/hw/nvram/eeprom93xx.c @@ -104,7 +104,7 @@ static int get_uint16_from_uint8(QEMUFile *f, void *pv,= size_t size, } =20 static int put_unused(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { fprintf(stderr, "uint16_from_uint8 is used only for backwards compatib= ility.\n"); fprintf(stderr, "Never should be used to write a new state.\n"); diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c index 44cb274a32..9b8dcca4ea 100644 --- a/hw/nvram/fw_cfg.c +++ b/hw/nvram/fw_cfg.c @@ -583,7 +583,7 @@ static int get_uint32_as_uint16(QEMUFile *f, void *pv, = size_t size, } =20 static int put_unused(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { fprintf(stderr, "uint32_as_uint16 is only used for backward compatibil= ity.\n"); fprintf(stderr, "This functions shouldn't be called.\n"); diff --git a/hw/pci/msix.c b/hw/pci/msix.c index 36491ee52b..ae9331cd0b 100644 --- a/hw/pci/msix.c +++ b/hw/pci/msix.c @@ -634,7 +634,7 @@ void msix_unset_vector_notifiers(PCIDevice *dev) } =20 static int put_msix_state(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { msix_save(pv, f); =20 diff --git a/hw/pci/pci.c b/hw/pci/pci.c index d4349ea577..dd589cd7c7 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -559,7 +559,7 @@ static int get_pci_config_device(QEMUFile *f, void *pv,= size_t size, =20 /* just put buffer */ static int put_pci_config_device(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vm= desc) { const uint8_t **v =3D pv; assert(size =3D=3D pci_config_size(container_of(pv, PCIDevice, config)= )); @@ -597,7 +597,7 @@ static int get_pci_irq_state(QEMUFile *f, void *pv, siz= e_t size, } =20 static int put_pci_irq_state(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { int i; PCIDevice *s =3D container_of(pv, PCIDevice, irq_state); diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c index b00dce629c..4786a44996 100644 --- a/hw/pci/shpc.c +++ b/hw/pci/shpc.c @@ -699,7 +699,7 @@ void shpc_cap_write_config(PCIDevice *d, uint32_t addr,= uint32_t val, int l) } =20 static int shpc_save(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { PCIDevice *d =3D container_of(pv, PCIDevice, shpc); qemu_put_buffer(f, d->shpc->config, SHPC_SIZEOF(d)); diff --git a/hw/rtc/twl92230.c b/hw/rtc/twl92230.c index f838913b37..d942908223 100644 --- a/hw/rtc/twl92230.c +++ b/hw/rtc/twl92230.c @@ -762,7 +762,7 @@ static int get_int32_as_uint16(QEMUFile *f, void *pv, s= ize_t size, } =20 static int put_int32_as_uint16(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmde= sc) { int *v =3D pv; qemu_put_be16(f, *v); diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index edb5c3492a..c349fb7f2d 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -1638,7 +1638,7 @@ static char *scsibus_get_fw_dev_path(DeviceState *dev) /* SCSI request list. For simplicity, pv points to the whole device */ =20 static int put_scsi_requests(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { SCSIDevice *s =3D pv; SCSIBus *bus =3D DO_UPCAST(SCSIBus, qbus, s->qdev.parent_bus); diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c index 3238de6bb8..4ca7d47ef7 100644 --- a/hw/usb/redirect.c +++ b/hw/usb/redirect.c @@ -2227,7 +2227,7 @@ static int usbredir_post_load(void *priv, int version= _id) =20 /* For usbredirparser migration */ static int usbredir_put_parser(QEMUFile *f, void *priv, size_t unused, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmde= sc) { USBRedirDevice *dev =3D priv; uint8_t *data; @@ -2294,7 +2294,7 @@ static const VMStateInfo usbredir_parser_vmstate_info= =3D { =20 /* For buffered packets (iso/irq) queue migration */ static int usbredir_put_bufpq(QEMUFile *f, void *priv, size_t unused, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdes= c) { struct endp_data *endp =3D priv; USBRedirDevice *dev =3D endp->dev; @@ -2421,7 +2421,8 @@ static const VMStateDescription usbredir_ep_vmstate = =3D { =20 /* For PacketIdQueue migration */ static int usbredir_put_packet_id_q(QEMUFile *f, void *priv, size_t unused, - const VMStateField *field, QJSON *vmde= sc) + const VMStateField *field, + JSONWriter *vmdesc) { struct PacketIdQueue *q =3D priv; USBRedirDevice *dev =3D q->dev; diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index eff35fab7c..b308026596 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2745,7 +2745,7 @@ static int get_extra_state(QEMUFile *f, void *pv, siz= e_t size, } =20 static int put_extra_state(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { VirtIODevice *vdev =3D pv; BusState *qbus =3D qdev_get_parent_bus(DEVICE(vdev)); @@ -2919,7 +2919,7 @@ int virtio_save(VirtIODevice *vdev, QEMUFile *f) =20 /* A wrapper for use as a VMState .put function */ static int virtio_device_put(QEMUFile *f, void *opaque, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdes= c) { return virtio_save(VIRTIO_DEVICE(opaque), f); } diff --git a/migration/qjson.c b/migration/qjson.c deleted file mode 100644 index e9889bdcb0..0000000000 --- a/migration/qjson.c +++ /dev/null @@ -1,114 +0,0 @@ -/* - * A simple JSON writer - * - * Copyright Alexander Graf - * - * Authors: - * Alexander Graf - * - * 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. - * - */ - -/* - * Type QJSON lets you build JSON text. Its interface mirrors (a - * subset of) abstract JSON syntax. - * - * It does *not* detect incorrect use. It happily produces invalid - * JSON then. This is what migration wants. - * - * QAPI output visitors also produce JSON text. However, they do - * assert their preconditions and invariants, and therefore abort on - * incorrect use. - */ - -#include "qemu/osdep.h" -#include "qapi/qmp/qstring.h" -#include "qjson.h" - -struct QJSON { - QString *str; - bool omit_comma; -}; - -static void json_emit_element(QJSON *json, const char *name) -{ - /* Check whether we need to print a , before an element */ - if (json->omit_comma) { - json->omit_comma =3D false; - } else { - qstring_append(json->str, ", "); - } - - if (name) { - qstring_append(json->str, "\""); - qstring_append(json->str, name); - qstring_append(json->str, "\" : "); - } -} - -void json_start_object(QJSON *json, const char *name) -{ - json_emit_element(json, name); - qstring_append(json->str, "{ "); - json->omit_comma =3D true; -} - -void json_end_object(QJSON *json) -{ - qstring_append(json->str, " }"); - json->omit_comma =3D false; -} - -void json_start_array(QJSON *json, const char *name) -{ - json_emit_element(json, name); - qstring_append(json->str, "[ "); - json->omit_comma =3D true; -} - -void json_end_array(QJSON *json) -{ - qstring_append(json->str, " ]"); - json->omit_comma =3D false; -} - -void json_prop_int(QJSON *json, const char *name, int64_t val) -{ - json_emit_element(json, name); - qstring_append_int(json->str, val); -} - -void json_prop_str(QJSON *json, const char *name, const char *str) -{ - json_emit_element(json, name); - qstring_append_chr(json->str, '"'); - qstring_append(json->str, str); - qstring_append_chr(json->str, '"'); -} - -const char *qjson_get_str(QJSON *json) -{ - return qstring_get_str(json->str); -} - -QJSON *qjson_new(void) -{ - QJSON *json =3D g_new0(QJSON, 1); - - json->str =3D qstring_from_str("{ "); - json->omit_comma =3D true; - return json; -} - -void qjson_finish(QJSON *json) -{ - json_end_object(json); -} - -void qjson_destroy(QJSON *json) -{ - qobject_unref(json->str); - g_free(json); -} diff --git a/migration/savevm.c b/migration/savevm.c index 5f937a2762..138a96de4d 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -42,6 +42,7 @@ #include "postcopy-ram.h" #include "qapi/error.h" #include "qapi/qapi-commands-migration.h" +#include "qapi/qmp/json-writer.h" #include "qapi/qmp/qerror.h" #include "qemu/error-report.h" #include "sysemu/cpus.h" @@ -58,7 +59,6 @@ #include "sysemu/runstate.h" #include "sysemu/sysemu.h" #include "sysemu/xen.h" -#include "qjson.h" #include "migration/colo.h" #include "qemu/bitmap.h" #include "net/announce.h" @@ -209,7 +209,7 @@ static int get_timer(QEMUFile *f, void *pv, size_t size, } =20 static int put_timer(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { QEMUTimer *v =3D pv; timer_put(f, v); @@ -406,7 +406,7 @@ static int get_capability(QEMUFile *f, void *pv, size_t= size, } =20 static int put_capability(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { MigrationCapability *capability =3D pv; const char *capability_str =3D MigrationCapability_str(*capability); @@ -884,7 +884,8 @@ static int vmstate_load(QEMUFile *f, SaveStateEntry *se) return vmstate_load_state(f, se->vmsd, se->opaque, se->load_version_id= ); } =20 -static void vmstate_save_old_style(QEMUFile *f, SaveStateEntry *se, QJSON = *vmdesc) +static void vmstate_save_old_style(QEMUFile *f, SaveStateEntry *se, + JSONWriter *vmdesc) { int64_t old_offset, size; =20 @@ -893,18 +894,19 @@ static void vmstate_save_old_style(QEMUFile *f, SaveS= tateEntry *se, QJSON *vmdes size =3D qemu_ftell_fast(f) - old_offset; =20 if (vmdesc) { - json_prop_int(vmdesc, "size", size); - json_start_array(vmdesc, "fields"); - json_start_object(vmdesc, NULL); - json_prop_str(vmdesc, "name", "data"); - json_prop_int(vmdesc, "size", size); - json_prop_str(vmdesc, "type", "buffer"); - json_end_object(vmdesc); - json_end_array(vmdesc); + json_writer_int64(vmdesc, "size", size); + json_writer_start_array(vmdesc, "fields"); + json_writer_start_object(vmdesc, NULL); + json_writer_str(vmdesc, "name", "data"); + json_writer_int64(vmdesc, "size", size); + json_writer_str(vmdesc, "type", "buffer"); + json_writer_end_object(vmdesc); + json_writer_end_array(vmdesc); } } =20 -static int vmstate_save(QEMUFile *f, SaveStateEntry *se, QJSON *vmdesc) +static int vmstate_save(QEMUFile *f, SaveStateEntry *se, + JSONWriter *vmdesc) { trace_vmstate_save(se->idstr, se->vmsd ? se->vmsd->name : "(old)"); if (!se->vmsd) { @@ -1357,14 +1359,15 @@ int qemu_savevm_state_complete_precopy_non_iterable= (QEMUFile *f, bool in_postcopy, bool inactivate_disks) { - g_autoptr(QJSON) vmdesc =3D NULL; + g_autoptr(JSONWriter) vmdesc =3D NULL; int vmdesc_len; SaveStateEntry *se; int ret; =20 - vmdesc =3D qjson_new(); - json_prop_int(vmdesc, "page_size", qemu_target_page_size()); - json_start_array(vmdesc, "devices"); + vmdesc =3D json_writer_new(false); + json_writer_start_object(vmdesc, NULL); + json_writer_int64(vmdesc, "page_size", qemu_target_page_size()); + json_writer_start_array(vmdesc, "devices"); QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { =20 if ((!se->ops || !se->ops->save_state) && !se->vmsd) { @@ -1377,9 +1380,9 @@ int qemu_savevm_state_complete_precopy_non_iterable(Q= EMUFile *f, =20 trace_savevm_section_start(se->idstr, se->section_id); =20 - json_start_object(vmdesc, NULL); - json_prop_str(vmdesc, "name", se->idstr); - json_prop_int(vmdesc, "instance_id", se->instance_id); + json_writer_start_object(vmdesc, NULL); + json_writer_str(vmdesc, "name", se->idstr); + json_writer_int64(vmdesc, "instance_id", se->instance_id); =20 save_section_header(f, se, QEMU_VM_SECTION_FULL); ret =3D vmstate_save(f, se, vmdesc); @@ -1390,7 +1393,7 @@ int qemu_savevm_state_complete_precopy_non_iterable(Q= EMUFile *f, trace_savevm_section_end(se->idstr, se->section_id, 0); save_section_footer(f, se); =20 - json_end_object(vmdesc); + json_writer_end_object(vmdesc); } =20 if (inactivate_disks) { @@ -1409,14 +1412,14 @@ int qemu_savevm_state_complete_precopy_non_iterable= (QEMUFile *f, qemu_put_byte(f, QEMU_VM_EOF); } =20 - json_end_array(vmdesc); - qjson_finish(vmdesc); - vmdesc_len =3D strlen(qjson_get_str(vmdesc)); + json_writer_end_array(vmdesc); + json_writer_end_object(vmdesc); + vmdesc_len =3D strlen(json_writer_get(vmdesc)); =20 if (should_send_vmdesc()) { qemu_put_byte(f, QEMU_VM_VMDESCRIPTION); qemu_put_be32(f, vmdesc_len); - qemu_put_buffer(f, (uint8_t *)qjson_get_str(vmdesc), vmdesc_len); + qemu_put_buffer(f, (uint8_t *)json_writer_get(vmdesc), vmdesc_len); } =20 return 0; diff --git a/migration/vmstate-types.c b/migration/vmstate-types.c index e22d41d73d..bf4d440308 100644 --- a/migration/vmstate-types.c +++ b/migration/vmstate-types.c @@ -29,7 +29,7 @@ static int get_bool(QEMUFile *f, void *pv, size_t size, } =20 static int put_bool(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { bool *v =3D pv; qemu_put_byte(f, *v); @@ -53,7 +53,7 @@ static int get_int8(QEMUFile *f, void *pv, size_t size, } =20 static int put_int8(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { int8_t *v =3D pv; qemu_put_s8s(f, v); @@ -77,7 +77,7 @@ static int get_int16(QEMUFile *f, void *pv, size_t size, } =20 static int put_int16(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { int16_t *v =3D pv; qemu_put_sbe16s(f, v); @@ -101,7 +101,7 @@ static int get_int32(QEMUFile *f, void *pv, size_t size, } =20 static int put_int32(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { int32_t *v =3D pv; qemu_put_sbe32s(f, v); @@ -178,7 +178,7 @@ static int get_int64(QEMUFile *f, void *pv, size_t size, } =20 static int put_int64(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { int64_t *v =3D pv; qemu_put_sbe64s(f, v); @@ -202,7 +202,7 @@ static int get_uint8(QEMUFile *f, void *pv, size_t size, } =20 static int put_uint8(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { uint8_t *v =3D pv; qemu_put_8s(f, v); @@ -226,7 +226,7 @@ static int get_uint16(QEMUFile *f, void *pv, size_t siz= e, } =20 static int put_uint16(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { uint16_t *v =3D pv; qemu_put_be16s(f, v); @@ -250,7 +250,7 @@ static int get_uint32(QEMUFile *f, void *pv, size_t siz= e, } =20 static int put_uint32(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { uint32_t *v =3D pv; qemu_put_be32s(f, v); @@ -300,7 +300,7 @@ static int get_uint64(QEMUFile *f, void *pv, size_t siz= e, } =20 static int put_uint64(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { uint64_t *v =3D pv; qemu_put_be64s(f, v); @@ -325,7 +325,7 @@ static int get_nullptr(QEMUFile *f, void *pv, size_t si= ze, } =20 static int put_nullptr(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) =20 { if (pv =3D=3D NULL) { @@ -432,7 +432,7 @@ static int get_cpudouble(QEMUFile *f, void *pv, size_t = size, } =20 static int put_cpudouble(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { CPU_DoubleU *v =3D pv; qemu_put_be32s(f, &v->l.upper); @@ -457,7 +457,7 @@ static int get_buffer(QEMUFile *f, void *pv, size_t siz= e, } =20 static int put_buffer(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { uint8_t *v =3D pv; qemu_put_buffer(f, v, size); @@ -488,7 +488,7 @@ static int get_unused_buffer(QEMUFile *f, void *pv, siz= e_t size, } =20 static int put_unused_buffer(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { static const uint8_t buf[1024]; int block_len; @@ -530,7 +530,7 @@ static int get_tmp(QEMUFile *f, void *pv, size_t size, } =20 static int put_tmp(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { const VMStateDescription *vmsd =3D field->vmsd; void *tmp =3D g_malloc(size); @@ -573,7 +573,7 @@ static int get_bitmap(QEMUFile *f, void *pv, size_t siz= e, } =20 static int put_bitmap(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { unsigned long *bmp =3D pv; int i, idx =3D 0; @@ -637,7 +637,7 @@ static int get_qtailq(QEMUFile *f, void *pv, size_t unu= sed_size, =20 /* put for QTAILQ */ static int put_qtailq(QEMUFile *f, void *pv, size_t unused_size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { const VMStateDescription *vmsd =3D field->vmsd; /* offset of the QTAILQ entry in a QTAILQ element*/ @@ -670,7 +670,7 @@ struct put_gtree_data { QEMUFile *f; const VMStateDescription *key_vmsd; const VMStateDescription *val_vmsd; - QJSON *vmdesc; + JSONWriter *vmdesc; int ret; }; =20 @@ -703,7 +703,7 @@ static gboolean put_gtree_elem(gpointer key, gpointer v= alue, gpointer data) } =20 static int put_gtree(QEMUFile *f, void *pv, size_t unused_size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { bool direct_key =3D (!field->start); const VMStateDescription *key_vmsd =3D direct_key ? NULL : &field->vms= d[1]; @@ -819,7 +819,7 @@ const VMStateInfo vmstate_info_gtree =3D { }; =20 static int put_qlist(QEMUFile *f, void *pv, size_t unused_size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { const VMStateDescription *vmsd =3D field->vmsd; /* offset of the QTAILQ entry in a QTAILQ element*/ diff --git a/migration/vmstate.c b/migration/vmstate.c index e9d2aef66b..05f87cdddc 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -14,14 +14,14 @@ #include "migration.h" #include "migration/vmstate.h" #include "savevm.h" +#include "qapi/qmp/json-writer.h" #include "qemu-file.h" #include "qemu/bitops.h" #include "qemu/error-report.h" #include "trace.h" -#include "qjson.h" =20 static int vmstate_subsection_save(QEMUFile *f, const VMStateDescription *= vmsd, - void *opaque, QJSON *vmdesc); + void *opaque, JSONWriter *vmdesc); static int vmstate_subsection_load(QEMUFile *f, const VMStateDescription *= vmsd, void *opaque); =20 @@ -249,7 +249,8 @@ static bool vmsd_can_compress(const VMStateField *field) return true; } =20 -static void vmsd_desc_field_start(const VMStateDescription *vmsd, QJSON *v= mdesc, +static void vmsd_desc_field_start(const VMStateDescription *vmsd, + JSONWriter *vmdesc, const VMStateField *field, int i, int ma= x) { char *name, *old_name; @@ -270,25 +271,26 @@ static void vmsd_desc_field_start(const VMStateDescri= ption *vmsd, QJSON *vmdesc, g_free(old_name); } =20 - json_start_object(vmdesc, NULL); - json_prop_str(vmdesc, "name", name); + json_writer_start_object(vmdesc, NULL); + json_writer_str(vmdesc, "name", name); if (is_array) { if (can_compress) { - json_prop_int(vmdesc, "array_len", max); + json_writer_int64(vmdesc, "array_len", max); } else { - json_prop_int(vmdesc, "index", i); + json_writer_int64(vmdesc, "index", i); } } - json_prop_str(vmdesc, "type", vmfield_get_type_name(field)); + json_writer_str(vmdesc, "type", vmfield_get_type_name(field)); =20 if (field->flags & VMS_STRUCT) { - json_start_object(vmdesc, "struct"); + json_writer_start_object(vmdesc, "struct"); } =20 g_free(name); } =20 -static void vmsd_desc_field_end(const VMStateDescription *vmsd, QJSON *vmd= esc, +static void vmsd_desc_field_end(const VMStateDescription *vmsd, + JSONWriter *vmdesc, const VMStateField *field, size_t size, in= t i) { if (!vmdesc) { @@ -297,11 +299,11 @@ static void vmsd_desc_field_end(const VMStateDescript= ion *vmsd, QJSON *vmdesc, =20 if (field->flags & VMS_STRUCT) { /* We printed a struct in between, close its child object */ - json_end_object(vmdesc); + json_writer_end_object(vmdesc); } =20 - json_prop_int(vmdesc, "size", size); - json_end_object(vmdesc); + json_writer_int64(vmdesc, "size", size); + json_writer_end_object(vmdesc); } =20 =20 @@ -316,13 +318,13 @@ bool vmstate_save_needed(const VMStateDescription *vm= sd, void *opaque) =20 =20 int vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, - void *opaque, QJSON *vmdesc_id) + void *opaque, JSONWriter *vmdesc_id) { return vmstate_save_state_v(f, vmsd, opaque, vmdesc_id, vmsd->version_= id); } =20 int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd, - void *opaque, QJSON *vmdesc, int version_id) + void *opaque, JSONWriter *vmdesc, int version_id) { int ret =3D 0; const VMStateField *field =3D vmsd->fields; @@ -339,9 +341,9 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDesc= ription *vmsd, } =20 if (vmdesc) { - json_prop_str(vmdesc, "vmsd_name", vmsd->name); - json_prop_int(vmdesc, "version", version_id); - json_start_array(vmdesc, "fields"); + json_writer_str(vmdesc, "vmsd_name", vmsd->name); + json_writer_int64(vmdesc, "version", version_id); + json_writer_start_array(vmdesc, "fields"); } =20 while (field->name) { @@ -353,7 +355,7 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDesc= ription *vmsd, int i, n_elems =3D vmstate_n_elems(opaque, field); int size =3D vmstate_size(opaque, field); int64_t old_offset, written_bytes; - QJSON *vmdesc_loop =3D vmdesc; + JSONWriter *vmdesc_loop =3D vmdesc; =20 trace_vmstate_save_state_loop(vmsd->name, field->name, n_elems= ); if (field->flags & VMS_POINTER) { @@ -413,7 +415,7 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDesc= ription *vmsd, } =20 if (vmdesc) { - json_end_array(vmdesc); + json_writer_end_array(vmdesc); } =20 ret =3D vmstate_subsection_save(f, vmsd, opaque, vmdesc); @@ -491,7 +493,7 @@ static int vmstate_subsection_load(QEMUFile *f, const V= MStateDescription *vmsd, } =20 static int vmstate_subsection_save(QEMUFile *f, const VMStateDescription *= vmsd, - void *opaque, QJSON *vmdesc) + void *opaque, JSONWriter *vmdesc) { const VMStateDescription **sub =3D vmsd->subsections; bool vmdesc_has_subsections =3D false; @@ -507,11 +509,11 @@ static int vmstate_subsection_save(QEMUFile *f, const= VMStateDescription *vmsd, if (vmdesc) { /* Only create subsection array when we have any */ if (!vmdesc_has_subsections) { - json_start_array(vmdesc, "subsections"); + json_writer_start_array(vmdesc, "subsections"); vmdesc_has_subsections =3D true; } =20 - json_start_object(vmdesc, NULL); + json_writer_start_object(vmdesc, NULL); } =20 qemu_put_byte(f, QEMU_VM_SUBSECTION); @@ -525,14 +527,14 @@ static int vmstate_subsection_save(QEMUFile *f, const= VMStateDescription *vmsd, } =20 if (vmdesc) { - json_end_object(vmdesc); + json_writer_end_object(vmdesc); } } sub++; } =20 if (vmdesc_has_subsections) { - json_end_array(vmdesc); + json_writer_end_array(vmdesc); } =20 return ret; diff --git a/target/alpha/machine.c b/target/alpha/machine.c index 9d20169d4f..2b7c8148ff 100644 --- a/target/alpha/machine.c +++ b/target/alpha/machine.c @@ -11,7 +11,7 @@ static int get_fpcr(QEMUFile *f, void *opaque, size_t siz= e, } =20 static int put_fpcr(QEMUFile *f, void *opaque, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { CPUAlphaState *env =3D opaque; qemu_put_be64(f, cpu_alpha_load_fpcr(env)); diff --git a/target/arm/machine.c b/target/arm/machine.c index c5a2114f51..581852bc53 100644 --- a/target/arm/machine.c +++ b/target/arm/machine.c @@ -27,7 +27,7 @@ static int get_fpscr(QEMUFile *f, void *opaque, size_t si= ze, } =20 static int put_fpscr(QEMUFile *f, void *opaque, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { ARMCPU *cpu =3D opaque; CPUARMState *env =3D &cpu->env; @@ -573,7 +573,7 @@ static int get_cpsr(QEMUFile *f, void *opaque, size_t s= ize, } =20 static int put_cpsr(QEMUFile *f, void *opaque, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { ARMCPU *cpu =3D opaque; CPUARMState *env =3D &cpu->env; @@ -608,7 +608,7 @@ static int get_power(QEMUFile *f, void *opaque, size_t = size, } =20 static int put_power(QEMUFile *f, void *opaque, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { ARMCPU *cpu =3D opaque; =20 diff --git a/target/avr/machine.c b/target/avr/machine.c index e315442787..de264f57c3 100644 --- a/target/avr/machine.c +++ b/target/avr/machine.c @@ -34,7 +34,7 @@ static int get_sreg(QEMUFile *f, void *opaque, size_t siz= e, } =20 static int put_sreg(QEMUFile *f, void *opaque, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { CPUAVRState *env =3D opaque; uint8_t sreg =3D cpu_get_sreg(env); @@ -61,7 +61,7 @@ static int get_segment(QEMUFile *f, void *opaque, size_t = size, } =20 static int put_segment(QEMUFile *f, void *opaque, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { uint32_t *ramp =3D opaque; uint8_t temp =3D *ramp >> 16; diff --git a/target/hppa/machine.c b/target/hppa/machine.c index b60b654efb..905991d7f9 100644 --- a/target/hppa/machine.c +++ b/target/hppa/machine.c @@ -52,7 +52,7 @@ static int get_psw(QEMUFile *f, void *opaque, size_t size, } =20 static int put_psw(QEMUFile *f, void *opaque, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { CPUHPPAState *env =3D opaque; qemu_put_betr(f, cpu_hppa_get_psw(env)); @@ -93,7 +93,7 @@ static int get_tlb(QEMUFile *f, void *opaque, size_t size, } =20 static int put_tlb(QEMUFile *f, void *opaque, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { hppa_tlb_entry *ent =3D opaque; uint32_t val =3D 0; diff --git a/target/microblaze/machine.c b/target/microblaze/machine.c index c2074bbdfe..d24def3992 100644 --- a/target/microblaze/machine.c +++ b/target/microblaze/machine.c @@ -46,7 +46,7 @@ static int get_msr(QEMUFile *f, void *opaque, size_t size, } =20 static int put_msr(QEMUFile *f, void *opaque, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { CPUMBState *env =3D container_of(opaque, CPUMBState, msr); =20 diff --git a/target/mips/machine.c b/target/mips/machine.c index 5b23e3e912..77afe654e9 100644 --- a/target/mips/machine.c +++ b/target/mips/machine.c @@ -31,7 +31,7 @@ static int get_fpr(QEMUFile *f, void *pv, size_t size, } =20 static int put_fpr(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { int i; fpr_t *v =3D pv; @@ -156,7 +156,7 @@ static int get_tlb(QEMUFile *f, void *pv, size_t size, } =20 static int put_tlb(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { r4k_tlb_t *v =3D pv; =20 diff --git a/target/openrisc/machine.c b/target/openrisc/machine.c index b92985d99b..6239725c4f 100644 --- a/target/openrisc/machine.c +++ b/target/openrisc/machine.c @@ -55,7 +55,7 @@ static int get_sr(QEMUFile *f, void *opaque, size_t size, } =20 static int put_sr(QEMUFile *f, void *opaque, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { CPUOpenRISCState *env =3D opaque; qemu_put_be32(f, cpu_get_sr(env)); diff --git a/target/ppc/machine.c b/target/ppc/machine.c index d9d911b9b1..283db1d28a 100644 --- a/target/ppc/machine.c +++ b/target/ppc/machine.c @@ -134,7 +134,7 @@ static int get_avr(QEMUFile *f, void *pv, size_t size, } =20 static int put_avr(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { ppc_avr_t *v =3D pv; =20 @@ -166,7 +166,7 @@ static int get_fpr(QEMUFile *f, void *pv, size_t size, } =20 static int put_fpr(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { ppc_vsr_t *v =3D pv; =20 @@ -197,7 +197,7 @@ static int get_vsr(QEMUFile *f, void *pv, size_t size, } =20 static int put_vsr(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { ppc_vsr_t *v =3D pv; =20 @@ -455,7 +455,7 @@ static int get_vscr(QEMUFile *f, void *opaque, size_t s= ize, } =20 static int put_vscr(QEMUFile *f, void *opaque, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { PowerPCCPU *cpu =3D opaque; qemu_put_be32(f, helper_mfvscr(&cpu->env)); @@ -580,7 +580,7 @@ static int get_slbe(QEMUFile *f, void *pv, size_t size, } =20 static int put_slbe(QEMUFile *f, void *pv, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { ppc_slb_t *v =3D pv; =20 diff --git a/target/sparc/machine.c b/target/sparc/machine.c index f38cf229af..917375c3a1 100644 --- a/target/sparc/machine.c +++ b/target/sparc/machine.c @@ -68,7 +68,7 @@ static int get_psr(QEMUFile *f, void *opaque, size_t size, } =20 static int put_psr(QEMUFile *f, void *opaque, size_t size, - const VMStateField *field, QJSON *vmdesc) + const VMStateField *field, JSONWriter *vmdesc) { SPARCCPU *cpu =3D opaque; CPUSPARCState *env =3D &cpu->env; diff --git a/migration/meson.build b/migration/meson.build index 980e37865c..291adc1337 100644 --- a/migration/meson.build +++ b/migration/meson.build @@ -6,7 +6,6 @@ migration_files =3D files( 'vmstate.c', 'qemu-file-channel.c', 'qemu-file.c', - 'qjson.c', ) softmmu_ss.add(migration_files) =20 --=20 2.26.2 From nobody Thu May 16 15:04:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608376338; cv=none; d=zohomail.com; s=zohoarc; b=UXrIDd5OU85hj8hg6TuRtr3gI3PWjGSeGExdZSSdZm/EQEuu1urJP7gHM1GahmjplYeNaVVmDWpFViSSQdFyFBEy2uUwkeGO44RKatbRkClBbUpGyWSby0Jw6hrffzM14z0qMDhMF3yZgiKb9uXYYJ2GH3RSLQ2vdCbRkbDnM/A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608376338; 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=29AdrfONURv16D17PL5O506hts+OonM70cmpwZeP+fo=; b=aVahEjf6HIhV3b5jOSTxkUGsL36ZyYWRtwmAnBcQJnkvhea2JgNFN2mq2WgkqsFDO/cSHJudBFhGRq2N0K1T75oUyoLxMhPFuA+xCieNZJ+jJOvqqsdDOtflIVCQLVcMQPJd08cENRIkuUdioxqGBEGG8aYaoKl6CPAU614ZcGA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1608376338969507.38694438327377; Sat, 19 Dec 2020 03:12:18 -0800 (PST) Received: from localhost ([::1]:36156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqa9p-0002C2-Sp for importer@patchew.org; Sat, 19 Dec 2020 06:12:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50828) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZtx-000568-5E for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:42114) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtm-0007Hx-7i for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:52 -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-147-IndbO86zO4eTuPb6iPjBJA-1; Sat, 19 Dec 2020 05:55:39 -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 51C20180A087; Sat, 19 Dec 2020 10:55:38 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 23E666A8F0; Sat, 19 Dec 2020 10:55:38 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id D9BE8112564B; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375341; 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=29AdrfONURv16D17PL5O506hts+OonM70cmpwZeP+fo=; b=YdFMIp9S/dflA7YzKvfDkoSh4FJPxzYNLikLdAJt1qEiLbkHO1xlOtpL3hP2FiCEoo84Jx E7nGYor3qdb2FvLloTHT1aBsNuE/xJMg3xHNdfHxqJ9/mdGAwbyNK4l1k1H6Z421os2lLM 6ZQ8vOSXx5K+ppxoyrcLwzMi007737I= X-MC-Unique: IndbO86zO4eTuPb6iPjBJA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 30/33] json: Use GString instead of QString to accumulate strings Date: Sat, 19 Dec 2020 11:55:29 +0100 Message-Id: <20201219105532.1734134-31-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H3=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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" QString supports modifying its string, but it's quite limited: you can only append. The remaining callers use it for building an initial string, never for modifying it later. Change parse_string() to do build the initial string with GString. This is another step towards making QString immutable. Signed-off-by: Markus Armbruster Message-Id: <20201211171152.146877-18-armbru@redhat.com> --- qobject/json-parser.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/qobject/json-parser.c b/qobject/json-parser.c index c0f521b56b..d351039b10 100644 --- a/qobject/json-parser.c +++ b/qobject/json-parser.c @@ -130,7 +130,7 @@ static int cvt4hex(const char *s) static QString *parse_string(JSONParserContext *ctxt, JSONToken *token) { const char *ptr =3D token->str; - QString *str; + GString *str; char quote; const char *beg; int cp, trailing; @@ -140,7 +140,7 @@ static QString *parse_string(JSONParserContext *ctxt, J= SONToken *token) =20 assert(*ptr =3D=3D '"' || *ptr =3D=3D '\''); quote =3D *ptr++; - str =3D qstring_new(); + str =3D g_string_new(NULL); =20 while (*ptr !=3D quote) { assert(*ptr); @@ -149,31 +149,31 @@ static QString *parse_string(JSONParserContext *ctxt,= JSONToken *token) beg =3D ptr++; switch (*ptr++) { case '"': - qstring_append_chr(str, '"'); + g_string_append_c(str, '"'); break; case '\'': - qstring_append_chr(str, '\''); + g_string_append_c(str, '\''); break; case '\\': - qstring_append_chr(str, '\\'); + g_string_append_c(str, '\\'); break; case '/': - qstring_append_chr(str, '/'); + g_string_append_c(str, '/'); break; case 'b': - qstring_append_chr(str, '\b'); + g_string_append_c(str, '\b'); break; case 'f': - qstring_append_chr(str, '\f'); + g_string_append_c(str, '\f'); break; case 'n': - qstring_append_chr(str, '\n'); + g_string_append_c(str, '\n'); break; case 'r': - qstring_append_chr(str, '\r'); + g_string_append_c(str, '\r'); break; case 't': - qstring_append_chr(str, '\t'); + g_string_append_c(str, '\t'); break; case 'u': cp =3D cvt4hex(ptr); @@ -200,7 +200,7 @@ static QString *parse_string(JSONParserContext *ctxt, J= SONToken *token) (int)(ptr - beg), beg); goto out; } - qstring_append(str, utf8_buf); + g_string_append(str, utf8_buf); break; default: parse_error(ctxt, token, "invalid escape sequence in strin= g"); @@ -225,14 +225,14 @@ static QString *parse_string(JSONParserContext *ctxt,= JSONToken *token) ptr =3D end; len =3D mod_utf8_encode(utf8_buf, sizeof(utf8_buf), cp); assert(len >=3D 0); - qstring_append(str, utf8_buf); + g_string_append(str, utf8_buf); } } =20 - return str; + return qstring_from_gstring(str); =20 out: - qobject_unref(str); + g_string_free(str, true); return NULL; } =20 --=20 2.26.2 From nobody Thu May 16 15:04:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608376247; cv=none; d=zohomail.com; s=zohoarc; b=WnqIOlM9/Mzq4iWvHaUi/TKzQ8SBxy6vY0nXFaTknNRdqDywyFOerRz5hAoThkwqaEGh1kQCLJiQPsCcefnNj6uQRJ7nB8x0BrO2+1mK6wtU+4NF7Al7XKuT6bmgf/W739duwJOKZDG4rXl5sYvuFgcQYFqVK1PXaUsnErRxLm4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608376247; 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=0PDVUNmxz2T8ZWdNyK2rDNunPXdtOqOJQJybNSVkkzU=; b=MA0BB4Zyi9nI8sBvcrGyYV+D90yVUp5lUbuRPrFmGuFU7oKrk7NuVEZoytzb2ryrNh26LFgomAetWycliNFQKmM5RQdFbl9PfctddueAmCcZdLcLy+J5vbfrj0QdxP0qOa1j2e0UvDFCOVZQLj6+azynuGhI6dsca6tdL3tkfdU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1608376247941910.4392723962651; Sat, 19 Dec 2020 03:10:47 -0800 (PST) Received: from localhost ([::1]:59274 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqa8M-0008Ps-RQ for importer@patchew.org; Sat, 19 Dec 2020 06:10:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50858) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZty-00059u-HT for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:37786) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtn-0007IH-0k for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:54 -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-119-PkQDDYQpPF-f0u16GZRtYg-1; Sat, 19 Dec 2020 05:55:39 -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 51DBE180A089; Sat, 19 Dec 2020 10:55:38 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 237383AA2; Sat, 19 Dec 2020 10:55:38 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id DC571112564C; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375342; 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=0PDVUNmxz2T8ZWdNyK2rDNunPXdtOqOJQJybNSVkkzU=; b=UMRK8BUn5bfgw6gEo0aQSZoW/BKC4axFb9tE1/KvHRFkSsm80ByNC4UAPwgwJiV7ISB+6h vECTp5559WMeNt/Bq2VgqWUJUtB2rUGkshjzmNmxiV94B/0OHeiYK5MrIGxIDaroV5UmNG iLInnlPX0lAOs8UYhAADrirr2DdVJk8= X-MC-Unique: PkQDDYQpPF-f0u16GZRtYg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 31/33] keyval: Use GString to accumulate value strings Date: Sat, 19 Dec 2020 11:55:30 +0100 Message-Id: <20201219105532.1734134-32-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H3=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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" QString supports modifying its string, but it's quite limited: you can only append. The remaining callers use it for building an initial string, never for modifying it later. Change keyval_parse_one() to do build the initial string with GString. This is another step towards making QString immutable. Signed-off-by: Markus Armbruster Message-Id: <20201211171152.146877-19-armbru@redhat.com> --- util/keyval.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/util/keyval.c b/util/keyval.c index 7f625ad33c..be34928813 100644 --- a/util/keyval.c +++ b/util/keyval.c @@ -189,7 +189,7 @@ static const char *keyval_parse_one(QDict *qdict, const= char *params, QDict *cur; int ret; QObject *next; - QString *val; + GString *val; =20 key =3D params; val_end =3D NULL; @@ -263,7 +263,7 @@ static const char *keyval_parse_one(QDict *qdict, const= char *params, =20 if (key =3D=3D implied_key) { assert(!*s); - val =3D qstring_from_substr(params, 0, val_end - params); + val =3D g_string_new_len(params, val_end - params); s =3D val_end; if (*s =3D=3D ',') { s++; @@ -276,7 +276,7 @@ static const char *keyval_parse_one(QDict *qdict, const= char *params, } s++; =20 - val =3D qstring_new(); + val =3D g_string_new(NULL); for (;;) { if (!*s) { break; @@ -286,11 +286,12 @@ static const char *keyval_parse_one(QDict *qdict, con= st char *params, break; } } - qstring_append_chr(val, *s++); + g_string_append_c(val, *s++); } } =20 - if (!keyval_parse_put(cur, key_in_cur, val, key, key_end, errp)) { + if (!keyval_parse_put(cur, key_in_cur, qstring_from_gstring(val), + key, key_end, errp)) { return NULL; } return s; --=20 2.26.2 From nobody Thu May 16 15:04:34 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=1608376488; cv=none; d=zohomail.com; s=zohoarc; b=Zr/QqcMP+/ODLDWpqTxNy8onMF/4uu2CuS6rlPVBCAPn++UguaeVkeiP0BtH1mftOnwYBoxzUx5vLx+zaHvueQB+U4xmSfj4PvjpP1UFO402Mq3M4fpXPPMEKhMis1MqPbkmrY2b6QyOUd4KDZzwHwGdgPHSyYoAk+Qy+zOBJ1I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608376488; 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=htQZY9xpY70D/Wz35TnpKgq09HOSjfOIwxK58Ld+TMY=; b=PVRMt0bgia2z4LvTupYkJG6FGFFdv9rX+OjLkYRtO4ylvOqZZilRBGaUtwZzxjodl6vcjp2o4k48iO+YNnQPkx7z23wdRUU46ljWb4BNQsEZMpeeq9hP2F+s/QddRQg83RpPbdBCSanSeG2FQKcc92gRi1eF7uxlpe51p4cxRNI= 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 1608376488194148.30465171950414; Sat, 19 Dec 2020 03:14:48 -0800 (PST) Received: from localhost ([::1]:43822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqaCF-0005O8-4P for importer@patchew.org; Sat, 19 Dec 2020 06:14:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50916) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZu2-0005Nx-S1 for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:34672) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtp-0007Ji-Nw for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:58 -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-157-XB-6YoueNw-T9E8aHAc_2g-1; Sat, 19 Dec 2020 05:55:39 -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 8364C801817; Sat, 19 Dec 2020 10:55:38 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2C8172B6C9; Sat, 19 Dec 2020 10:55:38 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id E4D73112564D; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375344; 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=htQZY9xpY70D/Wz35TnpKgq09HOSjfOIwxK58Ld+TMY=; b=UZXDq5Mo7di7nP5VXO1J7wPuJCDMDPrC3I52+M0n9YEPk8iD8GlgbqjEIGziU6rk0CYuiA cyG0RG8lHsRF1tdW8sbdBvELPVw+xKnmdKxN3w8/jAoCAhALjo8qRe0hKmp9CvmbakurGf z04gGiiNtbGgfM066dFpYRJt6moOvEU= X-MC-Unique: XB-6YoueNw-T9E8aHAc_2g-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 32/33] block: Use GString instead of QString to build filenames Date: Sat, 19 Dec 2020 11:55:31 +0100 Message-Id: <20201219105532.1734134-33-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: Kevin Wolf , peter.maydell@linaro.org, Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Max Reitz 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" QString supports modifying its string, but it's quite limited: you can only append. Just one caller remains: bdrv_parse_filename_strip_prefix() uses it just for building an initial string. Change it to do build the initial string with GString. This is another step towards making QString immutable. Cc: Kevin Wolf Cc: Max Reitz Cc: qemu-block@nongnu.org Signed-off-by: Markus Armbruster Message-Id: <20201211171152.146877-20-armbru@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy --- block.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/block.c b/block.c index 934d1bcc8f..27b2c3ba15 100644 --- a/block.c +++ b/block.c @@ -217,7 +217,7 @@ void bdrv_parse_filename_strip_prefix(const char *filen= ame, const char *prefix, /* Stripping the explicit protocol prefix may result in a protocol * prefix being (wrongly) detected (if the filename contains a col= on) */ if (path_has_protocol(filename)) { - QString *fat_filename; + GString *fat_filename; =20 /* This means there is some colon before the first slash; ther= efore, * this cannot be an absolute path */ @@ -225,12 +225,13 @@ void bdrv_parse_filename_strip_prefix(const char *fil= ename, const char *prefix, =20 /* And we can thus fix the protocol detection issue by prefixi= ng it * by "./" */ - fat_filename =3D qstring_from_str("./"); - qstring_append(fat_filename, filename); + fat_filename =3D g_string_new("./"); + g_string_append(fat_filename, filename); =20 - assert(!path_has_protocol(qstring_get_str(fat_filename))); + assert(!path_has_protocol(fat_filename->str)); =20 - qdict_put(options, "filename", fat_filename); + qdict_put(options, "filename", + qstring_from_gstring(fat_filename)); } else { /* If no protocol prefix was detected, we can use the shortened * filename as-is */ --=20 2.26.2 From nobody Thu May 16 15:04:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608376339; cv=none; d=zohomail.com; s=zohoarc; b=hGPF2kDsV1ao8I9VOfq4R8MvS+65almY5EEv/MlQmF9ccERF+T4anpcD/onCc3VarsWbFfJDqJWPHV93jDdzXeYxOZRnoTJgm6jFRbNCwHovcWLZM3UW9IHvPC4NDyxRlmA+N7liX+Rcers+Ork8K/IlY7ZEMLENK+bitaz5eQA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608376339; 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=vqhxR6uXG1fRCc/R6LcSH7A4bTgvfonW5xTAWh7dTgA=; b=gB3EPUnTXQHoq4uEf9rQjto66FSfhh3FGrhmGe+qXfUQTkAjDkO/fieSi4BE8G5GXu8Qo/xBj11trsP06DpaOHwz3Bim1Krz8hxbT8sR8aGY8xbwXE04lm1kvy6W81nqYs7AS6JXCH6blQ1aF6xhcanAK9bP7FIWA4JZvDXZAnE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1608376339567423.9226730746468; Sat, 19 Dec 2020 03:12:19 -0800 (PST) Received: from localhost ([::1]:36312 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqa9q-0002GG-HT for importer@patchew.org; Sat, 19 Dec 2020 06:12:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50914) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZu2-0005NI-HW for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:25429) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtn-0007Ic-AL for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:58 -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-133-7TazG8DyMquqPgRr-eWapw-1; Sat, 19 Dec 2020 05:55:39 -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 9E4658015C4; Sat, 19 Dec 2020 10:55:38 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4C6305D9C2; Sat, 19 Dec 2020 10:55:38 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id EAA9E112564E; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375342; 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=vqhxR6uXG1fRCc/R6LcSH7A4bTgvfonW5xTAWh7dTgA=; b=Ard8uiZHJDuFj54HReJQwmsODr990+1821YI2GPAfOoU9iKURj5JAoFnY+BJpSYtwKXrq+ uBX2MaeRBLpdU548ja4UieyjdkEv8APi02chzPAN01aGXwiX89Xmn6r2xIKpkhsXg/am4P T8Z5Ze1zwZKUUUwW2dnHiZzW23QKXLM= X-MC-Unique: 7TazG8DyMquqPgRr-eWapw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 33/33] qobject: Make QString immutable Date: Sat, 19 Dec 2020 11:55:32 +0100 Message-Id: <20201219105532.1734134-34-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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_H3=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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The functions to modify a QString's string are all unused now. Drop them, and make the string immutable. Saves 16 bytes per QString on my system. Signed-off-by: Markus Armbruster Message-Id: <20201211171152.146877-21-armbru@redhat.com> --- include/qapi/qmp/qstring.h | 8 +---- qobject/qstring.c | 65 ++------------------------------------ tests/check-qobject.c | 3 +- tests/check-qstring.c | 16 ---------- 4 files changed, 4 insertions(+), 88 deletions(-) diff --git a/include/qapi/qmp/qstring.h b/include/qapi/qmp/qstring.h index 53567db6c0..1d8ba46936 100644 --- a/include/qapi/qmp/qstring.h +++ b/include/qapi/qmp/qstring.h @@ -17,19 +17,13 @@ =20 struct QString { struct QObjectBase_ base; - char *string; - size_t length; - size_t capacity; + const char *string; }; =20 QString *qstring_new(void); QString *qstring_from_str(const char *str); QString *qstring_from_substr(const char *str, size_t start, size_t end); QString *qstring_from_gstring(GString *gstr); -size_t qstring_get_length(const QString *qstring); const char *qstring_get_str(const QString *qstring); -void qstring_append_int(QString *qstring, int64_t value); -void qstring_append(QString *qstring, const char *str); -void qstring_append_chr(QString *qstring, int c); =20 #endif /* QSTRING_H */ diff --git a/qobject/qstring.c b/qobject/qstring.c index ea86d80cf0..b4613899b9 100644 --- a/qobject/qstring.c +++ b/qobject/qstring.c @@ -24,14 +24,6 @@ QString *qstring_new(void) return qstring_from_str(""); } =20 -/** - * qstring_get_length(): Get the length of a QString - */ -size_t qstring_get_length(const QString *qstring) -{ - return qstring->length; -} - /** * qstring_from_substr(): Create a new QString from a C string substring * @@ -42,18 +34,9 @@ QString *qstring_from_substr(const char *str, size_t sta= rt, size_t end) QString *qstring; =20 assert(start <=3D end); - qstring =3D g_malloc(sizeof(*qstring)); qobject_init(QOBJECT(qstring), QTYPE_QSTRING); - - qstring->length =3D end - start; - qstring->capacity =3D qstring->length; - - assert(qstring->capacity < SIZE_MAX); - qstring->string =3D g_malloc(qstring->capacity + 1); - memcpy(qstring->string, str + start, qstring->length); - qstring->string[qstring->length] =3D 0; - + qstring->string =3D g_strndup(str + start, end - start); return qstring; } =20 @@ -79,55 +62,11 @@ QString *qstring_from_gstring(GString *gstr) =20 qstring =3D g_malloc(sizeof(*qstring)); qobject_init(QOBJECT(qstring), QTYPE_QSTRING); - qstring->length =3D gstr->len; - qstring->capacity =3D gstr->allocated_len; qstring->string =3D g_string_free(gstr, false); return qstring; } =20 =20 -static void capacity_increase(QString *qstring, size_t len) -{ - if (qstring->capacity < (qstring->length + len)) { - assert(len <=3D SIZE_MAX - qstring->capacity); - qstring->capacity +=3D len; - assert(qstring->capacity <=3D SIZE_MAX / 2); - qstring->capacity *=3D 2; /* use exponential growth */ - - qstring->string =3D g_realloc(qstring->string, qstring->capacity += 1); - } -} - -/* qstring_append(): Append a C string to a QString - */ -void qstring_append(QString *qstring, const char *str) -{ - size_t len =3D strlen(str); - - capacity_increase(qstring, len); - memcpy(qstring->string + qstring->length, str, len); - qstring->length +=3D len; - qstring->string[qstring->length] =3D 0; -} - -void qstring_append_int(QString *qstring, int64_t value) -{ - char num[32]; - - snprintf(num, sizeof(num), "%" PRId64, value); - qstring_append(qstring, num); -} - -/** - * qstring_append_chr(): Append a C char to a QString - */ -void qstring_append_chr(QString *qstring, int c) -{ - capacity_increase(qstring, 1); - qstring->string[qstring->length++] =3D c; - qstring->string[qstring->length] =3D 0; -} - /** * qstring_get_str(): Return a pointer to the stored string * @@ -158,6 +97,6 @@ void qstring_destroy_obj(QObject *obj) =20 assert(obj !=3D NULL); qs =3D qobject_to(QString, obj); - g_free(qs->string); + g_free((char *)qs->string); g_free(qs); } diff --git a/tests/check-qobject.c b/tests/check-qobject.c index 6b6deaeb8b..c1713d15af 100644 --- a/tests/check-qobject.c +++ b/tests/check-qobject.c @@ -155,8 +155,7 @@ static void qobject_is_equal_string_test(void) str_case =3D qstring_from_str("Foo"); =20 /* Should yield "foo" */ - str_built =3D qstring_from_substr("form", 0, 2); - qstring_append_chr(str_built, 'o'); + str_built =3D qstring_from_substr("buffoon", 3, 6); =20 check_unequal(str_base, str_whitespace_0, str_whitespace_1, str_whitespace_2, str_whitespace_3, str_case); diff --git a/tests/check-qstring.c b/tests/check-qstring.c index 2d079921e3..4bf9772093 100644 --- a/tests/check-qstring.c +++ b/tests/check-qstring.c @@ -47,21 +47,6 @@ static void qstring_get_str_test(void) qobject_unref(qstring); } =20 -static void qstring_append_chr_test(void) -{ - int i; - QString *qstring; - const char *str =3D "qstring append char unit-test"; - - qstring =3D qstring_new(); - - for (i =3D 0; str[i]; i++) - qstring_append_chr(qstring, str[i]); - - g_assert(strcmp(str, qstring_get_str(qstring)) =3D=3D 0); - qobject_unref(qstring); -} - static void qstring_from_substr_test(void) { QString *qs; @@ -90,7 +75,6 @@ int main(int argc, char **argv) =20 g_test_add_func("/public/from_str", qstring_from_str_test); g_test_add_func("/public/get_str", qstring_get_str_test); - g_test_add_func("/public/append_chr", qstring_append_chr_test); g_test_add_func("/public/from_substr", qstring_from_substr_test); g_test_add_func("/public/to_qstring", qobject_to_qstring_test); =20 --=20 2.26.2