[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH v2] golang/xenlight: implement constructor generation


  • To: Nick Rosbrook <rosbrookn@xxxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: George Dunlap <george.dunlap@xxxxxxxxxx>
  • Date: Thu, 5 Mar 2020 12:18:10 +0000
  • Authentication-results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=george.dunlap@xxxxxxxxxx; spf=Pass smtp.mailfrom=George.Dunlap@xxxxxxxxxx; spf=None smtp.helo=postmaster@xxxxxxxxxxxxxxx
  • Autocrypt: addr=george.dunlap@xxxxxxxxxx; prefer-encrypt=mutual; keydata= mQINBFPqG+MBEACwPYTQpHepyshcufo0dVmqxDo917iWPslB8lauFxVf4WZtGvQSsKStHJSj 92Qkxp4CH2DwudI8qpVbnWCXsZxodDWac9c3PordLwz5/XL41LevEoM3NWRm5TNgJ3ckPA+J K5OfSK04QtmwSHFP3G/SXDJpGs+oDJgASta2AOl9vPV+t3xG6xyfa2NMGn9wmEvvVMD44Z7R W3RhZPn/NEZ5gaJhIUMgTChGwwWDOX0YPY19vcy5fT4bTIxvoZsLOkLSGoZb/jHIzkAAznug Q7PPeZJ1kXpbW9EHHaUHiCD9C87dMyty0N3TmWfp0VvBCaw32yFtM9jUgB7UVneoZUMUKeHA fgIXhJ7I7JFmw3J0PjGLxCLHf2Q5JOD8jeEXpdxugqF7B/fWYYmyIgwKutiGZeoPhl9c/7RE Bf6f9Qv4AtQoJwtLw6+5pDXsTD5q/GwhPjt7ohF7aQZTMMHhZuS52/izKhDzIufl6uiqUBge 0lqG+/ViLKwCkxHDREuSUTtfjRc9/AoAt2V2HOfgKORSCjFC1eI0+8UMxlfdq2z1AAchinU0 eSkRpX2An3CPEjgGFmu2Je4a/R/Kd6nGU8AFaE8ta0oq5BSFDRYdcKchw4TSxetkG6iUtqOO ZFS7VAdF00eqFJNQpi6IUQryhnr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Opet9cnM7N9+fkStB8FQkGj8BPV9EEcBwXjpbjwHDdnSQS VdaLpWX1m1ov9McQUl+YOlKshz3d+S8FtZ9a5OjPwNhwaJ5BlZRYdwG8LEBHnhzzcLamBtLY Jf013pb3/LMvA4pBcYzol3G6JE9h7AhMphRnDBno8j2vZwZDnYepL5Xd5l1FH9sHgRFrg0dm iGMmZNB8/xqhHuYOG8QzkOraYh7IRsJhHT1+k9x4fFkTkFgYwtl/YYSG33jErTepn4/lECdJ zK3laGuMZxe0OM5xTu2j2zA=
  • Cc: Nick Rosbrook <rosbrookn@xxxxxxxxxxxx>, Ian Jackson <ian.jackson@xxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Thu, 05 Mar 2020 12:18:17 +0000
  • Ironport-sdr: r1qY6rT6YPDko2po66TtNQXrCiyTjkjeEcTUZbeIcHAUFoNo+QAdJKjgw5Sas2KLdwMdMP8sch uahJIv7CgiwZxRcCMKtREIIl6lDb6cdoa9HBEHpLQLyTcs1Ge3EjAcSbxx8vQxeHG+7ABKAJ/t ccChj2vV4Gks/DoRILViA9H3boJxOo9wabKFJDJesfNdg2zy1g6kFuObqpvv0zbuEDoEn5je43 h+qsKtf19Ndv/XMk2dOz/F5fNqeIhQx7ZI9kbvHlXBoUUgmVb/hexuQ00rfAKbFPnjQdy0BRLg 5vE=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 3/4/20 6:08 PM, George Dunlap wrote:
> On 3/2/20 8:10 PM, Nick Rosbrook wrote:
>> Generate constructors for generated Go types. Call libxl_<type>_init so
>> the Go type can be properly initialized.
>>
>> If a type has a keyed union field, add a parameter to the function
>> signature to set the key variable, and call the init function for the
>> keyed union.>
>> Signed-off-by: Nick Rosbrook <rosbrookn@xxxxxxxxxxxx>
> 
> So gave this a spin and ran a cross a niggle...
> 
>> +// NewDomainBuildInfo returns an instance of DomainBuildInfo initialized 
>> with defaults.
>> +func NewDomainBuildInfo(dtype DomainType) (*DomainBuildInfo, error) {
> 
> NewDomainBuildInfo() will take the domain type; but what I really want is...
> 
>> +// NewDomainConfig returns an instance of DomainConfig initialized with 
>> defaults.
>> +func NewDomainConfig() (*DomainConfig, error) {
> 
> ...for NewDomainConfig() to take the Domain Type.  Otherwise I'm in a
> position of having to do something like:
> 
>       dconf, err := xl.NewDomainConfig()
>       if err != nil {
>               fmt.Printf("NewDomainConfig: %v\n", err)
>               return
>       }
>         dconf.BInfo = xl.NewDomainBuildInfo(xl.DomainTypePv)

NewDomainConfig() as of this patch can never return success, because
DomainConfig.fromC() will call DomainBuildInfo.fromC(), which will choke
on b_info.type = LIBXL_DOMAIN_TYPE_INVALID.

This is actually a bug in to/fromC.  Consider libxl_channelinfo.

The idl says:

libxl_channelinfo = Struct("channelinfo", [
    ("backend", string),
    ("backend_id", uint32),
    ("frontend", string),
    ("frontend_id", uint32),
    ("devid", libxl_devid),
    ("state", integer),
    ("evtch", integer),
    ("rref", integer),
    ("u", KeyedUnion(None, libxl_channel_connection, "connection",
           [("unknown", None),
            ("pty", Struct(None, [("path", string),])),
            ("socket", None),
           ])),
    ], dir=DIR_OUT)

But the generated code currently only generates:

type Channelinfo struct {
        Backend         string
        BackendId       uint32
        Frontend        string
        FrontendId      uint32
        Devid           Devid
        State           intWhich means if libxl passes back
        Evtch           int
        Rref            int
        Connection      ChannelConnection
        ConnectionUnion channelinfoConnectionUnion
}

type channelinfoConnectionUnion interface {
        ischannelinfoConnectionUnion()
}

type ChannelinfoConnectionUnionPty struct {
        Path string
}

func (x ChannelinfoConnectionUnionPty) ischannelinfoConnectionUnion() {}

I think this makes sense -- there's no need to have types for 'unknown'
and 'socket' just to hold nothing.  But then the marshaling code looks
like this:

        switch x.Connection {
        case ChannelConnectionPty:
                tmp, ok := x.ConnectionUnion.(ChannelinfoConnectionUnionPty)
                if !ok {
                        return errors.New("wrong type for union key connection")
                }
                var pty C.libxl_channelinfo_connection_union_pty
                if tmp.Path != "" {
                        pty.path = C.CString(tmp.Path)
                }
                ptyBytes := C.GoBytes(unsafe.Pointer(&pty),
C.sizeof_libxl_channelinfo_connection_union_pty)
                copy(xc.u[:], ptyBytes)
        default:
                return fmt.Errorf("invalid union key '%v'", x.Connection)
        }

So this will incorrectly fail for for either 'unknown' or 'socket'.
What we need to have is for toC to ignore enumerated values that have
empty types, and fromC to set the union to `nil` in these cases.

I've got a patch -- I'll send it out.

 -George

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

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.