xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: George Dunlap <george.dunlap@citrix.com>
To: Nick Rosbrook <rosbrookn@gmail.com>
Cc: Nick Rosbrook <rosbrookn@ainfosec.com>,
	Xen-devel <xen-devel@lists.xenproject.org>,
	kerriganb@ainfosec.com, Ian Jackson <ian.jackson@eu.citrix.com>,
	Wei Liu <wl@xen.org>
Subject: Re: [Xen-devel] [PATCH v2 15/22] golang/xenlight: begin C to Go type marshaling
Date: Thu, 5 Dec 2019 18:00:26 +0000	[thread overview]
Message-ID: <ffe83eb5-ed94-d594-71f9-bef80377fc09@citrix.com> (raw)
In-Reply-To: <CAEBZRSe=8vW7qj5fbU7dTpPYTtuR5j1PTbiV0=tYnGvkcahG8w@mail.gmail.com>

On 12/5/19 4:38 PM, Nick Rosbrook wrote:
>> You should probably say here explicitly what kinds of elements you're
>> supporting and not supporting in this patch; specifically:
>>
>> - You're converting built-ins (or is this any struct-like type?)
> 
> Any struct-like type, since the fromC functions are all defined in
> this patch (excluding array fields and keyed unions as you said
> below).
> 
>> - You handle nested anonymous structs
>> - But you're not handling keyed unions or arrays (anything else)?
> 
> I think this covers it, thanks.
> 
>>> +func (x *VncInfo) fromC(xc *C.libxl_vnc_info) error {
>>> +     var defboolEnable Defbool
>>> +     if err := defboolEnable.fromC(&xc.enable); err != nil {
>>> +             return err
>>> +     }
>>
>> Is there a reason in these cases that we don't simply call .fromC on the
>> elemet itself?
> 
> This ensures that when we call fromC, we have an initialized variable.
> This might be overkill here, as this would matter more if we had
> structs with a nested struct pointer. E.g., [1] will panic since only
> the outer struct is initialized.

So first of all, I noticed that the marshalling code for Union structs
does what I suggest. :-)

I can see how such a construct would be needed when there was a pointer
type.  But if there was a pointer type, you'd have to special-case
things anyway.  Take the following code that has a non-pointer element:

	var defboolEnable Defbool // The same type as x.Enable
	if err := defboolEnable.fromC(&xc.enable); err != nil {
		return err
	}
	x.Enable = defboolEnable

Now suppose you had a pointer element instead; what would it look like?

	var defboolEnable Defbool // NOT the same type as x.Enable!
	if err := defboolEnable.fromC(&xc.enable); err != nil {
		return err
	}
	x.Enable = &defboolEnable

The generation code would have to replace the type of "Enable", which is
a pointer, with the actual instance of the thing; and then assign the
reference, rather than the value.  So if we run across something like
that, we can sort that out when we come to it.

I'm not super-strong on this, so I don't want to bike-shed.  But I think
the way you generate the marshalling code for the union structs is better:

	if err := x.Pae.fromC(&tmp.pae); err != nil {
		return err
	}

Thanks,
 -George

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2019-12-05 18:01 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-15 19:44 [Xen-devel] [PATCH v2 00/22] generated Go libxl bindings using IDL Nick Rosbrook
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 01/22] golang/xenlight: generate enum types from IDL Nick Rosbrook
2019-12-03 18:11   ` George Dunlap
2019-12-04 15:58   ` George Dunlap
2019-12-05 15:02   ` George Dunlap
2019-12-05 17:00     ` Nick Rosbrook
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 02/22] golang/xenlight: define Defbool builtin type Nick Rosbrook
2019-12-04 15:50   ` George Dunlap
2019-12-05 15:23     ` Nick Rosbrook
2019-12-05 15:27       ` George Dunlap
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 03/22] golang/xenlight: define Devid type as int Nick Rosbrook
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 04/22] golang/xenlight: define KeyValueList as empty struct Nick Rosbrook
2019-12-04 16:08   ` George Dunlap
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 05/22] golang/xenlight: re-name Bitmap marshaling functions Nick Rosbrook
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 06/22] golang/xenlight: define StringList builtin type Nick Rosbrook
2019-12-04 16:15   ` George Dunlap
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 07/22] golang/xenlight: define Mac " Nick Rosbrook
2019-12-04 16:18   ` George Dunlap
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 08/22] golang/xenlight: define MsVmGenid " Nick Rosbrook
2019-12-04 17:00   ` George Dunlap
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 09/22] golang/xenlight: define EvLink builtin as empty struct Nick Rosbrook
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 10/22] golang/xenlight: define CpuidPolicyList builtin type Nick Rosbrook
2019-12-04 16:48   ` George Dunlap
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 11/22] golang/xenlight: re-factor Uuid type implementation Nick Rosbrook
2019-12-04 17:02   ` George Dunlap
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 12/22] golang/xenlight: re-factor Hwcap " Nick Rosbrook
2019-12-04 17:07   ` George Dunlap
2019-12-05 15:35     ` Nick Rosbrook
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 13/22] golang/xenlight: generate structs from the IDL Nick Rosbrook
2019-12-04 17:25   ` George Dunlap
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 14/22] golang/xenlight: remove no-longer used type MemKB Nick Rosbrook
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 15/22] golang/xenlight: begin C to Go type marshaling Nick Rosbrook
2019-12-04 18:07   ` George Dunlap
2019-12-05 16:38     ` Nick Rosbrook
2019-12-05 18:00       ` George Dunlap [this message]
2019-12-05 18:32         ` Nick Rosbrook
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 16/22] golang/xenlight: implement keyed union C to Go marshaling Nick Rosbrook
2019-12-04 18:40   ` George Dunlap
2019-12-05 12:22     ` George Dunlap
2019-12-05 16:53       ` Nick Rosbrook
2019-12-05 17:33         ` George Dunlap
2019-12-05 18:39           ` Nick Rosbrook
2019-12-06 10:46             ` George Dunlap
2019-12-06 15:39               ` Nick Rosbrook
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 17/22] golang/xenlight: implement array " Nick Rosbrook
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 18/22] golang/xenlight: begin Go to C type marshaling Nick Rosbrook
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 19/22] golang/xenlight: implement keyed union Go to C marshaling Nick Rosbrook
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 20/22] golang/xenlight: implement array " Nick Rosbrook
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 21/22] golang/xenlight: revise use of Context type Nick Rosbrook
2019-11-15 19:44 ` [Xen-devel] [PATCH v2 22/22] golang/xenlight: add error return type to Context.Cpupoolinfo Nick Rosbrook

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=ffe83eb5-ed94-d594-71f9-bef80377fc09@citrix.com \
    --to=george.dunlap@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=kerriganb@ainfosec.com \
    --cc=rosbrookn@ainfosec.com \
    --cc=rosbrookn@gmail.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).