[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RESEND PATCH 05/12] golang/xenlight: use struct pointers in keyed union fields
- To: Nick Rosbrook <rosbrookn@xxxxxxxxx>
- From: George Dunlap <George.Dunlap@xxxxxxxxxx>
- Date: Fri, 18 Jun 2021 11:26:55 +0000
- Accept-language: en-US
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yaY5N2tOVkTtdixDR7oGscyi7yL+PzB7ecTsnjFt21I=; b=BXI/zhyqmkDV0JCHAk5MdmeXlEbBjv+Z/u7srrSYzgeDfdWrDEebpa3uC/VdwfXxb+PkOSVYhO8ZbCkBLriMwzu1lfSH7m6NTaMEbIi9sC3lizFgTsVErUVz77WdJfXlXPlZhMGbwrSOiYDRDH9t2qEcCadEIiNpDESW4kI/lHbf4ez6r6fWQk7Udpl/xfRvoOp6osIZlshMLREf7RQhBqOcg4Uy+9nlhS1HGjg0Fs/d92vNnzJFK13tEW7Bjts6ByfLHuXC6MFrBewVpHsR4auYnnNR/Qo8MyZKNWcN793xCc1uXpHlbm9H2xMdH5brBO0wmS19E3WVUmSmH1Dm1g==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ADucqfusRfRNAsB79eXdcKfO/9CNU8UKnfqYZ9EHD88hB/snKj/yl6a6+vdp9LDV6TDrSHoa2jrguYtTEJVbRlyliFEH+rmFQhzy3AGRfQmm7TQ1HaPOKn09278mAL/n4cV6jvg3F7T1EUKiQ0wIT/a2hD8BNEEG2qFRkF39MqDpTrZAlPDgHy/StXausTsXrh1NFKWMAcWJI/1CCpFJhBFUn5K344rFuvkDPnHF3yyWETWWnJsZCdL8/OI/iz8U/Od4d2qLRxGsog+YLVeY8QLijTRdAxwmkPk6/CpBc6zuHLpE0RCnrAb2q7qVZbcyMPCDiBXkArYOadIEqECv+A==
- Authentication-results: esa2.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
- Cc: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Nick Rosbrook <rosbrookn@xxxxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
- Delivery-date: Fri, 18 Jun 2021 11:27:06 +0000
- Ironport-hdrordr: A9a23:WgJQwK/aKpp1xFYluQ9uk+DfI+orL9Y04lQ7vn1ZYhZeG/bo8/ xG/c526faQsl0ssR4b9uxoVJPvfZq/z/5ICPgqXItKNTOO0AHEEGgI1/qA/9SPIVyaysdtkY tmbqhiGJnRIDFB/KHHCdCDYrQd/OU=
- Ironport-sdr: JUa+CK9JZNyUc/NSgVFg7sTc5KfQscgOYni/+vBkJEaPv9dtfwWvFesc07P+h1xjT3XZUoosoV X48277J/7P6mGONd7853k56/Y4YwnI0P8oaKDxovWhUgVgq94DZnDZc5rnInAZljNyuAN+b9aO pekSt9OOj5n6Zu0BnahSClRLgjYXwaOnwODAFpdhZlGN8ZXUHNcHYYCsMxEwKzmdUIJAg0ERaN zg30yb9M92tbAUxxdhv8jO2eT49eUg0UiwmUYx9iyj7PKy4od/Q3qpNXntnS490wSz2abggtVl MEs=
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
- Thread-index: AQHXUNzFppin6ei2JkOk4VRu7i00GqsZx/WA
- Thread-topic: [RESEND PATCH 05/12] golang/xenlight: use struct pointers in keyed union fields
> On May 24, 2021, at 9:36 PM, Nick Rosbrook <rosbrookn@xxxxxxxxx> wrote:
>
> 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 <rosbrookn@xxxxxxxxxxxx>
Reviewed-by: George Dunlap <george.dunlap@xxxxxxxxxx>
|