From nobody Sun Feb 8 22:52:02 2026 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=1587717911; cv=none; d=zohomail.com; s=zohoarc; b=AjIn5miUd3bmU1GgI3HyEvle9NqfomK5pBt/xPXkGIbaQWK0VuR6OU6HrFXLxNMkJQwhmvvmyOazWm3ryw60PIXNinRgqpPn8SqU1qZvSo0kmmD3oVDJORI+xLMaraOeu5dqcs/bZbJn2hA/Q+9AWLf3cdPZRvbsxb/ICgYO3yk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587717911; 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=zdGuvNgNJoclIQOb6lRaWN64KeTwHmGMWZV8PD3OfaY=; b=efaxQZPqdBzRXxglKUvOoYpcfRdJN6a+nc0kEUbZAkhlWqYliUJS8CAWBHxZEV1OpKWfWL+1rR9xoJVwWbgpegyG5mjYv72xnRORR6A8p+ojZOkoWPLmzYFmnwezaa9zOaUC/iYWW+hELGWKMqGGo8q+R4YcGNnDj1cGoO5WQzE= 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 1587717911935592.2228029990029; Fri, 24 Apr 2020 01:45:11 -0700 (PDT) Received: from localhost ([::1]:54874 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRtxO-0007Ql-3s for importer@patchew.org; Fri, 24 Apr 2020 04:45:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36652) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRtw1-0005e7-1j for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRtw0-00024f-7t for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:44 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:35935 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jRtvz-000248-QK for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:43 -0400 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-478-S9UZDmLtOxmslWbeUivCMQ-1; Fri, 24 Apr 2020 04:43:41 -0400 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 A7B4A18FE861; Fri, 24 Apr 2020 08:43:40 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-113-6.ams2.redhat.com [10.36.113.6]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5AFA95D70B; Fri, 24 Apr 2020 08:43:40 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id D214311358BD; Fri, 24 Apr 2020 10:43:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587717823; 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=zdGuvNgNJoclIQOb6lRaWN64KeTwHmGMWZV8PD3OfaY=; b=Ar2V6T3ZVOdpMfIzy4TB37bYXmjuRouvvqcKbDhwDf4h3xoxQYMJOEtzq6/9R3x2Vh0pA7 Ga48Sj6zy7w5E2/CUcjaEAQ8BaQA6jvo6wV1J0LsNHDtZdqzY7m7AeRoLctJFjmOsRdZXr IF95YfkRUHsk+rKjxfmnQy8bnVQRNAk= X-MC-Unique: S9UZDmLtOxmslWbeUivCMQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 01/15] qapi: Belatedly update visitor.h's big comment for QAPI modules Date: Fri, 24 Apr 2020 10:43:24 +0200 Message-Id: <20200424084338.26803-2-armbru@redhat.com> In-Reply-To: <20200424084338.26803-1-armbru@redhat.com> References: <20200424084338.26803-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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=205.139.110.61; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/24 02:57:59 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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: mdroth@linux.vnet.ibm.com 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" Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- include/qapi/visitor.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h index c5b23851a1..f8a0fc1ea9 100644 --- a/include/qapi/visitor.h +++ b/include/qapi/visitor.h @@ -58,7 +58,7 @@ * * where T is FOO for scalar types, and FOO * otherwise. The scalar * visitors are declared here; the remaining visitors are generated in - * qapi-visit.h. + * qapi-visit-MODULE.h. * * The @name parameter of visit_type_FOO() describes the relation * between this QAPI value and its parent container. When visiting @@ -86,16 +86,16 @@ * by manual construction. * * For the QAPI object types (structs, unions, and alternates), there - * is an additional generated function in qapi-visit.h compatible - * with: + * is an additional generated function in qapi-visit-MODULE.h + * compatible with: * * void visit_type_FOO_members(Visitor *v, FOO *obj, Error **errp); * * for visiting the members of a type without also allocating the QAPI * struct. * - * Additionally, in qapi-types.h, all QAPI pointer types (structs, - * unions, alternates, and lists) have a generated function compatible + * Additionally, QAPI pointer types (structs, unions, alternates, and + * lists) have a generated function in qapi-types-MODULE.h compatible * with: * * void qapi_free_FOO(FOO *obj); --=20 2.21.1 From nobody Sun Feb 8 22:52:02 2026 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=1587718250; cv=none; d=zohomail.com; s=zohoarc; b=JTw5t0cj2R5oB5DFBrBTTzWpdMkNZLY86AALI/WA0cOCtO96yGQyje2BOwZOAiWhVX+KoMNRggdiC1nb3ggA8aA16S8zjV8LXGo/2oou8ClbtlidbGQDIM6790zbkz+wqO9SIF+YZ8YEHdvnwuJhh6vQRezwdR+5CiRVVi5+Ews= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587718250; 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=agw2xR3FoLhsUJSn/He3ew7VPz+p34vBOddxjagzng0=; b=Qeqpc0/w49TNQNZaFmAv7FjOO8oqx+CUPr3dI/S8Zo5hdA7idO++oPEOSLkH+JKFc+Me1oSUjLsK4CToF/V3oKrDcv/LfO/COfGjtTSYNOOv5CobmJ37YtnL7+hvHTvDn0x1dFJjM1SEBUmgz8dhTVpvSsbiMAOnCRgy1WC4Mew= 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 1587718250969496.309852094867; Fri, 24 Apr 2020 01:50:50 -0700 (PDT) Received: from localhost ([::1]:55338 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRu2r-0000Zp-6d for importer@patchew.org; Fri, 24 Apr 2020 04:50:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36704) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRtw2-0005ek-Pf for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRtw0-00025P-SA for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:46 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:52226 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jRtw0-00024L-Dw for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:44 -0400 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-340-FOyMccDLOF6fKLNF8HO0oQ-1; Fri, 24 Apr 2020 04:43:41 -0400 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 A9A0180B70E; Fri, 24 Apr 2020 08:43:40 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-113-6.ams2.redhat.com [10.36.113.6]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5CB0B10016DA; Fri, 24 Apr 2020 08:43:40 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id D52AD11358BE; Fri, 24 Apr 2020 10:43:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587717823; 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=agw2xR3FoLhsUJSn/He3ew7VPz+p34vBOddxjagzng0=; b=Li3NSF9Gg+lo2wmlCsQeLvv08Khs3/pcSrXdjJJMVTVnmper11iNRnc69Pkedm7nadLWir 8d1cyxzZXf67cBsM6yCZr9tKQstaTMtGO/S8sAlsjQimfduWHTchsfPauGbtuNBusczjMM b2CV6nR8lzyawdMczD/ZkLiWH7kX8hE= X-MC-Unique: FOyMccDLOF6fKLNF8HO0oQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 02/15] qapi: Fix the virtual walk example in visitor.h's big comment Date: Fri, 24 Apr 2020 10:43:25 +0200 Message-Id: <20200424084338.26803-3-armbru@redhat.com> In-Reply-To: <20200424084338.26803-1-armbru@redhat.com> References: <20200424084338.26803-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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=205.139.110.61; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/24 02:57:59 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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: mdroth@linux.vnet.ibm.com 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" Call visit_check_list(). Missed in commit a4a1c70dc7 "qapi: Make input visitors detect unvisited list tails". Drop an irrelevant error_propagate() while there. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- include/qapi/visitor.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h index f8a0fc1ea9..7f63e4c381 100644 --- a/include/qapi/visitor.h +++ b/include/qapi/visitor.h @@ -215,6 +215,9 @@ * goto outlist; * } * outlist: + * if (!err) { + * visit_check_list(v, &err); + * } * visit_end_list(v, NULL); * if (!err) { * visit_check_struct(v, &err); @@ -222,7 +225,6 @@ * outobj: * visit_end_struct(v, NULL); * out: - * error_propagate(errp, err); * visit_free(v); * */ --=20 2.21.1 From nobody Sun Feb 8 22:52:02 2026 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=1587717910; cv=none; d=zohomail.com; s=zohoarc; b=DLjC2F2oLo7ZgBDW89EoYtgqC2hPnsEqki3p8viOQPEvsJyogIk7vuudi2LnpWaZG8zz6EJMD6fWn2zlTAXYJSJ9nig1C3E77aWosKEdv9d+ELv84Frb6bBX0rFTqwAn9pBDOUoI/d4pdWfeq44hAi5mSQTJJrVDU8RiozkFOHQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587717910; 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=TAV2xhcXlUODkFrnp9hgnflmY8ZxvRVq9YuteVWPylc=; b=XSNwtSNDJqFV6BXE3vxY9TpLQ/iA2jBXuPdu3M2xPccDqzVfXNSCulTeNdhUqkBAFACDPFCTVpWsanJbsereInot1i6FwBaXcb0LiIb0qB9iQ74FLV8oHLaCHS7FEdt1jzxHsSKMO8jkZ37qSFx2S1jD29cHWHzRJibne3tX3Ik= 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 1587717909964639.7773418849013; Fri, 24 Apr 2020 01:45:09 -0700 (PDT) Received: from localhost ([::1]:54862 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRtxI-0007ET-Rr for importer@patchew.org; Fri, 24 Apr 2020 04:45:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36664) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRtw1-0005e8-1Y for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRtw0-00024q-DM for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:44 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:27662 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jRtw0-00024C-0X for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:44 -0400 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-285-Wv4QlrwVPCqcb7b7vdjvUw-1; Fri, 24 Apr 2020 04:43:41 -0400 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 A44CA461; Fri, 24 Apr 2020 08:43:40 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-113-6.ams2.redhat.com [10.36.113.6]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5FE125D70C; Fri, 24 Apr 2020 08:43:40 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id D8AC611358BF; Fri, 24 Apr 2020 10:43:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587717823; 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=TAV2xhcXlUODkFrnp9hgnflmY8ZxvRVq9YuteVWPylc=; b=IdamB3PbNRF3qUMDk8tyRYkkEOT1EA2BLWBFoeoVk+L0i5Hs7blfxVoCE2qPdXGijZhtfc ICkhSQVqL1SKJO4S1diCMTLdYbfSgeKb2HmLwl2v/Pv44srliRWHKM2q+erelCP4rMyUwA tlP+Ht6/YsAg4EPQjOU3ntwO+7kk48o= X-MC-Unique: Wv4QlrwVPCqcb7b7vdjvUw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 03/15] qapi: Fix typo in visit_start_list()'s contract Date: Fri, 24 Apr 2020 10:43:26 +0200 Message-Id: <20200424084338.26803-4-armbru@redhat.com> In-Reply-To: <20200424084338.26803-1-armbru@redhat.com> References: <20200424084338.26803-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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=207.211.31.120; envelope-from=armbru@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/24 03:07:34 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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: mdroth@linux.vnet.ibm.com 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" Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- include/qapi/visitor.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h index 7f63e4c381..c5d0ce9184 100644 --- a/include/qapi/visitor.h +++ b/include/qapi/visitor.h @@ -345,9 +345,9 @@ void visit_end_struct(Visitor *v, void **obj); * input visitors set *@list to NULL. * * After visit_start_list() succeeds, the caller may visit its members - * one after the other. A real visit (where @obj is non-NULL) uses + * one after the other. A real visit (where @list is non-NULL) uses * visit_next_list() for traversing the linked list, while a virtual - * visit (where @obj is NULL) uses other means. For each list + * visit (where @list is NULL) uses other means. For each list * element, call the appropriate visit_type_FOO() with name set to * NULL and obj set to the address of the value member of the list * element. Finally, visit_end_list() needs to be called with the --=20 2.21.1 From nobody Sun Feb 8 22:52:02 2026 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=1587718023; cv=none; d=zohomail.com; s=zohoarc; b=NrzOrDJCdvbSh4wy8kehEVB+/32siwjGE7m+MpekELpo9WoHUXSiOo3/jo3sDgpNwUcjQsPEh3y5fcbWvKQi7f3FdCpC90nXDHR3WWDPLBI3Ib2FWS8r2ntCFyGfKICnoL2oMDmydCvA51zPccsJk32syKkTL5ZHmiPPkDUqJH4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587718023; 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=dvVGsdZJ9alE8IhMtuIoIkeU5eNisODPa6Z3hFo46GA=; b=BoUQrn6Wo3rSjB2ojMjVYA29DJQulfuH9sw5hwvi97gG5y0T3do1Y1MJbLQp9ECrqTliPDgUo2R3ygDJ8kRDDWomKmAQJt/pcPMW1oecQBmX7BC6oC4x9EYahEUVHaHYdW+Q1r+sVXj9vZj0uLFJGyBejtQYaMnIddMgtWUsaRU= 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 158771802355453.31052552877463; Fri, 24 Apr 2020 01:47:03 -0700 (PDT) Received: from localhost ([::1]:55048 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRtzC-0002gK-88 for importer@patchew.org; Fri, 24 Apr 2020 04:47:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36672) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRtw1-0005eA-FJ for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRtw0-00024w-F5 for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:45 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:41123 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jRtw0-00024A-1M for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:44 -0400 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-478-lLH9WUSENqmuTqEo3hBDKg-1; Fri, 24 Apr 2020 04:43:41 -0400 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 C90E9107ACF3; Fri, 24 Apr 2020 08:43:40 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-113-6.ams2.redhat.com [10.36.113.6]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 62D3760F8D; Fri, 24 Apr 2020 08:43:40 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id DBE4E11358C0; Fri, 24 Apr 2020 10:43:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587717823; 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=dvVGsdZJ9alE8IhMtuIoIkeU5eNisODPa6Z3hFo46GA=; b=Tfg+tMiY0GjXQagJQLWVRD38jl1KZGlNuEpcw/S3+LdM4oJdjFsQjJE2JogPqNrZBqXXhR PCYbw6XDEB2df+kmGTacJitd+juOJ1GwnzwipjgFbnhqVP1gsJdQl4Ja7cUctwyFZwmO6/ nokqFZjzAexaR5gQT6VPGLMSQQCXueU= X-MC-Unique: lLH9WUSENqmuTqEo3hBDKg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 04/15] qapi: Document @errp usage more thoroughly in visitor.h Date: Fri, 24 Apr 2020 10:43:27 +0200 Message-Id: <20200424084338.26803-5-armbru@redhat.com> In-Reply-To: <20200424084338.26803-1-armbru@redhat.com> References: <20200424084338.26803-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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=205.139.110.61; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/24 02:57:59 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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: mdroth@linux.vnet.ibm.com 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" Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- include/qapi/visitor.h | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h index c5d0ce9184..09df7099c6 100644 --- a/include/qapi/visitor.h +++ b/include/qapi/visitor.h @@ -284,9 +284,7 @@ void visit_free(Visitor *v); * into *@obj. @obj may also be NULL for a virtual walk, in which * case @size is ignored. * - * @errp obeys typical error usage, and reports failures such as a - * member @name is not present, or present but not an object. On - * error, input visitors set *@obj to NULL. + * On failure, set *@obj to NULL and store an error through @errp. * * After visit_start_struct() succeeds, the caller may visit its * members one after the other, passing the member's name and address @@ -303,8 +301,7 @@ void visit_start_struct(Visitor *v, const char *name, v= oid **obj, /* * Prepare for completing an object visit. * - * @errp obeys typical error usage, and reports failures such as - * unparsed keys remaining in the input stream. + * On failure, store an error through @errp. * * Should be called prior to visit_end_struct() if all other * intermediate visit steps were successful, to allow the visitor one @@ -340,9 +337,7 @@ void visit_end_struct(Visitor *v, void **obj); * allow @list to be NULL for a virtual walk, in which case @size is * ignored. * - * @errp obeys typical error usage, and reports failures such as a - * member @name is not present, or present but not a list. On error, - * input visitors set *@list to NULL. + * On failure, set *@list to NULL and store an error through @errp. * * After visit_start_list() succeeds, the caller may visit its members * one after the other. A real visit (where @list is non-NULL) uses @@ -376,8 +371,7 @@ GenericList *visit_next_list(Visitor *v, GenericList *t= ail, size_t size); /* * Prepare for completing a list visit. * - * @errp obeys typical error usage, and reports failures such as - * unvisited list tail remaining in the input stream. + * On failure, store an error through @errp. * * Should be called prior to visit_end_list() if all other * intermediate visit steps were successful, to allow the visitor one @@ -409,8 +403,10 @@ void visit_end_list(Visitor *v, void **list); * * @obj must not be NULL. Input and clone visitors use @size to * determine how much memory to allocate into *@obj, then determine - * the qtype of the next thing to be visited, stored in (*@obj)->type. - * Other visitors will leave @obj unchanged. + * the qtype of the next thing to be visited, and store it in + * (*@obj)->type. Other visitors leave @obj unchanged. + * + * On failure, set *@obj to NULL and store an error through @errp. * * If successful, this must be paired with visit_end_alternate() with * the same @obj to clean up, even if visiting the contents of the @@ -463,8 +459,9 @@ bool visit_optional(Visitor *v, const char *name, bool = *present); * * Currently, all input visitors parse text input, and all output * visitors produce text output. The mapping between enumeration - * values and strings is done by the visitor core, using @strings; it - * should be the ENUM_lookup array from visit-types.h. + * values and strings is done by the visitor core, using @lookup. + * + * On failure, store an error through @errp. * * May call visit_type_str() under the hood, and the enum visit may * fail even if the corresponding string visit succeeded; this implies @@ -488,6 +485,8 @@ bool visit_is_input(Visitor *v); * * @obj must be non-NULL. Input visitors set *@obj to the value; * other visitors will leave *@obj unchanged. + * + * On failure, store an error through @errp. */ void visit_type_int(Visitor *v, const char *name, int64_t *obj, Error **er= rp); =20 @@ -564,6 +563,8 @@ void visit_type_size(Visitor *v, const char *name, uint= 64_t *obj, * * @obj must be non-NULL. Input visitors set *@obj to the value; * other visitors will leave *@obj unchanged. + * + * On failure, store an error through @errp. */ void visit_type_bool(Visitor *v, const char *name, bool *obj, Error **errp= ); =20 @@ -581,6 +582,8 @@ void visit_type_bool(Visitor *v, const char *name, bool= *obj, Error **errp); * It is safe to cast away const when preparing a (const char *) value * into @obj for use by an output visitor. * + * On failure, set *@obj to NULL and store an error through @errp. + * * FIXME: Callers that try to output NULL *obj should not be allowed. */ void visit_type_str(Visitor *v, const char *name, char **obj, Error **errp= ); @@ -594,6 +597,8 @@ void visit_type_str(Visitor *v, const char *name, char = **obj, Error **errp); * @obj must be non-NULL. Input visitors set *@obj to the value; * other visitors will leave *@obj unchanged. Visitors should * document if infinity or NaN are not permitted. + * + * On failure, store an error through @errp. */ void visit_type_number(Visitor *v, const char *name, double *obj, Error **errp); @@ -608,6 +613,8 @@ void visit_type_number(Visitor *v, const char *name, do= uble *obj, * other visitors will leave *@obj unchanged. *@obj must be non-NULL * for output visitors. * + * On failure, set *@obj to NULL and store an error through @errp. + * * Note that some kinds of input can't express arbitrary QObject. * E.g. the visitor returned by qobject_input_visitor_new_keyval() * can't create numbers or booleans, only strings. @@ -622,6 +629,8 @@ void visit_type_any(Visitor *v, const char *name, QObje= ct **obj, Error **errp); * * @obj must be non-NULL. Input visitors set *@obj to the value; * other visitors ignore *@obj. + * + * On failure, set *@obj to NULL and store an error through @errp. */ void visit_type_null(Visitor *v, const char *name, QNull **obj, Error **errp); --=20 2.21.1 From nobody Sun Feb 8 22:52:02 2026 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=1587718676; cv=none; d=zohomail.com; s=zohoarc; b=XHQ7RPj3wDS8BClEt/A5zk5+xcN1ujMyweZzFORITORS2CPpE3c9J+6a3GPzBNSKvXSVgMtpeVWJfT641zggOuYRxhFMqWEYsR2Dr/8+ika5exSyMqmrwWl+qrKtmXwtcFSwY6jgOLWjBACjrBSVFlL9uqad23XkgsehlAtapT4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587718676; 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=zgFMq8bQpgJdbXdZXsZY6rZNQAS4ggeYICAj4u3G42c=; b=WLXCiDM78AC/EuEwt7+EjHFwkGKHCsno2aXzvfvZMTIlmo2McSeGuqOTqxrGgWL3YSwMW0i2YR9/4IwWUh4on0kEtDpCCsMdSFfgFoIXxIXPEJI1mlKwd4LWGUToKc4a+rwZvF9JiP6ZnO+tlt7p0Xhnz6VnZOX5iynht0qK/vc= 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 1587718676436542.7630292844133; Fri, 24 Apr 2020 01:57:56 -0700 (PDT) Received: from localhost ([::1]:55842 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRu9i-0002dP-3Z for importer@patchew.org; Fri, 24 Apr 2020 04:57:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36918) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRtwE-00062f-HH for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRtw2-0002B0-9b for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:58 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:43913 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jRtw1-00026M-Lr for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:45 -0400 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-155-B_g4EV3rM7uM_O_2LePAhg-1; Fri, 24 Apr 2020 04:43:43 -0400 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 4A2738005B7; Fri, 24 Apr 2020 08:43:42 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-113-6.ams2.redhat.com [10.36.113.6]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E6DA35D70C; Fri, 24 Apr 2020 08:43:41 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id DF49611358C1; Fri, 24 Apr 2020 10:43:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587717824; 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=zgFMq8bQpgJdbXdZXsZY6rZNQAS4ggeYICAj4u3G42c=; b=izQVrZoWqrvKqKFgWirGAzzTBpDo9/aK6re1M9eLkHrC2gpiTEkNN1xx6wAPtkdBKPndaH +uQpUD8Thinmli8i0I3EddnRiOxHukB2DPdRPpBdGmyuFHMr5pO3s/a9m72VUNr1Y37PGG uS8DiK3JIxLt+eYqRE7M/xUCmcmEzY8= X-MC-Unique: B_g4EV3rM7uM_O_2LePAhg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 05/15] qapi: Polish prose in visitor.h Date: Fri, 24 Apr 2020 10:43:28 +0200 Message-Id: <20200424084338.26803-6-armbru@redhat.com> In-Reply-To: <20200424084338.26803-1-armbru@redhat.com> References: <20200424084338.26803-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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=207.211.31.120; envelope-from=armbru@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/24 03:07:34 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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: mdroth@linux.vnet.ibm.com 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" Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- include/qapi/visitor.h | 104 +++++++++++++++++++++-------------------- 1 file changed, 54 insertions(+), 50 deletions(-) diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h index 09df7099c6..a425ea514c 100644 --- a/include/qapi/visitor.h +++ b/include/qapi/visitor.h @@ -25,19 +25,21 @@ * for doing work at each node of a QAPI graph; it can also be used * for a virtual walk, where there is no actual QAPI C struct. * - * There are four kinds of visitor classes: input visitors (QObject, - * string, and QemuOpts) parse an external representation and build - * the corresponding QAPI graph, output visitors (QObject and string) take - * a completed QAPI graph and generate an external representation, the - * dealloc visitor can take a QAPI graph (possibly partially - * constructed) and recursively free its resources, and the clone - * visitor performs a deep clone of one QAPI object to another. While - * the dealloc and QObject input/output visitors are general, the string, - * QemuOpts, and clone visitors have some implementation limitations; - * see the documentation for each visitor for more details on what it - * supports. Also, see visitor-impl.h for the callback contracts - * implemented by each visitor, and docs/devel/qapi-code-gen.txt for more - * about the QAPI code generator. + * There are four kinds of visitors: input visitors (QObject, string, + * and QemuOpts) parse an external representation and build the + * corresponding QAPI object, output visitors (QObject and string) + * take a QAPI object and generate an external representation, the + * dealloc visitor takes a QAPI object (possibly partially + * constructed) and recursively frees it, and the clone visitor + * performs a deep clone of a QAPI object. + * + * While the dealloc and QObject input/output visitors are general, + * the string, QemuOpts, and clone visitors have some implementation + * limitations; see the documentation for each visitor for more + * details on what it supports. Also, see visitor-impl.h for the + * callback contracts implemented by each visitor, and + * docs/devel/qapi-code-gen.txt for more about the QAPI code + * generator. * * All of the visitors are created via: * @@ -45,11 +47,15 @@ * * A visitor should be used for exactly one top-level visit_type_FOO() * or virtual walk; if that is successful, the caller can optionally - * call visit_complete() (for now, useful only for output visits, but - * safe to call on all visits). Then, regardless of success or - * failure, the user should call visit_free() to clean up resources. - * It is okay to free the visitor without completing the visit, if - * some other error is detected in the meantime. + * call visit_complete() (useful only for output visits, but safe to + * call on all visits). Then, regardless of success or failure, the + * user should call visit_free() to clean up resources. It is okay to + * free the visitor without completing the visit, if some other error + * is detected in the meantime. + * + * The clone and dealloc visitor should not be used directly outside + * of QAPI code. Use the qapi_free_FOO() and QAPI_CLONE() instead, + * described below. * * All QAPI types have a corresponding function with a signature * roughly compatible with this: @@ -68,22 +74,26 @@ * alternate, @name should equal the name used for visiting the * alternate. * - * The visit_type_FOO() functions expect a non-null @obj argument; - * they allocate *@obj during input visits, leave it unchanged on - * output visits, and recursively free any resources during a dealloc - * visit. Each function also takes the customary @errp argument (see + * The visit_type_FOO() functions take a non-null @obj argument; they + * allocate *@obj during input visits, leave it unchanged during + * output and clone visits, and free it (recursively) during a dealloc + * visit. + * + * Each function also takes the customary @errp argument (see * qapi/error.h for details), for reporting any errors (such as if a * member @name is not present, or is present but not the specified * type). * * If an error is detected during visit_type_FOO() with an input - * visitor, then *@obj will be NULL for pointer types, and left - * unchanged for scalar types. Using an output or clone visitor with - * an incomplete object has undefined behavior (other than a special - * case for visit_type_str() treating NULL like ""), while the dealloc - * visitor safely handles incomplete objects. Since input visitors - * never produce an incomplete object, such an object is possible only - * by manual construction. + * visitor, then *@obj will be set to NULL for pointer types, and left + * unchanged for scalar types. + * + * Using an output or clone visitor with an incomplete object has + * undefined behavior (other than a special case for visit_type_str() + * treating NULL like ""), while the dealloc visitor safely handles + * incomplete objects. Since input visitors never produce an + * incomplete object, such an object is possible only by manual + * construction. * * For the QAPI object types (structs, unions, and alternates), there * is an additional generated function in qapi-visit-MODULE.h @@ -100,23 +110,20 @@ * * void qapi_free_FOO(FOO *obj); * - * where behaves like free() in that @obj may be NULL. Such objects - * may also be used with the following macro, provided alongside the - * clone visitor: + * Does nothing when @obj is NULL. + * + * Such objects may also be used with macro * * Type *QAPI_CLONE(Type, src); * - * in order to perform a deep clone of @src. Because of the generated - * qapi_free functions and the QAPI_CLONE() macro, the clone and - * dealloc visitor should not be used directly outside of QAPI code. + * in order to perform a deep clone of @src. * - * QAPI types can also inherit from a base class; when this happens, a - * function is generated for easily going from the derived type to the - * base type: + * For QAPI types can that inherit from a base type, a function is + * generated for going from the derived type to the base type: * * BASE *qapi_CHILD_base(CHILD *obj); * - * For a real QAPI struct, typical input usage involves: + * Typical input visitor usage involves: * * * Foo *f; @@ -153,7 +160,7 @@ * qapi_free_FooList(l); * * - * Similarly, typical output usage is: + * Typical output visitor usage: * * * Foo *f =3D ...obtain populated object... @@ -172,17 +179,8 @@ * visit_free(v); * * - * When visiting a real QAPI struct, this file provides several - * helpers that rely on in-tree information to control the walk: - * visit_optional() for the 'has_member' field associated with - * optional 'member' in the C struct; and visit_next_list() for - * advancing through a FooList linked list. Similarly, the - * visit_is_input() helper makes it possible to write code that is - * visitor-agnostic everywhere except for cleanup. Only the generated - * visit_type functions need to use these helpers. - * * It is also possible to use the visitors to do a virtual walk, where - * no actual QAPI struct is present. In this situation, decisions + * no actual QAPI object is present. In this situation, decisions * about what needs to be walked are made by the calling code, and * structured visits are split between pairs of start and end methods * (where the end method must be called if the start function @@ -227,6 +225,12 @@ * out: * visit_free(v); * + * + * This file provides helpers for use by the generated + * visit_type_FOO(): visit_optional() for the 'has_member' field + * associated with optional 'member' in the C struct, + * visit_next_list() for advancing through a FooList linked list, and + * visit_is_input() for cleaning up on failure. */ =20 /*** Useful types ***/ --=20 2.21.1 From nobody Sun Feb 8 22:52:02 2026 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=1587718525; cv=none; d=zohomail.com; s=zohoarc; b=C/uW3lcOOV+sfbzZLEcCokRk/uJ+5UFj/AQw+RozSrA+HRGwyPbHEErbzVbHeYI9k/Gkc3JqDVVxhZ9jSNeOnWHxxTZRX/cDdRVeWxJ/gWnWXYxnyCGtTKtntZWGn7nCTeM+IhUP7OKCx5hddmjIhcpR+hcROERibH//91tbFpo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587718525; 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=r2bTsOPYHrwb9n0OKeIzU4fn75r1gih2+vUSm1+9v/E=; b=L4dvZvOHHUCTtDN8axEq9fvY7ELF8TqctYqEpPY8RdigY78dy5aZ0GcFpBsH7uwCU/ziru1YunFrFl41wqIy3Fm9PnUy3f/VQhIG8SeWUSAuFUe5MJm91xguxKrTHQXDuYiYlG7VVqxRb/ZpIjt8lqLl3CL9L/OwtcqFiVUrgBE= 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 1587718525443295.97999513686545; Fri, 24 Apr 2020 01:55:25 -0700 (PDT) Received: from localhost ([::1]:55642 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRu7I-0007Lj-7B for importer@patchew.org; Fri, 24 Apr 2020 04:55:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36754) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRtw4-0005hh-Ej for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRtw2-0002BT-9j for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:48 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:21854 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jRtw1-00026C-Ko for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:45 -0400 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-171-rDDnzSXoNPi7MH0Hl1DAFQ-1; Fri, 24 Apr 2020 04:43:43 -0400 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 21EF745F; Fri, 24 Apr 2020 08:43:42 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-113-6.ams2.redhat.com [10.36.113.6]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E663A5D70B; Fri, 24 Apr 2020 08:43:41 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id E2AEF11358C2; Fri, 24 Apr 2020 10:43:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587717824; 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=r2bTsOPYHrwb9n0OKeIzU4fn75r1gih2+vUSm1+9v/E=; b=gTzJ5DW8Dtap9+/nsu04rH5GaoBBzdnJm0DiSkG2zqkJChUQMai5cctlXbus10UiQDXlJx UIeykoN/lyDG6H1GoHN8RlIPdkLG+ih2Vjt0I1o6QnWqmgJX1fXJSyY4T4xWZICiMWnQfZ cuXIRygRxsf4u6abVv92VeNHiGN1IQw= X-MC-Unique: rDDnzSXoNPi7MH0Hl1DAFQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 06/15] qapi: Assert incomplete object occurs only in dealloc visitor Date: Fri, 24 Apr 2020 10:43:29 +0200 Message-Id: <20200424084338.26803-7-armbru@redhat.com> In-Reply-To: <20200424084338.26803-1-armbru@redhat.com> References: <20200424084338.26803-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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=207.211.31.120; envelope-from=armbru@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/24 03:07:34 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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: mdroth@linux.vnet.ibm.com 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" Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Signed-off-by: Markus Armbruster --- docs/devel/qapi-code-gen.txt | 2 ++ include/qapi/visitor.h | 5 +++++ qapi/qapi-visit-core.c | 5 +++++ scripts/qapi/visit.py | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index 1967adfa92..c6dd1891c3 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -1446,6 +1446,8 @@ Example: goto out; } if (!*obj) { + /* incomplete */ + assert(visit_is_dealloc(v)); goto out_obj; } visit_type_UserDefOne_members(v, *obj, &err); diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h index a425ea514c..2d40d2fe0f 100644 --- a/include/qapi/visitor.h +++ b/include/qapi/visitor.h @@ -479,6 +479,11 @@ void visit_type_enum(Visitor *v, const char *name, int= *obj, */ bool visit_is_input(Visitor *v); =20 +/* + * Check if visitor is a dealloc visitor. + */ +bool visit_is_dealloc(Visitor *v); + /*** Visiting built-in types ***/ =20 /* diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c index 5365561b07..d4aac206cf 100644 --- a/qapi/qapi-visit-core.c +++ b/qapi/qapi-visit-core.c @@ -142,6 +142,11 @@ bool visit_is_input(Visitor *v) return v->type =3D=3D VISITOR_INPUT; } =20 +bool visit_is_dealloc(Visitor *v) +{ + return v->type =3D=3D VISITOR_DEALLOC; +} + void visit_type_int(Visitor *v, const char *name, int64_t *obj, Error **er= rp) { assert(obj); diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 23d9194aa4..e3467b770b 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -189,6 +189,8 @@ void visit_type_%(c_name)s(Visitor *v, const char *name= , %(c_name)s **obj, Error goto out; } if (!*obj) { + /* incomplete */ + assert(visit_is_dealloc(v)); goto out_obj; } switch ((*obj)->type) { @@ -260,6 +262,8 @@ void visit_type_%(c_name)s(Visitor *v, const char *name= , %(c_name)s **obj, Error goto out; } if (!*obj) { + /* incomplete */ + assert(visit_is_dealloc(v)); goto out_obj; } visit_type_%(c_name)s_members(v, *obj, &err); --=20 2.21.1 From nobody Sun Feb 8 22:52:02 2026 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=1587718144; cv=none; d=zohomail.com; s=zohoarc; b=AWloNzBvSlmflZ5dYu5iAk8MdiseLYSzmpWxgI3BXdUgo5H0aeZos4BickbqEm8nWVkPE/Y2QlsbVYeneVLBCL8pUK0XoyhX/RYQ/0RelTeJLZPoTNPiePsIDXwVTU6JH9ZMz1nuiljeI0xrpAFoot6sPG/FtMzPwRUFPkoYPjM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587718144; 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=nlhIBE9wCreqoJev7C2ceZoOivO0fBd4IhEJP3CNvNw=; b=keFqum75iG86dm3Dkx8TyBg4EhpVMNEkGrVHlpZ7pEgLyYNxDnnBHCPK0507ipNjJnFYiuo/EOOcFMHTA7hYGk6JJrR97KUVRXxuCcAim3jzSAWQOuX9rUnALjNhy5CoRtbjwBsVVp6Yy8XXqrl9+JuIZaGuEPUbJPf3inyYI+U= 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 1587718144692689.5922988910094; Fri, 24 Apr 2020 01:49:04 -0700 (PDT) Received: from localhost ([::1]:55192 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRu19-00069K-D4 for importer@patchew.org; Fri, 24 Apr 2020 04:49:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36722) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRtw3-0005fm-E1 for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRtw2-0002BD-6s for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:47 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:58615 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jRtw1-00026i-L9 for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:45 -0400 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-317-cRRtKpGVOsiEfhs9985E6w-1; Fri, 24 Apr 2020 04:43:43 -0400 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 255D5107ACCA; Fri, 24 Apr 2020 08:43:42 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-113-6.ams2.redhat.com [10.36.113.6]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EA017600EF; Fri, 24 Apr 2020 08:43:41 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id E5FED11358C3; Fri, 24 Apr 2020 10:43:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587717824; 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=nlhIBE9wCreqoJev7C2ceZoOivO0fBd4IhEJP3CNvNw=; b=NRpaZ+ezPHHIOYNcW7wxvp2jaw8BfFiaRLbwKgsg4waOFty01ZNcAslCen9MwbjWyPfEZo UgJ22XY3tM6PDaplFkxTZfjI+Fj/c8DRcfHf8c4moOHsOjwVPLwJlma2v2hYVrPjelP0nv z82W13W5gcu1BTy2VhEDebdFgZxZq/I= X-MC-Unique: cRRtKpGVOsiEfhs9985E6w-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 07/15] qapi: Fix Visitor contract for start_alternate() Date: Fri, 24 Apr 2020 10:43:30 +0200 Message-Id: <20200424084338.26803-8-armbru@redhat.com> In-Reply-To: <20200424084338.26803-1-armbru@redhat.com> References: <20200424084338.26803-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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=207.211.31.120; envelope-from=armbru@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/24 03:07:34 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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: mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The contract demands v->start_alternate() for input and dealloc visitors, but visit_start_alternate() actually requires it for input and clone visitors. Fix the contract, and delete superfluous qapi_dealloc_start_alternate(). Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- include/qapi/visitor-impl.h | 5 ++--- qapi/qapi-dealloc-visitor.c | 7 ------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/include/qapi/visitor-impl.h b/include/qapi/visitor-impl.h index 8ccb3b6c20..252206dc0d 100644 --- a/include/qapi/visitor-impl.h +++ b/include/qapi/visitor-impl.h @@ -67,13 +67,12 @@ struct Visitor /* Must be set */ void (*end_list)(Visitor *v, void **list); =20 - /* Must be set by input and dealloc visitors to visit alternates; - * optional for output visitors. */ + /* Must be set by input and clone visitors to visit alternates */ void (*start_alternate)(Visitor *v, const char *name, GenericAlternate **obj, size_t size, Error **errp); =20 - /* Optional, needed for dealloc visitor */ + /* Optional */ void (*end_alternate)(Visitor *v, void **obj); =20 /* Must be set */ diff --git a/qapi/qapi-dealloc-visitor.c b/qapi/qapi-dealloc-visitor.c index d192724b13..2239fc6417 100644 --- a/qapi/qapi-dealloc-visitor.c +++ b/qapi/qapi-dealloc-visitor.c @@ -34,12 +34,6 @@ static void qapi_dealloc_end_struct(Visitor *v, void **o= bj) } } =20 -static void qapi_dealloc_start_alternate(Visitor *v, const char *name, - GenericAlternate **obj, size_t si= ze, - Error **errp) -{ -} - static void qapi_dealloc_end_alternate(Visitor *v, void **obj) { if (obj) { @@ -123,7 +117,6 @@ Visitor *qapi_dealloc_visitor_new(void) v->visitor.type =3D VISITOR_DEALLOC; v->visitor.start_struct =3D qapi_dealloc_start_struct; v->visitor.end_struct =3D qapi_dealloc_end_struct; - v->visitor.start_alternate =3D qapi_dealloc_start_alternate; v->visitor.end_alternate =3D qapi_dealloc_end_alternate; v->visitor.start_list =3D qapi_dealloc_start_list; v->visitor.next_list =3D qapi_dealloc_next_list; --=20 2.21.1 From nobody Sun Feb 8 22:52:02 2026 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=1587718250; cv=none; d=zohomail.com; s=zohoarc; b=T20T4dd/1d3lRoOm/mL6uzUE4RDHOYegiLh2HLFDAe0aqjOdvFdkts/ckVz2oTgKM4WoYEuBLqnMee0rLw2Edm0MCoKaO59RSuy8tzV0ypnMsmaMJclX/3/ACpQxDw/0xXxtReQhs/1o0v9yg7HhnfHPq7WXXmHftkl/dIFxjHQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587718250; 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=EC1eBNlA151Lmref6Ha1Xz2fSZDp1v6NUj8i4iaXwd8=; b=kIZ5gef41/LFc/z9FfXBVDIlmuT2CqzQksD/SBOb5pJgotzs+V6avsyKv5N3IOADOKZDpC/id9npiSc3ziuRCjjXdW3tlAvB/wa3FHZRy2Oiz/ADMtqlu3rVYislo+qRO/Tdik/9x97/oEoN1oztPuTkj5WPK13v0Gr2Up6l6Rw= 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 1587718250978276.75326238897014; Fri, 24 Apr 2020 01:50:50 -0700 (PDT) Received: from localhost ([::1]:55342 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRu2r-0000b3-8W for importer@patchew.org; Fri, 24 Apr 2020 04:50:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36822) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRtw6-0005mm-PD for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRtw4-0002JN-3H for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:50 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:53346 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jRtw3-0002Cx-In for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:47 -0400 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-59-Ac1Kzeb-O4Ch8UBAAgrNbw-1; Fri, 24 Apr 2020 04:43:45 -0400 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 856E6107ACF4; Fri, 24 Apr 2020 08:43:44 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-113-6.ams2.redhat.com [10.36.113.6]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EABD510016DA; Fri, 24 Apr 2020 08:43:41 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id E921111358C4; Fri, 24 Apr 2020 10:43:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587717826; 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=EC1eBNlA151Lmref6Ha1Xz2fSZDp1v6NUj8i4iaXwd8=; b=gfuNEKCCUN3P9QoriNFqTVc+u4+2dillQgmt49gz0WJj7DmeUTBRMY0cwgyHXUaF4nauAb /qnzn0rSfFXduTaCjiG7CZTtwrvO6FoXzol0SNm21G5nTh4P02ozcBrDODZQNDt2IsIl+A 4mRkv826XeHkdWWD6JigUojTBWQY6oQ= X-MC-Unique: Ac1Kzeb-O4Ch8UBAAgrNbw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 08/15] qapi: Assert output visitors see only valid enum values Date: Fri, 24 Apr 2020 10:43:31 +0200 Message-Id: <20200424084338.26803-9-armbru@redhat.com> In-Reply-To: <20200424084338.26803-1-armbru@redhat.com> References: <20200424084338.26803-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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=207.211.31.120; envelope-from=armbru@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/24 03:07:34 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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: mdroth@linux.vnet.ibm.com 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" output_type_enum() fails when *obj is not a valid value of the enum type. Should not happen. Drop the check, along with its unit tests. qapi_enum_lookup()'s assertion still guards. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- qapi/qapi-visit-core.c | 9 ------- tests/test-qobject-output-visitor.c | 39 ----------------------------- tests/test-string-output-visitor.c | 19 -------------- 3 files changed, 67 deletions(-) diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c index d4aac206cf..80ca83bcb9 100644 --- a/qapi/qapi-visit-core.c +++ b/qapi/qapi-visit-core.c @@ -341,15 +341,6 @@ static void output_type_enum(Visitor *v, const char *n= ame, int *obj, int value =3D *obj; char *enum_str; =20 - /* - * TODO why is this an error, not an assertion? If assertion: - * delete, and rely on qapi_enum_lookup() - */ - if (value < 0 || value >=3D lookup->size) { - error_setg(errp, QERR_INVALID_PARAMETER, name ? name : "null"); - return; - } - enum_str =3D (char *)qapi_enum_lookup(lookup, value); visit_type_str(v, name, &enum_str, errp); } diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-outpu= t-visitor.c index d7761ebf84..1c856d9bd2 100644 --- a/tests/test-qobject-output-visitor.c +++ b/tests/test-qobject-output-visitor.c @@ -141,21 +141,6 @@ static void test_visitor_out_enum(TestOutputVisitorDat= a *data, } } =20 -static void test_visitor_out_enum_errors(TestOutputVisitorData *data, - const void *unused) -{ - EnumOne i, bad_values[] =3D { ENUM_ONE__MAX, -1 }; - - for (i =3D 0; i < ARRAY_SIZE(bad_values) ; i++) { - Error *err =3D NULL; - - visit_type_EnumOne(data->ov, "unused", &bad_values[i], &err); - error_free_or_abort(&err); - visitor_reset(data); - } -} - - static void test_visitor_out_struct(TestOutputVisitorData *data, const void *unused) { @@ -234,26 +219,6 @@ static void test_visitor_out_struct_nested(TestOutputV= isitorData *data, qapi_free_UserDefTwo(ud2); } =20 -static void test_visitor_out_struct_errors(TestOutputVisitorData *data, - const void *unused) -{ - EnumOne bad_values[] =3D { ENUM_ONE__MAX, -1 }; - UserDefOne u =3D {0}; - UserDefOne *pu =3D &u; - int i; - - for (i =3D 0; i < ARRAY_SIZE(bad_values) ; i++) { - Error *err =3D NULL; - - u.has_enum1 =3D true; - u.enum1 =3D bad_values[i]; - visit_type_UserDefOne(data->ov, "unused", &pu, &err); - error_free_or_abort(&err); - visitor_reset(data); - } -} - - static void test_visitor_out_list(TestOutputVisitorData *data, const void *unused) { @@ -821,14 +786,10 @@ int main(int argc, char **argv) &out_visitor_data, test_visitor_out_no_string); output_visitor_test_add("/visitor/output/enum", &out_visitor_data, test_visitor_out_enum); - output_visitor_test_add("/visitor/output/enum-errors", - &out_visitor_data, test_visitor_out_enum_error= s); output_visitor_test_add("/visitor/output/struct", &out_visitor_data, test_visitor_out_struct); output_visitor_test_add("/visitor/output/struct-nested", &out_visitor_data, test_visitor_out_struct_nes= ted); - output_visitor_test_add("/visitor/output/struct-errors", - &out_visitor_data, test_visitor_out_struct_err= ors); output_visitor_test_add("/visitor/output/list", &out_visitor_data, test_visitor_out_list); output_visitor_test_add("/visitor/output/any", diff --git a/tests/test-string-output-visitor.c b/tests/test-string-output-= visitor.c index 1be1540767..3bd732222c 100644 --- a/tests/test-string-output-visitor.c +++ b/tests/test-string-output-visitor.c @@ -203,19 +203,6 @@ static void test_visitor_out_enum(TestOutputVisitorDat= a *data, } } =20 -static void test_visitor_out_enum_errors(TestOutputVisitorData *data, - const void *unused) -{ - EnumOne i, bad_values[] =3D { ENUM_ONE__MAX, -1 }; - - for (i =3D 0; i < ARRAY_SIZE(bad_values) ; i++) { - Error *err =3D NULL; - - visit_type_EnumOne(data->ov, "unused", &bad_values[i], &err); - error_free_or_abort(&err); - } -} - static void output_visitor_test_add(const char *testpath, TestOutputVisitorData *data, @@ -260,12 +247,6 @@ int main(int argc, char **argv) &out_visitor_data, test_visitor_out_enum, fals= e); output_visitor_test_add("/string-visitor/output/enum-human", &out_visitor_data, test_visitor_out_enum, true= ); - output_visitor_test_add("/string-visitor/output/enum-errors", - &out_visitor_data, test_visitor_out_enum_error= s, - false); - output_visitor_test_add("/string-visitor/output/enum-errors-human", - &out_visitor_data, test_visitor_out_enum_error= s, - true); output_visitor_test_add("/string-visitor/output/intList", &out_visitor_data, test_visitor_out_intList, f= alse); output_visitor_test_add("/string-visitor/output/intList-human", --=20 2.21.1 From nobody Sun Feb 8 22:52:02 2026 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=1587718025; cv=none; d=zohomail.com; s=zohoarc; b=nQ++0uSOmv/RYA4fm7EXafVJSr+NWE/sFwLV7arN5oyNijHhlmxBEUYuCQWoYEdeVl8mTegZeWbFdNZIcYW21OM000mOF/Q14U50nEhbgCr4A6pXEaDzbBR7LCTbPDDbHst0SAnl2WtZ8nAMoinJjeePrOBWIfKLUhqUGL7bwCM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587718025; 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=hr3YG+KjfcK59fxwDqq0zT0dktaKoHpEMtoEYHOt+0s=; b=AuoBVNhjVJxrip887sAalBXAd67SG+un9gNH+3+x0fA7isnCt/iyxRlhCxW9UTk/041Lcf5e/0rZ00JC4MHnYPxtnpzqjkFoty1j9ZoG7WANrUF2VzDiNCnH5ehusiUEVTWzZwnMp8iKqzzWFNWefEAyRrperrt92juF8UKcitc= 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 1587718025640726.7750365615836; Fri, 24 Apr 2020 01:47:05 -0700 (PDT) Received: from localhost ([::1]:55052 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRtzE-0002m4-9V for importer@patchew.org; Fri, 24 Apr 2020 04:47:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36786) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRtw5-0005jY-Bz for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRtw3-0002Eq-Id for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:49 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:35073 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jRtw2-00026b-2E for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:47 -0400 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-138-FdfTyFVsNqmFUhW4UCogHQ-1; Fri, 24 Apr 2020 04:43:43 -0400 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 2841F107ACCD; Fri, 24 Apr 2020 08:43:42 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-113-6.ams2.redhat.com [10.36.113.6]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EAB5699CD; Fri, 24 Apr 2020 08:43:41 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id EC4CD11358C5; Fri, 24 Apr 2020 10:43:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587717824; 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=hr3YG+KjfcK59fxwDqq0zT0dktaKoHpEMtoEYHOt+0s=; b=Qy/i23R02kHsHiF8ujRbj9iAAX086ZTHpWMnV3sYuHRu+SCqnGv+2pdXLMvN0GMZSw1XV8 xdCnmTRCnOILHQb2F50/fwM3F7prkzxF9LYxVJr2MRjGTBA8RTgYmUPvYRVr6hSDnCUxMI m73+UWWHvLh0tRVI0pp1D7CnFjgjykw= X-MC-Unique: FdfTyFVsNqmFUhW4UCogHQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 09/15] qapi: Assert non-input visitors see only valid narrow integers Date: Fri, 24 Apr 2020 10:43:32 +0200 Message-Id: <20200424084338.26803-10-armbru@redhat.com> In-Reply-To: <20200424084338.26803-1-armbru@redhat.com> References: <20200424084338.26803-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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=205.139.110.120; envelope-from=armbru@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/24 03:54:07 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 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: mdroth@linux.vnet.ibm.com 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" visit_type_intN() and visit_type_uintN() fail when the value is out of bounds. This is appropriate with an input visitor: the value comes from input, and input may be bad. It should never happen with the other visitors: the value comes from the caller, and callers must keep it within bounds. Assert that. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- qapi/qapi-visit-core.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c index 80ca83bcb9..74aa9c04bd 100644 --- a/qapi/qapi-visit-core.c +++ b/qapi/qapi-visit-core.c @@ -160,10 +160,13 @@ static void visit_type_uintN(Visitor *v, uint64_t *ob= j, const char *name, Error *err =3D NULL; uint64_t value =3D *obj; =20 + assert(v->type =3D=3D VISITOR_INPUT || value <=3D max); + v->type_uint64(v, name, &value, &err); if (err) { error_propagate(errp, err); } else if (value > max) { + assert(v->type =3D=3D VISITOR_INPUT); error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null", type); } else { @@ -219,10 +222,13 @@ static void visit_type_intN(Visitor *v, int64_t *obj,= const char *name, Error *err =3D NULL; int64_t value =3D *obj; =20 + assert(v->type =3D=3D VISITOR_INPUT || (value >=3D min && value <=3D m= ax)); + v->type_int64(v, name, &value, &err); if (err) { error_propagate(errp, err); } else if (value < min || value > max) { + assert(v->type =3D=3D VISITOR_INPUT); error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null", type); } else { --=20 2.21.1 From nobody Sun Feb 8 22:52:02 2026 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=1587718346; cv=none; d=zohomail.com; s=zohoarc; b=KmzwU4K4nnz2AvNy9jC9fj4ImQzyw2VM6C6tiSp9nfAGWB9Pwj1GIvoEOilpcB8ld9ZQThSED0drKSwicgLCqgnzx9j73wcLJpV5VrecN6n+Q7wQPzPIHAOQD6XAT9goQQVMl/vKWJ2l84zC+9P+8++smwDz1w3+1i8msuhsPOw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587718346; 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=+1AD7bP464ByRBM+IDNKx3lChiOeJt9PaiOdLk6OQ/U=; b=W7iUf8qoRuR3nXfIVKmVybKxRzB6wMRC3eQbwMHf0kXDljlDSy7wCuJjnqN2CQY4CubFb0u3k5YUYF2K5vZOQiuZCb+Z11ucLm9qGoCBevxT9ctxmK/Y/tCZGrG0qT6apq3b+JUaNXLCoaG89ARc7S762QtRmf879Hqul0V1lHE= 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 1587718346295432.6188194314342; Fri, 24 Apr 2020 01:52:26 -0700 (PDT) Received: from localhost ([::1]:55466 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRu4O-0002zX-Sg for importer@patchew.org; Fri, 24 Apr 2020 04:52:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36738) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRtw3-0005gj-Vj for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRtw2-0002C2-GG for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:47 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:45107 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jRtw1-000276-T7 for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:46 -0400 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-93-pIYVoZJUMSOgZlxilznAvA-1; Fri, 24 Apr 2020 04:43:43 -0400 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 2A35B800D24; Fri, 24 Apr 2020 08:43:42 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-113-6.ams2.redhat.com [10.36.113.6]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ECCEB5D9CC; Fri, 24 Apr 2020 08:43:41 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id EF53B11358C6; Fri, 24 Apr 2020 10:43:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587717825; 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=+1AD7bP464ByRBM+IDNKx3lChiOeJt9PaiOdLk6OQ/U=; b=T2VME+cwttYX0bEltYjiE3cU1M0kclyTfTHOhXcTsJQaghDUwz76B/dVdY6TA4CGjdAfVH Pzv+0a52bBWWRQuROB8/i3sz8fD///35IOVEtH8ZHh2/7Mxe6BGNH4/s+ddufve8FlA3TT 5HD9023/LCokWHuCHZLB5dvvl0ajGtM= X-MC-Unique: pIYVoZJUMSOgZlxilznAvA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 10/15] qapi: Clean up visitor's recovery from input with invalid type Date: Fri, 24 Apr 2020 10:43:33 +0200 Message-Id: <20200424084338.26803-11-armbru@redhat.com> In-Reply-To: <20200424084338.26803-1-armbru@redhat.com> References: <20200424084338.26803-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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=207.211.31.81; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/24 03:11:53 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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: mdroth@linux.vnet.ibm.com 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" An alternate type's visit_type_FOO() fails when it runs into an invalid ->type. If it's an input visit, we then need to free the the object we got from visit_start_alternate(). We do that with qapi_free_FOO(), which uses the dealloc visitor. Trouble is that object is in a bad state: its ->type is invalid. So the dealloc visitor will run into the same error again, and the error recovery skips deallocating the alternate's (invalid) alternative. Works, because qapi_free_FOO() ignores the error. Avoid it instead: free the messed up object with by g_free(). Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- scripts/qapi/visit.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index e3467b770b..678109dfb5 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -234,6 +234,9 @@ void visit_type_%(c_name)s(Visitor *v, const char *name= , %(c_name)s **obj, Error default: error_setg(&err, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", "%(name)s"); + /* Avoid passing invalid *obj to qapi_free_%(c_name)s() */ + g_free(*obj); + *obj =3D NULL; } out_obj: visit_end_alternate(v, (void **)obj); --=20 2.21.1 From nobody Sun Feb 8 22:52:02 2026 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=1587718446; cv=none; d=zohomail.com; s=zohoarc; b=D+KaFdIdMyp0GY5Z107rNyrsozYyMTDuqhOqbC5M40STrIQUQKaeEzbFqTFfsYyjTfCxfX7oGgpL6v1L/5YDY9JyknYcmWr3qJxIULcfHRJoQiao7ufuAOhY5i976mayhsQU33VpaCei1IeQqu77Qx7zDbUAxs4W55dR6bc1WiQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587718446; 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=RFbWMeYh5axJy08tl7Z/bC/83o9qMilX16dPJVSkuYM=; b=bQgDbtc7xLMf3oiDCArjjA3u1/Is28GZeAWj3QS48V44pYx7fNTP3E8/+6fWFDgxH8hginoEyzwAMYunnZBRS1xs0qG5NvINxXmFQABlbKSCBXPng2X3Y62ztJyU0nfUgP+hsqg6Fu5OxWSQLek1yHOnltwDqQQHQUaobKTOmwk= 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 1587718446534983.5356877308162; Fri, 24 Apr 2020 01:54:06 -0700 (PDT) Received: from localhost ([::1]:55562 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRu61-00055U-4o for importer@patchew.org; Fri, 24 Apr 2020 04:54:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36760) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRtw4-0005hz-Jd for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRtw2-0002CH-Hg for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:48 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:42178 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jRtw1-00026Z-W9 for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:46 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-192-Gigd53FkP9ubrVRvARBKQg-1; Fri, 24 Apr 2020 04:43:43 -0400 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 2B7AD80B709; Fri, 24 Apr 2020 08:43:42 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-113-6.ams2.redhat.com [10.36.113.6]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F000110016EB; Fri, 24 Apr 2020 08:43:41 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id F28DF11358C7; Fri, 24 Apr 2020 10:43:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587717824; 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=RFbWMeYh5axJy08tl7Z/bC/83o9qMilX16dPJVSkuYM=; b=feyoAaA+sVK4gkQce1AQlWEfe1WIMKvjFZ9gyqfySxd/hYhgN9MnRYd0F2fyEtGgA3OHTZ 8Bt3nHr6ab5byOpJk8UChexSbkdwKOmoTMNewV86Q6DFwvdfkaKW6QFIqc+7PD1HspafXX zuz5gr5UZr8x8so/l+dbAUOicApHXL0= X-MC-Unique: Gigd53FkP9ubrVRvARBKQg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 11/15] qapi: Assert non-input visitors see only valid alternate tags Date: Fri, 24 Apr 2020 10:43:34 +0200 Message-Id: <20200424084338.26803-12-armbru@redhat.com> In-Reply-To: <20200424084338.26803-1-armbru@redhat.com> References: <20200424084338.26803-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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=205.139.110.61; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/24 02:57:59 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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: mdroth@linux.vnet.ibm.com 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" An alternate type's visit_type_FOO() fails when it runs into an invalid ->type. This is appropriate with an input visitor: visit_start_alternate() sets ->type according to the input, and bad input can lead to bad ->type. It should never happen with an output, clone or dealloc visitor: if it did, the alternate being output, cloned or deallocated would be messed up beyond repair. Assert that. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- scripts/qapi/visit.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 678109dfb5..d5d7a1031f 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -232,6 +232,7 @@ void visit_type_%(c_name)s(Visitor *v, const char *name= , %(c_name)s **obj, Error case QTYPE_NONE: abort(); default: + assert(visit_is_input(v)); error_setg(&err, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", "%(name)s"); /* Avoid passing invalid *obj to qapi_free_%(c_name)s() */ --=20 2.21.1 From nobody Sun Feb 8 22:52:02 2026 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=1587718346; cv=none; d=zohomail.com; s=zohoarc; b=h7tcb6k2aBPClWGsHiBXWahWZSrX3muCemyAYW+q0lsezdnEKQZedc3/QGFxVG6xnvbKHEA27YCTUoSNpi7iQkniV2GEvPV/qs5aPaAvLD04zMR4LjdFpLAdFCnGbn1fg/0NnyV3CPTzgKXqSE535DOIvHy1WCgTP+ThU0RV59g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587718346; 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=FepFtRVYArHipsl5aZWkuTrzdKgIF+H2eKxfXugPTrw=; b=aPk1OI30oXGvmWnNVMVI/XtrrS3khPKeevW3yj45cPFNtk0PhMPiv2hUnH6QI10r0Hs8C3OspTnBXGSfWzhdJD4hwfad9wb8gehX1+b/pAzUJxoruLFF7VtOHUdsS9WD6Y9qeMwJvQnHYBH3Udlho1OXPdO7qfnKnKT/VxLKrsI= 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 1587718346185466.16393879934753; Fri, 24 Apr 2020 01:52:26 -0700 (PDT) Received: from localhost ([::1]:55464 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRu4N-0002yj-Gt for importer@patchew.org; Fri, 24 Apr 2020 04:52:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36812) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRtw6-0005lv-DH for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRtw3-0002F9-KD for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:50 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:29209 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jRtw2-00028E-3O for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:47 -0400 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-182-tIasAzhNMrCyQ3nsfsi3GA-1; Fri, 24 Apr 2020 04:43:43 -0400 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 592EE463; Fri, 24 Apr 2020 08:43:42 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-113-6.ams2.redhat.com [10.36.113.6]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 001375C1D2; Fri, 24 Apr 2020 08:43:41 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 01ACC11358C8; Fri, 24 Apr 2020 10:43:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587717825; 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=FepFtRVYArHipsl5aZWkuTrzdKgIF+H2eKxfXugPTrw=; b=HGEr6/ItuvVEZs6xf5EXzwLsT46nuKKCX/JJuNoSH5IOcEY5pEUQMDX/1oybpJAjWH61M+ Klnz5fHbt3c1ghnwwKXK4OM24rIJrO1NqPV3E6lqFQyAuDyRSTI5KfVaah2FAEHR7ikxcV ZrypQP87SZumwpyYWy9rbDEvA+bQ6v4= X-MC-Unique: tIasAzhNMrCyQ3nsfsi3GA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 12/15] qapi: Only input visitors can actually fail Date: Fri, 24 Apr 2020 10:43:35 +0200 Message-Id: <20200424084338.26803-13-armbru@redhat.com> In-Reply-To: <20200424084338.26803-1-armbru@redhat.com> References: <20200424084338.26803-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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=205.139.110.120; envelope-from=armbru@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/24 03:54:07 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 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: mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The previous few commits have made this more obvious, and removed the one exception. Time to clarify the documentation, and drop dead error checking. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- include/qapi/visitor-impl.h | 4 ++++ include/qapi/visitor.h | 40 ++++++++++++++++++++++--------------- block.c | 9 +-------- block/sheepdog.c | 9 +-------- blockdev.c | 16 ++------------- hw/core/machine-hmp-cmds.c | 2 +- monitor/hmp-cmds.c | 3 ++- 7 files changed, 35 insertions(+), 48 deletions(-) diff --git a/include/qapi/visitor-impl.h b/include/qapi/visitor-impl.h index 252206dc0d..98dc533d39 100644 --- a/include/qapi/visitor-impl.h +++ b/include/qapi/visitor-impl.h @@ -43,6 +43,10 @@ typedef enum VisitorType { =20 struct Visitor { + /* + * Only input visitors may fail! + */ + /* Must be set to visit structs */ void (*start_struct)(Visitor *v, const char *name, void **obj, size_t size, Error **errp); diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h index 2d40d2fe0f..5573906966 100644 --- a/include/qapi/visitor.h +++ b/include/qapi/visitor.h @@ -82,7 +82,7 @@ * Each function also takes the customary @errp argument (see * qapi/error.h for details), for reporting any errors (such as if a * member @name is not present, or is present but not the specified - * type). + * type). Only input visitors can fail. * * If an error is detected during visit_type_FOO() with an input * visitor, then *@obj will be set to NULL for pointer types, and left @@ -164,19 +164,14 @@ * * * Foo *f =3D ...obtain populated object... - * Error *err =3D NULL; * Visitor *v; * Type *result; * * v =3D FOO_visitor_new(..., &result); - * visit_type_Foo(v, NULL, &f, &err); - * if (err) { - * ...handle error... - * } else { - * visit_complete(v, &result); - * ...use result... - * } + * visit_type_Foo(v, NULL, &f, &error_abort); + * visit_complete(v, &result); * visit_free(v); + * ...use result... * * * It is also possible to use the visitors to do a virtual walk, where @@ -289,6 +284,7 @@ void visit_free(Visitor *v); * case @size is ignored. * * On failure, set *@obj to NULL and store an error through @errp. + * Can happen only when @v is an input visitor. * * After visit_start_struct() succeeds, the caller may visit its * members one after the other, passing the member's name and address @@ -305,7 +301,8 @@ void visit_start_struct(Visitor *v, const char *name, v= oid **obj, /* * Prepare for completing an object visit. * - * On failure, store an error through @errp. + * On failure, store an error through @errp. Can happen only when @v + * is an input visitor. * * Should be called prior to visit_end_struct() if all other * intermediate visit steps were successful, to allow the visitor one @@ -342,6 +339,7 @@ void visit_end_struct(Visitor *v, void **obj); * ignored. * * On failure, set *@list to NULL and store an error through @errp. + * Can happen only when @v is an input visitor. * * After visit_start_list() succeeds, the caller may visit its members * one after the other. A real visit (where @list is non-NULL) uses @@ -375,7 +373,8 @@ GenericList *visit_next_list(Visitor *v, GenericList *t= ail, size_t size); /* * Prepare for completing a list visit. * - * On failure, store an error through @errp. + * On failure, store an error through @errp. Can happen only when @v + * is an input visitor. * * Should be called prior to visit_end_list() if all other * intermediate visit steps were successful, to allow the visitor one @@ -411,6 +410,7 @@ void visit_end_list(Visitor *v, void **list); * (*@obj)->type. Other visitors leave @obj unchanged. * * On failure, set *@obj to NULL and store an error through @errp. + * Can happen only when @v is an input visitor. * * If successful, this must be paired with visit_end_alternate() with * the same @obj to clean up, even if visiting the contents of the @@ -465,11 +465,13 @@ bool visit_optional(Visitor *v, const char *name, boo= l *present); * visitors produce text output. The mapping between enumeration * values and strings is done by the visitor core, using @lookup. * - * On failure, store an error through @errp. + * On failure, store an error through @errp. Can happen only when @v + * is an input visitor. * * May call visit_type_str() under the hood, and the enum visit may * fail even if the corresponding string visit succeeded; this implies - * that visit_type_str() must have no unwelcome side effects. + * that an input visitor's visit_type_str() must have no unwelcome + * side effects. */ void visit_type_enum(Visitor *v, const char *name, int *obj, const QEnumLookup *lookup, Error **errp); @@ -495,7 +497,8 @@ bool visit_is_dealloc(Visitor *v); * @obj must be non-NULL. Input visitors set *@obj to the value; * other visitors will leave *@obj unchanged. * - * On failure, store an error through @errp. + * On failure, store an error through @errp. Can happen only when @v + * is an input visitor. */ void visit_type_int(Visitor *v, const char *name, int64_t *obj, Error **er= rp); =20 @@ -573,7 +576,8 @@ void visit_type_size(Visitor *v, const char *name, uint= 64_t *obj, * @obj must be non-NULL. Input visitors set *@obj to the value; * other visitors will leave *@obj unchanged. * - * On failure, store an error through @errp. + * On failure, store an error through @errp. Can happen only when @v + * is an input visitor. */ void visit_type_bool(Visitor *v, const char *name, bool *obj, Error **errp= ); =20 @@ -592,6 +596,7 @@ void visit_type_bool(Visitor *v, const char *name, bool= *obj, Error **errp); * into @obj for use by an output visitor. * * On failure, set *@obj to NULL and store an error through @errp. + * Can happen only when @v is an input visitor. * * FIXME: Callers that try to output NULL *obj should not be allowed. */ @@ -607,7 +612,8 @@ void visit_type_str(Visitor *v, const char *name, char = **obj, Error **errp); * other visitors will leave *@obj unchanged. Visitors should * document if infinity or NaN are not permitted. * - * On failure, store an error through @errp. + * On failure, store an error through @errp. Can happen only when @v + * is an input visitor. */ void visit_type_number(Visitor *v, const char *name, double *obj, Error **errp); @@ -623,6 +629,7 @@ void visit_type_number(Visitor *v, const char *name, do= uble *obj, * for output visitors. * * On failure, set *@obj to NULL and store an error through @errp. + * Can happen only when @v is an input visitor. * * Note that some kinds of input can't express arbitrary QObject. * E.g. the visitor returned by qobject_input_visitor_new_keyval() @@ -640,6 +647,7 @@ void visit_type_any(Visitor *v, const char *name, QObje= ct **obj, Error **errp); * other visitors ignore *@obj. * * On failure, set *@obj to NULL and store an error through @errp. + * Can happen only when @v is an input visitor. */ void visit_type_null(Visitor *v, const char *name, QNull **obj, Error **errp); diff --git a/block.c b/block.c index 2e3905c99e..c11385ae05 100644 --- a/block.c +++ b/block.c @@ -2982,7 +2982,6 @@ BdrvChild *bdrv_open_child(const char *filename, BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp) { BlockDriverState *bs =3D NULL; - Error *local_err =3D NULL; QObject *obj =3D NULL; QDict *qdict =3D NULL; const char *reference =3D NULL; @@ -2995,11 +2994,7 @@ BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef= *ref, Error **errp) assert(ref->type =3D=3D QTYPE_QDICT); =20 v =3D qobject_output_visitor_new(&obj); - visit_type_BlockdevOptions(v, NULL, &options, &local_err); - if (local_err) { - error_propagate(errp, local_err); - goto fail; - } + visit_type_BlockdevOptions(v, NULL, &options, &error_abort); visit_complete(v, &obj); =20 qdict =3D qobject_to(QDict, obj); @@ -3017,8 +3012,6 @@ BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef = *ref, Error **errp) =20 bs =3D bdrv_open_inherit(NULL, reference, qdict, 0, NULL, NULL, errp); obj =3D NULL; - -fail: qobject_unref(obj); visit_free(v); return bs; diff --git a/block/sheepdog.c b/block/sheepdog.c index 59f7ebb171..5f3aead038 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -1854,19 +1854,12 @@ static int sd_create_prealloc(BlockdevOptionsSheepd= og *location, int64_t size, Visitor *v; QObject *obj =3D NULL; QDict *qdict; - Error *local_err =3D NULL; int ret; =20 v =3D qobject_output_visitor_new(&obj); - visit_type_BlockdevOptionsSheepdog(v, NULL, &location, &local_err); + visit_type_BlockdevOptionsSheepdog(v, NULL, &location, &error_abort); visit_free(v); =20 - if (local_err) { - error_propagate(errp, local_err); - qobject_unref(obj); - return -EINVAL; - } - qdict =3D qobject_to(QDict, obj); qdict_flatten(qdict); =20 diff --git a/blockdev.c b/blockdev.c index 5faddaa705..9da960b1e7 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3725,14 +3725,8 @@ void qmp_blockdev_add(BlockdevOptions *options, Erro= r **errp) QObject *obj; Visitor *v =3D qobject_output_visitor_new(&obj); QDict *qdict; - Error *local_err =3D NULL; - - visit_type_BlockdevOptions(v, NULL, &options, &local_err); - if (local_err) { - error_propagate(errp, local_err); - goto fail; - } =20 + visit_type_BlockdevOptions(v, NULL, &options, &error_abort); visit_complete(v, &obj); qdict =3D qobject_to(QDict, obj); =20 @@ -3760,7 +3754,6 @@ void qmp_x_blockdev_reopen(BlockdevOptions *options, = Error **errp) AioContext *ctx; QObject *obj; Visitor *v =3D qobject_output_visitor_new(&obj); - Error *local_err =3D NULL; BlockReopenQueue *queue; QDict *qdict; =20 @@ -3777,12 +3770,7 @@ void qmp_x_blockdev_reopen(BlockdevOptions *options,= Error **errp) } =20 /* Put all options in a QDict and flatten it */ - visit_type_BlockdevOptions(v, NULL, &options, &local_err); - if (local_err) { - error_propagate(errp, local_err); - goto fail; - } - + visit_type_BlockdevOptions(v, NULL, &options, &error_abort); visit_complete(v, &obj); qdict =3D qobject_to(QDict, obj); =20 diff --git a/hw/core/machine-hmp-cmds.c b/hw/core/machine-hmp-cmds.c index b76f7223af..39999c47c5 100644 --- a/hw/core/machine-hmp-cmds.c +++ b/hw/core/machine-hmp-cmds.c @@ -113,7 +113,7 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict) =20 while (m) { v =3D string_output_visitor_new(false, &str); - visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL); + visit_type_uint16List(v, NULL, &m->value->host_nodes, &error_abort= ); monitor_printf(mon, "memory backend: %s\n", m->value->id); monitor_printf(mon, " size: %" PRId64 "\n", m->value->size); monitor_printf(mon, " merge: %s\n", diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 9b94e67879..7f6e982dc8 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -334,7 +334,8 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict) Visitor *v; char *str; v =3D string_output_visitor_new(false, &str); - visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime, NUL= L); + visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime, + &error_abort); visit_complete(v, &str); monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str); g_free(str); --=20 2.21.1 From nobody Sun Feb 8 22:52:02 2026 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=1587717915; cv=none; d=zohomail.com; s=zohoarc; b=f7VeIeGo5KI/cNZSBMXO0/8lF0pvin741suVaHi0NtmEbiN+RGdwXZaVthCciYxH5rCjSxi26Qtunf6SN9nWL9ycbvRe85ffwom92PtOIdkfNzrnEnNH89mECHwbzkT78WpXWA/ciZ8KVg5vmtGzeoy5sqeWLMLK14w83vOf4Is= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587717915; 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=dlIFOtfhVbhNxqOwZVLcK02Url4cj+xwTmU++3lC+So=; b=cf4uvJ5nMML0ap/+eMWqDVVcsf/5SU7v0ySDXKUbXtREQ7kBKc2sk2RO8ocm9v0LAmdOD6bbcnkTKx4XaWDVHH4qL+GI5ABHievrFhnRkqC6CddcrM6wGXnnnFuaNcbcesWaV4oxxr2mIBh/itmOQiHB+uIP7AEjLE7osXH+qww= 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 1587717915384709.768227993797; Fri, 24 Apr 2020 01:45:15 -0700 (PDT) Received: from localhost ([::1]:54880 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRtxR-0007W8-Df for importer@patchew.org; Fri, 24 Apr 2020 04:45:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36768) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRtw4-0005iY-TO for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRtw3-0002D1-5M for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:48 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:53563 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jRtw2-00028c-Nl for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:46 -0400 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-167-QHp4NYsvOYiy3-RJe8Oc0g-1; Fri, 24 Apr 2020 04:43:43 -0400 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 4904380B70B; Fri, 24 Apr 2020 08:43:42 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-113-6.ams2.redhat.com [10.36.113.6]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1827599CF; Fri, 24 Apr 2020 08:43:42 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 04D2111358CA; Fri, 24 Apr 2020 10:43:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587717825; 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=dlIFOtfhVbhNxqOwZVLcK02Url4cj+xwTmU++3lC+So=; b=eFeM0FZ8ceWEzeePDpqB9oVQEsg+xFIzOr/raSc3p5eoHzZLnQhIHki4Sgly/xyIi2ETdu mKZjv470DD92jq+TP4kc9hstPXGOprxl1tN+LbIBB3NXAOpusvEyItHWGhWwCkdc4z9FRJ bZA5op4NRV7jHIvjDueq7v8ocD+YCPw= X-MC-Unique: QHp4NYsvOYiy3-RJe8Oc0g-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 13/15] qom: Simplify object_property_get_enum() Date: Fri, 24 Apr 2020 10:43:36 +0200 Message-Id: <20200424084338.26803-14-armbru@redhat.com> In-Reply-To: <20200424084338.26803-1-armbru@redhat.com> References: <20200424084338.26803-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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=207.211.31.81; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/24 03:11:53 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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: mdroth@linux.vnet.ibm.com 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" Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- qom/object.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/qom/object.c b/qom/object.c index 1812f79224..be700e831f 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1550,11 +1550,9 @@ int object_property_get_enum(Object *obj, const char= *name, } visit_complete(v, &str); visit_free(v); - v =3D string_input_visitor_new(str); - visit_type_enum(v, name, &ret, enumprop->lookup, errp); =20 + ret =3D qapi_enum_parse(enumprop->lookup, str, -1, errp); g_free(str); - visit_free(v); =20 return ret; } --=20 2.21.1 From nobody Sun Feb 8 22:52:02 2026 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=1587718020; cv=none; d=zohomail.com; s=zohoarc; b=ZRonmD2sPfPOuMki1D0Bv6vvabnxWdvhRMPGqJ+pAuV+XLMeh5e5DJlhUv5ExHC4BJqjt9c0ZKEFG9oNxLadNXEzqToPnE1A5ON9//JTL9Z0A7GkGfO9N2vocrZG1jThqQhIt2sTGu+aWSB4Jq7PluVzIX3BoMoOdHr8BCWBI6Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587718020; 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=7BqaGAKuD0af63A1Fb4ex1OM+gdx0nvrdX9IZS1/a24=; b=GZcmNmB8q+ZH8DfWwcUDqlTxvXNNLZZK/9fPYY4Qh/tf/6EDOgzBle+eiU4xsvstDlnYKquhvmQag/tsctZ3kTdJ0kd+CkxWlmjcjLDIh7vclvkUChnPHvxro0pyjfSIa0KNcIGNEdWiuOE/UteH38491nmrQOS2Lz0GKd1OeHE= 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 1587718020171259.3079191990174; Fri, 24 Apr 2020 01:47:00 -0700 (PDT) Received: from localhost ([::1]:55044 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRtz7-0002YR-CI for importer@patchew.org; Fri, 24 Apr 2020 04:46:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36828) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRtw6-0005nE-Uv for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRtw2-0002BI-9M for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:50 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:28111 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jRtw1-00026S-Kp for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:45 -0400 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-194-rtscwCKTMB69GSLVxGVr-Q-1; Fri, 24 Apr 2020 04:43:43 -0400 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 54A5A100A61F; Fri, 24 Apr 2020 08:43:42 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-113-6.ams2.redhat.com [10.36.113.6]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 23D8A1002388; Fri, 24 Apr 2020 08:43:42 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 07EC811358CB; Fri, 24 Apr 2020 10:43:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587717824; 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=7BqaGAKuD0af63A1Fb4ex1OM+gdx0nvrdX9IZS1/a24=; b=V9eSQwZtureHUzP/luHGtTCp84qjSbgKxfcKOC/QGaxqjinHQglVXxGIiGYme3+tFUIrgk +144qNjaOiD3MoSYjZ1xx6yhlzkby5EsRzTNQqPinnO7comsn4wP5PwBrx+5P2Y11WTewo Ow3gwXtEVNyQf9C1MHoz88qnc/oZtTI= X-MC-Unique: rtscwCKTMB69GSLVxGVr-Q-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 14/15] qapi: Disallow qmp_marshal_FOO(NULL, ...) Date: Fri, 24 Apr 2020 10:43:37 +0200 Message-Id: <20200424084338.26803-15-armbru@redhat.com> In-Reply-To: <20200424084338.26803-1-armbru@redhat.com> References: <20200424084338.26803-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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=205.139.110.61; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/24 02:57:59 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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: mdroth@linux.vnet.ibm.com 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" For QMP commands without arguments, gen_marshal() laboriously generates a qmp_marshal_FOO() that copes with null @args. Turns there's just one caller that passes null instead of an empty QDict. Adjust that caller, and simplify gen_marshal(). Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- docs/devel/qapi-code-gen.txt | 2 +- monitor/qmp.c | 5 ++++- scripts/qapi/commands.py | 26 ++------------------------ 3 files changed, 7 insertions(+), 26 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index c6dd1891c3..a7794ef658 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -1579,8 +1579,8 @@ Example: void qmp_marshal_my_command(QDict *args, QObject **ret, Error **errp) { Error *err =3D NULL; - UserDefOne *retval; Visitor *v; + UserDefOne *retval; q_obj_my_command_arg arg =3D {0}; =20 v =3D qobject_input_visitor_new(QOBJECT(args)); diff --git a/monitor/qmp.c b/monitor/qmp.c index f89e7daf27..d433ceae5b 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -322,9 +322,12 @@ static QDict *qmp_greeting(MonitorQMP *mon) { QList *cap_list =3D qlist_new(); QObject *ver =3D NULL; + QDict *args; QMPCapability cap; =20 - qmp_marshal_query_version(NULL, &ver, NULL); + args =3D qdict_new(); + qmp_marshal_query_version(args, &ver, NULL); + qobject_unref(args); =20 for (cap =3D 0; cap < QMP_CAPABILITY__MAX; cap++) { if (mon->capab_offered[cap]) { diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index bc30876c88..f545903567 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -104,6 +104,7 @@ def gen_marshal(name, arg_type, boxed, ret_type): %(proto)s { Error *err =3D NULL; + Visitor *v; ''', proto=3Dbuild_marshal_proto(name)) =20 @@ -117,21 +118,14 @@ def gen_marshal(name, arg_type, boxed, ret_type): visit_members =3D ('visit_type_%s_members(v, &arg, &err);' % arg_type.c_name()) ret +=3D mcgen(''' - Visitor *v; %(c_name)s arg =3D {0}; - ''', c_name=3Darg_type.c_name()) else: visit_members =3D '' - ret +=3D mcgen(''' - Visitor *v =3D NULL; - - if (args) { -''') - push_indent() =20 ret +=3D mcgen(''' + v =3D qobject_input_visitor_new(QOBJECT(args)); visit_start_struct(v, NULL, NULL, 0, &err); if (err) { @@ -148,12 +142,6 @@ def gen_marshal(name, arg_type, boxed, ret_type): ''', visit_members=3Dvisit_members) =20 - if not have_args: - pop_indent() - ret +=3D mcgen(''' - } -''') - ret +=3D gen_call(name, arg_type, boxed, ret_type) =20 ret +=3D mcgen(''' @@ -168,10 +156,6 @@ out: % arg_type.c_name()) else: visit_members =3D '' - ret +=3D mcgen(''' - if (args) { -''') - push_indent() =20 ret +=3D mcgen(''' v =3D qapi_dealloc_visitor_new(); @@ -182,12 +166,6 @@ out: ''', visit_members=3Dvisit_members) =20 - if not have_args: - pop_indent() - ret +=3D mcgen(''' - } -''') - ret +=3D mcgen(''' } ''') --=20 2.21.1 From nobody Sun Feb 8 22:52:02 2026 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=1587718595; cv=none; d=zohomail.com; s=zohoarc; b=Cs5UmXScRTUpOhVfAoZFSr+jPKq7qPLuqKOhz/LjmnYPWfFLnpjm9I+gE5Myx1HglLTjUu6GcQoq/3yOPV3cYBummHJX3iSsZVPdCqFrzspEwP69iqszWOtf4k72vMDVdKn1r0r8gxuJGzwItnzIdDK8v5I0FpY+uS71Cgxzglo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587718595; 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=+ZGh1VRdSb0WLd0ve8k2eIZ69HGOaNSTJcy03Z6W6YM=; b=QC5NsVrA6ZxCVWNHZZxkfjREvt/fz1T3rL3S8k1qkpoq/Nb8G8pMnN4jK0TEAReDmuEKbsuUZ5tCWi+vwMCY2+D0SK+oDIhvInH8Ke5nSds7Wbob1fUXedWsPpilh3NPdYFvSq/ONCOHocq8Yz7R1EboJwv4ldCd9tHHgIB1OZ4= 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 1587718595894703.0790595698982; Fri, 24 Apr 2020 01:56:35 -0700 (PDT) Received: from localhost ([::1]:55732 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRu8P-0000MT-VD for importer@patchew.org; Fri, 24 Apr 2020 04:56:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36806) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRtw6-0005lC-3l for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRtw3-0002FX-N5 for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:49 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:29048 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jRtw3-0002CV-6y for qemu-devel@nongnu.org; Fri, 24 Apr 2020 04:43:47 -0400 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-474-V38DvYHtNKK42K9lQv_vUw-1; Fri, 24 Apr 2020 04:43:44 -0400 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 98A41107ACF2; Fri, 24 Apr 2020 08:43:43 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-113-6.ams2.redhat.com [10.36.113.6]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 65FC86084A; Fri, 24 Apr 2020 08:43:43 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 0B38C11358CC; Fri, 24 Apr 2020 10:43:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587717826; 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=+ZGh1VRdSb0WLd0ve8k2eIZ69HGOaNSTJcy03Z6W6YM=; b=ZTERLUlJe+ViN/ifJA/lYqz/NogJDxh1dalhl8tx3Jp+O8dejLT7tkxK9a9Rd6B6UbFWWB Xv2pVqveRAxgkIT8KwuABfLfJrXHq41YylGmLFlX7suThwUolN35MQfN2eMt6arNB8kHhe 1UYDLWVxj/9ZZKS3QRAAgZfeH2+M+zU= X-MC-Unique: V38DvYHtNKK42K9lQv_vUw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 15/15] qapi: Generate simpler marshalling code when no arguments Date: Fri, 24 Apr 2020 10:43:38 +0200 Message-Id: <20200424084338.26803-16-armbru@redhat.com> In-Reply-To: <20200424084338.26803-1-armbru@redhat.com> References: <20200424084338.26803-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=205.139.110.61; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/24 02:57:59 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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: mdroth@linux.vnet.ibm.com 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" When command FOO has no arguments, its generated qmp_marshal_FOO() is a bit confusing. Make it simpler: visit_start_struct(v, NULL, NULL, 0, &err); if (err) { goto out; } - - if (!err) { - visit_check_struct(v, &err); - } + visit_check_struct(v, &err); visit_end_struct(v, NULL); if (err) { goto out; } Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- scripts/qapi/commands.py | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index f545903567..6809b0fb6e 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -115,14 +115,10 @@ def gen_marshal(name, arg_type, boxed, ret_type): c_type=3Dret_type.c_type()) =20 if have_args: - visit_members =3D ('visit_type_%s_members(v, &arg, &err);' - % arg_type.c_name()) ret +=3D mcgen(''' %(c_name)s arg =3D {0}; ''', c_name=3Darg_type.c_name()) - else: - visit_members =3D '' =20 ret +=3D mcgen(''' =20 @@ -131,16 +127,27 @@ def gen_marshal(name, arg_type, boxed, ret_type): if (err) { goto out; } - %(visit_members)s +''') + + if have_args: + ret +=3D mcgen(''' + visit_type_%(c_arg_type)s_members(v, &arg, &err); if (!err) { visit_check_struct(v, &err); } +''', + c_arg_type=3Darg_type.c_name()) + else: + ret +=3D mcgen(''' + visit_check_struct(v, &err); +''') + + ret +=3D mcgen(''' visit_end_struct(v, NULL); if (err) { goto out; } -''', - visit_members=3Dvisit_members) +''') =20 ret +=3D gen_call(name, arg_type, boxed, ret_type) =20 @@ -151,20 +158,21 @@ out: visit_free(v); ''') =20 - if have_args: - visit_members =3D ('visit_type_%s_members(v, &arg, NULL);' - % arg_type.c_name()) - else: - visit_members =3D '' - ret +=3D mcgen(''' v =3D qapi_dealloc_visitor_new(); visit_start_struct(v, NULL, NULL, 0, NULL); - %(visit_members)s +''') + + if have_args: + ret +=3D mcgen(''' + visit_type_%(c_arg_type)s_members(v, &arg, NULL); +''', + c_arg_type=3Darg_type.c_name()) + + ret +=3D mcgen(''' visit_end_struct(v, NULL); visit_free(v); -''', - visit_members=3Dvisit_members) +''') =20 ret +=3D mcgen(''' } --=20 2.21.1