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

Re: [Xen-devel] [PATCH] golang/xenlight: Fix handling of marshalling of empty elements for keyed unions



> Keyed types in libxl_types.idl can have elements of type 'None'.  The
> golang type generator (correctly) don't implement any union types for
> these empty elements.  However, the toC and fromC helper generators
> incorrectly treat these elements as invalid.
>
> Consider for example, libxl_channelinfo.  The idl contains the
> following keyed element:
>
>     ("u", KeyedUnion(None, libxl_channel_connection, "connection",
>            [("unknown", None),
>             ("pty", Struct(None, [("path", string),])),
>             ("socket", None),
>            ])),
>
> But the toC marshaller currently 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)
>         }
>
> Which means toC() will fail for ChannelConnectionUnknown or
> ChannelConnectionSocket.
>
> Modify the generator to handle keyed union elements of type 'None'.
> For fromC, set the value to 'nil'; for toC, leave things as-is.
>
> Signed-off-by: George Dunlap <george.dunlap@xxxxxxxxxx>

Reviewed-by: Nick Rosbrook <rosbrookn@xxxxxxxxxxxx>


    
_______________________________________________
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®.