From: George Dunlap <george.dunlap@citrix.com>
To: Nicholas Rosbrook <rosbrookn@ainfosec.com>,
"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: "anthony.perard@citrix.com" <anthony.perard@citrix.com>,
Brendan Kerrigan <kerriganb@ainfosec.com>,
"ian.jackson@eu.citrix.com" <ian.jackson@eu.citrix.com>,
Nicolas Belouin <nicolas.belouin@gandi.net>,
"wl@xen.org" <wl@xen.org>
Subject: Re: [Xen-devel] [RFC] Generating Go bindings for libxl
Date: Wed, 4 Sep 2019 17:59:18 +0100 [thread overview]
Message-ID: <dbeeb071-25ae-9652-4be1-e3067109179f@citrix.com> (raw)
In-Reply-To: <871a9191-f32b-383e-4f78-1a0a79737cd8@citrix.com>
On 9/4/19 5:52 PM, George Dunlap wrote:
> On 9/4/19 1:36 AM, Nicholas Rosbrook wrote:
>> George,
>>
>>> Are you up for taking a stab at something like `gengotypes.py`?
>>
>> I have was able to make a bit of progress on this over the weekend. I've started
>> `gengotypes.py` in my branch[1]; the portion which generates `xenlight_types.go`
>> (the counterpart to _libxl_types.h) is mostly working.
>>
>> The main exception is that I am not certain how the `KeyedUnion` type from the IDL
>> should be translated for Go. One option is to do something similar to the `oneof` field
>> in gRPC's protobuf messages[2]. Essentially, we would define a separate struct for each
>> of the structs that belong to the union. Then, where a union would be used in C, we use
>> an interface type which the previously defined structs implement.
>
> Yes, I think that's really the only option. Poking around, it looks
> like a lot of different people have recommended it; and the fact that
> it's in use by gRPC means it can't be too terrible a solution.
>
> The really annoying thing is that with the "interface-as-union", we
> can't use anonymous types: we'll have to explicitly define the
> {parent-struct} x {union-key} as a distinct type, and the is$TYPE()
> method on each one.
>
>> E.g.
>>
>> type isDomainTypeStruct interface {
>> isDomainTypeStruct()
>> }
>
> The interface type itself will need to be exported, right? (Obviously
> we don't want to export the defining method.)
>
>> type domainTypeHVMStruct struct {
>> ...
>> }
>
> So you've named the struct after the name of the key (libxl_domain_type)
> and the key value (hvm); but I don't think that's sufficient. Already
> there are two different structures indexed by libxl_channel_connection:
>
> typedef struct libxl_device_channel {
> libxl_domid backend_domid;
> char * backend_domname;
> libxl_devid devid;
> char * name;
> libxl_channel_connection connection;
> union {
> struct {
> char * path;
> } socket;
> } u;
> } libxl_device_channel;
>
> typedef struct libxl_channelinfo {
> char * backend;
> uint32_t backend_id;
> char * frontend;
> uint32_t frontend_id;
> libxl_devid devid;
> int state;
> int evtch;
> int rref;
> libxl_channel_connection connection;
> union {
> struct {
> char * path;
> } pty;
> } u;
> } libxl_channelinfo;
>
>
> (Note that in one, `socket` is defined, and in the other, `pty` is
> defined. I'm not sure that's not a bug, but anyway, that's what the IDL
> allows.)
>
> And there's no reason, theoretically, we couldn't have the following:
>
> ("u1", KeyedUnion(None, libxl_channel_connection, "connection",
> [/* One set of types */,
> ])),
> ("u2", KeyedUnion(None, libxl_channel_connection, "connection2",
> [/* A second set of types set of types */,
> ])),
>
> So we need to include the element name as well. But actually, I suppose
> that means we don't actually need to include the type, since the element
> name will be unique.
>
>> func (d domainTypeHVMStruct) isDomainTypeStruct() {}
>>
>> type DomainBuildInfo struct {
>> ...
>> Type DomainType
>> dts isDomainTypeStruct
>> }
>
> ...and then I'm afraid you'd need to have 'Dts' (should be exported,
> right?) instead by the element specified by the IDL; so 'U' in all the
> current cases.
>
> This gives us:
>
> type DomainBuildInfoU interface {
> isDomainBuildInfoU()
> }
>
> type DomainBuildInfoUHvmstruct {
> // ...
> }
Unfortunately this would mean the type assertion would be pretty long as
well:
hvm := di.TypeUnion.(xenlight.DomainBuildInfoTypeUnionHvm)
hvm.[element]
Compared to C:
di.u.hvm.[element]
But unfortunately I don't think there's a way around that; that's just a
limitation of Go.
-George
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2019-09-04 16:59 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-30 13:11 [Xen-devel] [RFC] Generating Go bindings for libxl Nicholas Rosbrook
2019-07-30 13:48 ` Tamas K Lengyel
2019-07-30 15:49 ` George Dunlap
2019-07-30 18:39 ` Tamas K Lengyel
2019-07-31 15:14 ` George Dunlap
2019-07-30 15:22 ` George Dunlap
2019-07-30 21:52 ` Nicholas Rosbrook
2019-07-31 15:06 ` George Dunlap
2019-07-31 21:22 ` Nicholas Rosbrook
2019-08-01 18:59 ` Nicholas Rosbrook
2019-08-02 15:38 ` George Dunlap
2019-08-02 19:09 ` Nicholas Rosbrook
2019-09-04 0:36 ` Nicholas Rosbrook
2019-09-04 16:52 ` George Dunlap
2019-09-04 16:59 ` George Dunlap [this message]
2019-09-04 18:23 ` Nicholas Rosbrook
2019-09-11 20:25 ` Nicholas Rosbrook
2019-09-12 14:37 ` George Dunlap
2019-09-12 17:35 ` Nicholas Rosbrook
2019-09-13 11:21 ` George Dunlap
2019-09-13 13:28 ` Nicholas Rosbrook
2019-09-24 0:33 ` Nicholas Rosbrook
2019-09-30 14:51 ` George Dunlap
2019-09-30 18:08 ` Nicholas Rosbrook
2019-09-04 18:15 ` Nicholas Rosbrook
2019-08-02 15:55 ` George Dunlap
2019-07-30 16:27 ` George Dunlap
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=dbeeb071-25ae-9652-4be1-e3067109179f@citrix.com \
--to=george.dunlap@citrix.com \
--cc=anthony.perard@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=kerriganb@ainfosec.com \
--cc=nicolas.belouin@gandi.net \
--cc=rosbrookn@ainfosec.com \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).