From nobody Wed May 1 06:51:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1598919111; cv=none; d=zohomail.com; s=zohoarc; b=fB+uN1rnhahomyKyUgFja1piTQqCji4d/9xQeFO07iOKIs7iUA9BGJi8H77XDVRGMrrbf8He4QenTeElRhVHZiyZVhDLlUk+Dspr7uZ6n2cuWkBjY9DTw5Ox/ftF+7oNqFXsRyHyfJ32tPurS7/MC80Mc5I964KqMO6YoQOTsU8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598919111; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=4NqMQIvKR+cjPWOKjy1YxbxPsO0+lnWPEKbNxZzXwjU=; b=BCKXJcWed0TPnpr18Zn8QWdcVKYmBg/pujQS/QVUWSZUUJL7EEH3kIwLrc7nyuGiCyhH7khIwSA9SE5xuJGhwQ93yuENkCcGjHxvITeJK9FeMhNNBVAinM4YNb7Z09mXbzj32z1c9Hh3FIG0/llMqLeXG/fiSkhnVFTQTLEnLv0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1598919111490258.93223678275126; Mon, 31 Aug 2020 17:11:51 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kCttI-0001sA-GP; Tue, 01 Sep 2020 00:11:12 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kCttH-0001rt-B1 for xen-devel@lists.xenproject.org; Tue, 01 Sep 2020 00:11:11 +0000 Received: from mail-qv1-xf2c.google.com (unknown [2607:f8b0:4864:20::f2c]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 36012594-5be5-4ae7-9f1b-36e5500f7e11; Tue, 01 Sep 2020 00:11:06 +0000 (UTC) Received: by mail-qv1-xf2c.google.com with SMTP id h1so1965691qvo.9 for ; Mon, 31 Aug 2020 17:11:06 -0700 (PDT) Received: from six.home (cpe-67-241-56-252.twcny.res.rr.com. [67.241.56.252]) by smtp.gmail.com with ESMTPSA id d10sm3371675qkk.1.2020.08.31.17.11.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Aug 2020 17:11:05 -0700 (PDT) X-Inumbo-ID: 36012594-5be5-4ae7-9f1b-36e5500f7e11 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=4NqMQIvKR+cjPWOKjy1YxbxPsO0+lnWPEKbNxZzXwjU=; b=jFvnfywmTtiMJU9SOpVcCiJlyCVr+Ri3bPz76Z9vfvCRsP0aVNQwmCJuIIe4n5mJFC Ei9Wmb4xE7QUS4CQnLhKfZvFAmP1FDLpxwYcBzr8kjh6DanQNEoPOUC4d7ZMbDHUtFGo kj1XOMRyNX++1fx4HboUNlmS4gN++4IvTqg8O0EsRFSp0lwIMXdiFtuOB3n9quubUOGP K1GiPbWP2IdMrA0Qi6uo3gDfuhMc6hhJF4uxrsFFnEKiBNpV0dDzE7IJsuW/4QhPZ9xC /TjNmiZHjXx97pwIAvjBELazGbAKd8PaOXxsbTiyKcW83jqM0Ole2KgB4ILiHQMcMXv0 5aYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=4NqMQIvKR+cjPWOKjy1YxbxPsO0+lnWPEKbNxZzXwjU=; b=oPJmKLNdJx1vW822mPY9puUBf7ulKZiPqafCtQAfy8tmg8Hd3S/QiDze/ZWIxS/Yfw xgH2dn36II7BByN4/+6fESoKqgbqFlMZueAz/trDjbdVIKMCQAELkZNYP0yvuokSwIpQ qUCai04b8sEI6ac7U1rJTa6id7tdx0ER0nH6IJR4t4+9szSRRNzmeL2v2KyZwhMXWKik JlnkhRBp9Y5uuI+1PWN5hrSeciDC/b6E1SrIggZjAuvkJQ0NdRj0i07f7STRc/W8qqZk q8PJ53N3n7jJ0rW1ZOuogV+/6Ym6UqJvUA+EeY9RMWSVx7fpNGeqtsDqXeQnH0xYxh4w QgBA== X-Gm-Message-State: AOAM530ezEE9++6QlNo3ZgA+URfHxuGasosTdpdF4/KtFq+WtTlJFujs DYf0iLGez3HE0HNXUi4LnelI54JG+OU2Rg== X-Google-Smtp-Source: ABdhPJy8fb0P45dahxyVr4Rd9ZAJ3OHpBcNNnw19/ETtG6rEJ3qkMfCdecS4x1/+QxwzzTBgO1WCOQ== X-Received: by 2002:ad4:51c8:: with SMTP id p8mr3688380qvq.31.1598919065697; Mon, 31 Aug 2020 17:11:05 -0700 (PDT) From: Nick Rosbrook X-Google-Original-From: Nick Rosbrook To: xen-devel@lists.xenproject.org Cc: Nick Rosbrook , George Dunlap , Ian Jackson , Wei Liu Subject: [PATCH 1/2] golang/xenlight: export keyed union interface types Date: Mon, 31 Aug 2020 20:10:57 -0400 Message-Id: <554916143fa18f389902cca888490d54cbb6b77a.1598918801.git.rosbrookn@ainfosec.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" For structs that have a keyed union, e.g. DomainBuildInfo, the TypeUnion field must be exported so that package users can get/set the fields within. This means that users are aware of the existence of the interface type used in those fields (see [1]), so it is awkward that the interface itself is not exported. However, the single method within the interface must remain unexported so that users cannot mistakenly "implement" those interfaces. Since there seems to be no reason to do otherwise, export the keyed union interface types. [1] https://pkg.go.dev/xenbits.xenproject.org/git-http/xen.git/tools/golang= /xenlight?tab=3Ddoc#DeviceUsbdev Signed-off-by: Nick Rosbrook --- tools/golang/xenlight/gengotypes.py | 6 +-- tools/golang/xenlight/types.gen.go | 58 ++++++++++++++--------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/tools/golang/xenlight/gengotypes.py b/tools/golang/xenlight/ge= ngotypes.py index ebec938224..9acc8c0b49 100644 --- a/tools/golang/xenlight/gengotypes.py +++ b/tools/golang/xenlight/gengotypes.py @@ -152,7 +152,7 @@ def xenlight_golang_define_union(ty =3D None, struct_na= me =3D '', union_name =3D ''): extras =3D [] =20 interface_name =3D '{0}_{1}_union'.format(struct_name, ty.keyvar.name) - interface_name =3D xenlight_golang_fmt_name(interface_name, exported= =3DFalse) + interface_name =3D xenlight_golang_fmt_name(interface_name) =20 s +=3D 'type {0} interface {{\n'.format(interface_name) s +=3D 'is{0}()\n'.format(interface_name) @@ -334,7 +334,7 @@ def xenlight_golang_union_from_C(ty =3D None, union_nam= e =3D '', struct_name =3D ''): field_name =3D xenlight_golang_fmt_name('{0}_union'.format(keyname)) =20 interface_name =3D '{0}_{1}_union'.format(struct_name, keyname) - interface_name =3D xenlight_golang_fmt_name(interface_name, exported= =3DFalse) + interface_name =3D xenlight_golang_fmt_name(interface_name) =20 cgo_keyname =3D keyname if cgo_keyname in go_keywords: @@ -538,7 +538,7 @@ def xenlight_golang_union_to_C(ty =3D None, union_name = =3D '', gokeytype =3D xenlight_golang_fmt_name(keytype) =20 interface_name =3D '{0}_{1}_union'.format(struct_name, keyname) - interface_name =3D xenlight_golang_fmt_name(interface_name, exported= =3DFalse) + interface_name =3D xenlight_golang_fmt_name(interface_name) =20 cgo_keyname =3D keyname if cgo_keyname in go_keywords: diff --git a/tools/golang/xenlight/types.gen.go b/tools/golang/xenlight/typ= es.gen.go index 663c1e86b4..b143e32a9c 100644 --- a/tools/golang/xenlight/types.gen.go +++ b/tools/golang/xenlight/types.gen.go @@ -337,18 +337,18 @@ State int Evtch int Rref int Connection ChannelConnection -ConnectionUnion channelinfoConnectionUnion +ConnectionUnion ChannelinfoConnectionUnion } =20 -type channelinfoConnectionUnion interface { -ischannelinfoConnectionUnion() +type ChannelinfoConnectionUnion interface { +isChannelinfoConnectionUnion() } =20 type ChannelinfoConnectionUnionPty struct { Path string } =20 -func (x ChannelinfoConnectionUnionPty) ischannelinfoConnectionUnion(){} +func (x ChannelinfoConnectionUnionPty) isChannelinfoConnectionUnion(){} =20 type Vminfo struct { Uuid Uuid @@ -510,7 +510,7 @@ Apic Defbool DmRestrict Defbool Tee TeeType Type DomainType -TypeUnion domainBuildInfoTypeUnion +TypeUnion DomainBuildInfoTypeUnion ArchArm struct { GicVersion GicVersion Vuart VuartType @@ -518,8 +518,8 @@ Vuart VuartType Altp2M Altp2MMode } =20 -type domainBuildInfoTypeUnion interface { -isdomainBuildInfoTypeUnion() +type DomainBuildInfoTypeUnion interface { +isDomainBuildInfoTypeUnion() } =20 type DomainBuildInfoTypeUnionHvm struct { @@ -571,7 +571,7 @@ RdmMemBoundaryMemkb uint64 McaCaps uint64 } =20 -func (x DomainBuildInfoTypeUnionHvm) isdomainBuildInfoTypeUnion(){} +func (x DomainBuildInfoTypeUnionHvm) isDomainBuildInfoTypeUnion(){} =20 type DomainBuildInfoTypeUnionPv struct { Kernel string @@ -584,7 +584,7 @@ Features string E820Host Defbool } =20 -func (x DomainBuildInfoTypeUnionPv) isdomainBuildInfoTypeUnion(){} +func (x DomainBuildInfoTypeUnionPv) isDomainBuildInfoTypeUnion(){} =20 type DomainBuildInfoTypeUnionPvh struct { Pvshim Defbool @@ -593,7 +593,7 @@ PvshimCmdline string PvshimExtra string } =20 -func (x DomainBuildInfoTypeUnionPvh) isdomainBuildInfoTypeUnion(){} +func (x DomainBuildInfoTypeUnionPvh) isDomainBuildInfoTypeUnion(){} =20 type DeviceVfb struct { BackendDomid Domid @@ -756,11 +756,11 @@ type DeviceUsbdev struct { Ctrl Devid Port int Type UsbdevType -TypeUnion deviceUsbdevTypeUnion +TypeUnion DeviceUsbdevTypeUnion } =20 -type deviceUsbdevTypeUnion interface { -isdeviceUsbdevTypeUnion() +type DeviceUsbdevTypeUnion interface { +isDeviceUsbdevTypeUnion() } =20 type DeviceUsbdevTypeUnionHostdev struct { @@ -768,7 +768,7 @@ Hostbus byte Hostaddr byte } =20 -func (x DeviceUsbdevTypeUnionHostdev) isdeviceUsbdevTypeUnion(){} +func (x DeviceUsbdevTypeUnionHostdev) isDeviceUsbdevTypeUnion(){} =20 type DeviceDtdev struct { Path string @@ -802,18 +802,18 @@ BackendDomname string Devid Devid Name string Connection ChannelConnection -ConnectionUnion deviceChannelConnectionUnion +ConnectionUnion DeviceChannelConnectionUnion } =20 -type deviceChannelConnectionUnion interface { -isdeviceChannelConnectionUnion() +type DeviceChannelConnectionUnion interface { +isDeviceChannelConnectionUnion() } =20 type DeviceChannelConnectionUnionSocket struct { Path string } =20 -func (x DeviceChannelConnectionUnionSocket) isdeviceChannelConnectionUnion= (){} +func (x DeviceChannelConnectionUnionSocket) isDeviceChannelConnectionUnion= (){} =20 type ConnectorParam struct { UniqueId string @@ -1110,31 +1110,31 @@ Domid Domid Domuuid Uuid ForUser uint64 Type EventType -TypeUnion eventTypeUnion +TypeUnion EventTypeUnion } =20 -type eventTypeUnion interface { -iseventTypeUnion() +type EventTypeUnion interface { +isEventTypeUnion() } =20 type EventTypeUnionDomainShutdown struct { ShutdownReason byte } =20 -func (x EventTypeUnionDomainShutdown) iseventTypeUnion(){} +func (x EventTypeUnionDomainShutdown) isEventTypeUnion(){} =20 type EventTypeUnionDiskEject struct { Vdev string Disk DeviceDisk } =20 -func (x EventTypeUnionDiskEject) iseventTypeUnion(){} +func (x EventTypeUnionDiskEject) isEventTypeUnion(){} =20 type EventTypeUnionOperationComplete struct { Rc int } =20 -func (x EventTypeUnionOperationComplete) iseventTypeUnion(){} +func (x EventTypeUnionOperationComplete) isEventTypeUnion(){} =20 type PsrCmtType int const( @@ -1169,11 +1169,11 @@ PsrFeatTypeMba PsrFeatType =3D 2 type PsrHwInfo struct { Id uint32 Type PsrFeatType -TypeUnion psrHwInfoTypeUnion +TypeUnion PsrHwInfoTypeUnion } =20 -type psrHwInfoTypeUnion interface { -ispsrHwInfoTypeUnion() +type PsrHwInfoTypeUnion interface { +isPsrHwInfoTypeUnion() } =20 type PsrHwInfoTypeUnionCat struct { @@ -1182,7 +1182,7 @@ CbmLen uint32 CdpEnabled bool } =20 -func (x PsrHwInfoTypeUnionCat) ispsrHwInfoTypeUnion(){} +func (x PsrHwInfoTypeUnionCat) isPsrHwInfoTypeUnion(){} =20 type PsrHwInfoTypeUnionMba struct { CosMax uint32 @@ -1190,5 +1190,5 @@ ThrtlMax uint32 Linear bool } =20 -func (x PsrHwInfoTypeUnionMba) ispsrHwInfoTypeUnion(){} +func (x PsrHwInfoTypeUnionMba) isPsrHwInfoTypeUnion(){} =20 --=20 2.17.1 From nobody Wed May 1 06:51:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1598919108; cv=none; d=zohomail.com; s=zohoarc; b=AlBjjGpcn3bp8j9Gtdqt6qqkNs7sHFDK9FOeIxdtrGLgzP4LlvcHY+0BEfmmeNjscszp8cyCqGsIZjQRabS1t79wkDDG5CQ+RObXFfSvVN+JsDTms2duKJssmBs7Qyh2eW6sS8jrj0TVZe6umwD5oFtGVPCXQ+5FVrx5OtUX0QM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598919108; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=5ChwAZPKBJXfRIooObF/mR23x75fGlNBFyiMAw9Jq/8=; b=SzdDo/uWK82e62qCrV2s0iZdaBKibRyhF3Fo5vD7q9eVjBf9vvNM6FhlsuYSr9hMSXJ/IS76kTAJTojUGV46NqXKk8w8911ZQZE+RpOXMDlAd7Q9QfmjiX4NbSmG3RyyuH8fgXSIwDFCPNHouyBRaWUSdKRWWK1mvYVxbg8w+0A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 159891910837492.02768808382825; Mon, 31 Aug 2020 17:11:48 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kCttN-0001sX-PN; Tue, 01 Sep 2020 00:11:17 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kCttM-0001rt-BB for xen-devel@lists.xenproject.org; Tue, 01 Sep 2020 00:11:16 +0000 Received: from mail-qt1-x830.google.com (unknown [2607:f8b0:4864:20::830]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 8e8d1671-645a-4483-aff3-ca16b319ce19; Tue, 01 Sep 2020 00:11:08 +0000 (UTC) Received: by mail-qt1-x830.google.com with SMTP id k18so6147929qtm.10 for ; Mon, 31 Aug 2020 17:11:08 -0700 (PDT) Received: from six.home (cpe-67-241-56-252.twcny.res.rr.com. [67.241.56.252]) by smtp.gmail.com with ESMTPSA id d10sm3371675qkk.1.2020.08.31.17.11.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Aug 2020 17:11:06 -0700 (PDT) X-Inumbo-ID: 8e8d1671-645a-4483-aff3-ca16b319ce19 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=5ChwAZPKBJXfRIooObF/mR23x75fGlNBFyiMAw9Jq/8=; b=mwQrqXOu1DSz3/WiI3xwBvdp6E90F3+aImy0JdN4xrN23XTwtcNMnkf/PJofPG3nRM CLQ5oipb9OgvWbqxsH6yW5ZNyQw5QLf8vmUcH5u6KoU/Us2VWo8bvTYG1nbcfD3EZyHn OpDb8CL+7Y2jWM73S9ytmndJm3NqVvVZfDDmqbYSnk8WSqJU9n4zOsnm7q6sDdHeALZe IMMd4LyaTGBnzUuN5xh+EOXztvDqdwUJHwRXp0i2/LllnKZH7u7thVurgEeHSa44LMxv DqbUw8vLFiSzfvC+SS4cib1f9Mf75b3N1gbEiGUO4yniildP37Ud3Js0GzKBN+o6P5Ox Dq0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=5ChwAZPKBJXfRIooObF/mR23x75fGlNBFyiMAw9Jq/8=; b=ncp2fdVvzh//YrjujOEb7qST/QZonwO2gK5h4bl1F9nTUWxTUS0caChsUtm7OlMvU1 u8vKOqHxzAuJhIZJEAdNK3USmaK1aoFZDw8d88gLkygR8qa/BFLwXmDPHOO8BYMSPQ1j 0aRf2Kh5L6dlVieA6g6ODHOiTgkX4sBKxB0zRsymFgd++wDDMOiWhUPfQ0KLFAvIWoDq 8kHLhR2+xzdXIAWtZoLgD8tFH+U7CHc+dCG4WtqFZ8GX+/203vK2LwMgtpVFXWRt7i9q wsaw+36p7gTU/CXH2wvA7yuotdDxKcIXhegEaWheirz4i2mouj7a01TzGx+j7UE3yPza 2pUw== X-Gm-Message-State: AOAM5335c4kKA/0yvIyPiL6M7BrYPi0KJ6D/WnjlsdqE0LECd45uRsVy QdCrmElgDOCb+2ZwejwL2nw22i1B1A0l6g== X-Google-Smtp-Source: ABdhPJy715YUYk/ht8ekkXDjWBE9mg5R91qYbPlbr31ucbKHNdWjJf2jY7mBATo7Pc82fybnts1luA== X-Received: by 2002:ac8:4548:: with SMTP id z8mr3978566qtn.291.1598919067240; Mon, 31 Aug 2020 17:11:07 -0700 (PDT) From: Nick Rosbrook X-Google-Original-From: Nick Rosbrook To: xen-devel@lists.xenproject.org Cc: Nick Rosbrook , George Dunlap , Ian Jackson , Wei Liu Subject: [PATCH 2/2] golang/xenlight: use struct pointers in keyed union fields Date: Mon, 31 Aug 2020 20:10:58 -0400 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Currently, when marshalig Go types with keyed union fields, we assign the value of the struct (e.g. DomainBuildInfoTypeUnionHvm) which implements the interface of the keyed union field (e.g. DomainBuildInfoTypeUnion). As-is, this means that if a populated DomainBuildInfo is marshaled to e.g. JSON, unmarshaling back to DomainBuildInfo will fail. When the encoding/json is unmarshaling data into a Go type, and encounters a JSON object, it basically can either marshal the data into an empty interface, a map, or a struct. It cannot, however, marshal data into an interface with at least one method defined on it (e.g. DomainBuildInfoTypeUnion). Before this check is done, however, the decoder will check if the Go type is a pointer, and dereference it if so. It will then use the type of this value as the "target" type. This means that if the TypeUnion field is populated with a DomainBuildInfoTypeUnion, the decoder will see a non-empty interface and fail. If the TypeUnion field is populated with a *DomainBuildInfoTypeUnionHvm, it dereferences the pointer and sees a struct instead, allowing decoding to continue normally. Since there does not appear to be a strict need for NOT using pointers in these fields, update code generation to set keyed union fields to pointers of their implementing structs. Signed-off-by: Nick Rosbrook --- tools/golang/xenlight/gengotypes.py | 4 +-- tools/golang/xenlight/helpers.gen.go | 44 ++++++++++++++-------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/tools/golang/xenlight/gengotypes.py b/tools/golang/xenlight/ge= ngotypes.py index 9acc8c0b49..a802c371b6 100644 --- a/tools/golang/xenlight/gengotypes.py +++ b/tools/golang/xenlight/gengotypes.py @@ -397,7 +397,7 @@ def xenlight_golang_union_from_C(ty =3D None, union_nam= e =3D '', struct_name =3D ''): s +=3D 'if err :=3D {0}.fromC(xc);'.format(goname) s +=3D 'err !=3D nil {{\n return fmt.Errorf("converting field {0}:= %v", err)\n}}\n'.format(goname) =20 - s +=3D 'x.{0} =3D {1}\n'.format(field_name, goname) + s +=3D 'x.{0} =3D &{1}\n'.format(field_name, goname) =20 # End switch statement s +=3D 'default:\n' @@ -563,7 +563,7 @@ def xenlight_golang_union_to_C(ty =3D None, union_name = =3D '', gotype =3D xenlight_golang_fmt_name(cgotype) =20 field_name =3D xenlight_golang_fmt_name('{0}_union'.format(keyname= )) - s +=3D 'tmp, ok :=3D x.{0}.({1})\n'.format(field_name,gotype) + s +=3D 'tmp, ok :=3D x.{0}.(*{1})\n'.format(field_name,gotype) s +=3D 'if !ok {\n' s +=3D 'return errors.New("wrong type for union key {0}")\n'.forma= t(keyname) s +=3D '}\n' diff --git a/tools/golang/xenlight/helpers.gen.go b/tools/golang/xenlight/h= elpers.gen.go index 152c7e8e6b..1a7ff89c7c 100644 --- a/tools/golang/xenlight/helpers.gen.go +++ b/tools/golang/xenlight/helpers.gen.go @@ -436,7 +436,7 @@ var connectionPty ChannelinfoConnectionUnionPty if err :=3D connectionPty.fromC(xc);err !=3D nil { return fmt.Errorf("converting field connectionPty: %v", err) } -x.ConnectionUnion =3D connectionPty +x.ConnectionUnion =3D &connectionPty case ChannelConnectionSocket: x.ConnectionUnion =3D nil case ChannelConnectionUnknown: @@ -476,7 +476,7 @@ switch x.Connection{ case ChannelConnectionUnknown: break case ChannelConnectionPty: -tmp, ok :=3D x.ConnectionUnion.(ChannelinfoConnectionUnionPty) +tmp, ok :=3D x.ConnectionUnion.(*ChannelinfoConnectionUnionPty) if !ok { return errors.New("wrong type for union key connection") } @@ -1097,7 +1097,7 @@ var typeHvm DomainBuildInfoTypeUnionHvm if err :=3D typeHvm.fromC(xc);err !=3D nil { return fmt.Errorf("converting field typeHvm: %v", err) } -x.TypeUnion =3D typeHvm +x.TypeUnion =3D &typeHvm case DomainTypeInvalid: x.TypeUnion =3D nil case DomainTypePv: @@ -1105,13 +1105,13 @@ var typePv DomainBuildInfoTypeUnionPv if err :=3D typePv.fromC(xc);err !=3D nil { return fmt.Errorf("converting field typePv: %v", err) } -x.TypeUnion =3D typePv +x.TypeUnion =3D &typePv case DomainTypePvh: var typePvh DomainBuildInfoTypeUnionPvh if err :=3D typePvh.fromC(xc);err !=3D nil { return fmt.Errorf("converting field typePvh: %v", err) } -x.TypeUnion =3D typePvh +x.TypeUnion =3D &typePvh default: return fmt.Errorf("invalid union key '%v'", x.Type)} x.ArchArm.GicVersion =3D GicVersion(xc.arch_arm.gic_version) @@ -1426,7 +1426,7 @@ xc.tee =3D C.libxl_tee_type(x.Tee) xc._type =3D C.libxl_domain_type(x.Type) switch x.Type{ case DomainTypeHvm: -tmp, ok :=3D x.TypeUnion.(DomainBuildInfoTypeUnionHvm) +tmp, ok :=3D x.TypeUnion.(*DomainBuildInfoTypeUnionHvm) if !ok { return errors.New("wrong type for union key type") } @@ -1544,7 +1544,7 @@ hvm.mca_caps =3D C.uint64_t(tmp.McaCaps) hvmBytes :=3D C.GoBytes(unsafe.Pointer(&hvm),C.sizeof_libxl_domain_build_i= nfo_type_union_hvm) copy(xc.u[:],hvmBytes) case DomainTypePv: -tmp, ok :=3D x.TypeUnion.(DomainBuildInfoTypeUnionPv) +tmp, ok :=3D x.TypeUnion.(*DomainBuildInfoTypeUnionPv) if !ok { return errors.New("wrong type for union key type") } @@ -1569,7 +1569,7 @@ return fmt.Errorf("converting field E820Host: %v", er= r) pvBytes :=3D C.GoBytes(unsafe.Pointer(&pv),C.sizeof_libxl_domain_build_inf= o_type_union_pv) copy(xc.u[:],pvBytes) case DomainTypePvh: -tmp, ok :=3D x.TypeUnion.(DomainBuildInfoTypeUnionPvh) +tmp, ok :=3D x.TypeUnion.(*DomainBuildInfoTypeUnionPvh) if !ok { return errors.New("wrong type for union key type") } @@ -2149,7 +2149,7 @@ var typeHostdev DeviceUsbdevTypeUnionHostdev if err :=3D typeHostdev.fromC(xc);err !=3D nil { return fmt.Errorf("converting field typeHostdev: %v", err) } -x.TypeUnion =3D typeHostdev +x.TypeUnion =3D &typeHostdev default: return fmt.Errorf("invalid union key '%v'", x.Type)} =20 @@ -2176,7 +2176,7 @@ xc.port =3D C.int(x.Port) xc._type =3D C.libxl_usbdev_type(x.Type) switch x.Type{ case UsbdevTypeHostdev: -tmp, ok :=3D x.TypeUnion.(DeviceUsbdevTypeUnionHostdev) +tmp, ok :=3D x.TypeUnion.(*DeviceUsbdevTypeUnionHostdev) if !ok { return errors.New("wrong type for union key type") } @@ -2367,7 +2367,7 @@ var connectionSocket DeviceChannelConnectionUnionSock= et if err :=3D connectionSocket.fromC(xc);err !=3D nil { return fmt.Errorf("converting field connectionSocket: %v", err) } -x.ConnectionUnion =3D connectionSocket +x.ConnectionUnion =3D &connectionSocket case ChannelConnectionUnknown: x.ConnectionUnion =3D nil default: @@ -2403,7 +2403,7 @@ break case ChannelConnectionPty: break case ChannelConnectionSocket: -tmp, ok :=3D x.ConnectionUnion.(DeviceChannelConnectionUnionSocket) +tmp, ok :=3D x.ConnectionUnion.(*DeviceChannelConnectionUnionSocket) if !ok { return errors.New("wrong type for union key connection") } @@ -3938,7 +3938,7 @@ var typeDiskEject EventTypeUnionDiskEject if err :=3D typeDiskEject.fromC(xc);err !=3D nil { return fmt.Errorf("converting field typeDiskEject: %v", err) } -x.TypeUnion =3D typeDiskEject +x.TypeUnion =3D &typeDiskEject case EventTypeDomainCreateConsoleAvailable: x.TypeUnion =3D nil case EventTypeDomainDeath: @@ -3948,13 +3948,13 @@ var typeDomainShutdown EventTypeUnionDomainShutdown if err :=3D typeDomainShutdown.fromC(xc);err !=3D nil { return fmt.Errorf("converting field typeDomainShutdown: %v", err) } -x.TypeUnion =3D typeDomainShutdown +x.TypeUnion =3D &typeDomainShutdown case EventTypeOperationComplete: var typeOperationComplete EventTypeUnionOperationComplete if err :=3D typeOperationComplete.fromC(xc);err !=3D nil { return fmt.Errorf("converting field typeOperationComplete: %v", err) } -x.TypeUnion =3D typeOperationComplete +x.TypeUnion =3D &typeOperationComplete default: return fmt.Errorf("invalid union key '%v'", x.Type)} =20 @@ -4009,7 +4009,7 @@ xc.for_user =3D C.uint64_t(x.ForUser) xc._type =3D C.libxl_event_type(x.Type) switch x.Type{ case EventTypeDomainShutdown: -tmp, ok :=3D x.TypeUnion.(EventTypeUnionDomainShutdown) +tmp, ok :=3D x.TypeUnion.(*EventTypeUnionDomainShutdown) if !ok { return errors.New("wrong type for union key type") } @@ -4020,7 +4020,7 @@ copy(xc.u[:],domain_shutdownBytes) case EventTypeDomainDeath: break case EventTypeDiskEject: -tmp, ok :=3D x.TypeUnion.(EventTypeUnionDiskEject) +tmp, ok :=3D x.TypeUnion.(*EventTypeUnionDiskEject) if !ok { return errors.New("wrong type for union key type") } @@ -4033,7 +4033,7 @@ return fmt.Errorf("converting field Disk: %v", err) disk_ejectBytes :=3D C.GoBytes(unsafe.Pointer(&disk_eject),C.sizeof_libxl_= event_type_union_disk_eject) copy(xc.u[:],disk_ejectBytes) case EventTypeOperationComplete: -tmp, ok :=3D x.TypeUnion.(EventTypeUnionOperationComplete) +tmp, ok :=3D x.TypeUnion.(*EventTypeUnionOperationComplete) if !ok { return errors.New("wrong type for union key type") } @@ -4108,13 +4108,13 @@ var typeCat PsrHwInfoTypeUnionCat if err :=3D typeCat.fromC(xc);err !=3D nil { return fmt.Errorf("converting field typeCat: %v", err) } -x.TypeUnion =3D typeCat +x.TypeUnion =3D &typeCat case PsrFeatTypeMba: var typeMba PsrHwInfoTypeUnionMba if err :=3D typeMba.fromC(xc);err !=3D nil { return fmt.Errorf("converting field typeMba: %v", err) } -x.TypeUnion =3D typeMba +x.TypeUnion =3D &typeMba default: return fmt.Errorf("invalid union key '%v'", x.Type)} =20 @@ -4153,7 +4153,7 @@ xc.id =3D C.uint32_t(x.Id) xc._type =3D C.libxl_psr_feat_type(x.Type) switch x.Type{ case PsrFeatTypeCat: -tmp, ok :=3D x.TypeUnion.(PsrHwInfoTypeUnionCat) +tmp, ok :=3D x.TypeUnion.(*PsrHwInfoTypeUnionCat) if !ok { return errors.New("wrong type for union key type") } @@ -4164,7 +4164,7 @@ cat.cdp_enabled =3D C.bool(tmp.CdpEnabled) catBytes :=3D C.GoBytes(unsafe.Pointer(&cat),C.sizeof_libxl_psr_hw_info_ty= pe_union_cat) copy(xc.u[:],catBytes) case PsrFeatTypeMba: -tmp, ok :=3D x.TypeUnion.(PsrHwInfoTypeUnionMba) +tmp, ok :=3D x.TypeUnion.(*PsrHwInfoTypeUnionMba) if !ok { return errors.New("wrong type for union key type") } --=20 2.17.1