Re: [Xen-devel] [PATCH v2 08/22] golang/xenlight: define MsVmGenid builtin type

2019-12-04 Thread George Dunlap
On 11/15/19 7:44 PM, Nick Rosbrook wrote:
> From: Nick Rosbrook 
> 
> Define MsVmGenid as [int(C.LIBXL_MS_VM_GENID_LEN)]byte and implement fromC 
> and toC functions.
> 
> Signed-off-by: Nick Rosbrook 
> Reviewed-by: George Dunlap 
> ---
>  tools/golang/xenlight/xenlight.go | 23 +++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/tools/golang/xenlight/xenlight.go 
> b/tools/golang/xenlight/xenlight.go
> index eb0d309543..108b50124a 100644
> --- a/tools/golang/xenlight/xenlight.go
> +++ b/tools/golang/xenlight/xenlight.go
> @@ -216,6 +216,29 @@ func (mac Mac) toC() (C.libxl_mac, error) {
>   return cmac, nil
>  }
>  
> +// MsVmGenid represents a libxl_ms_vm_genid.
> +type MsVmGenid [int(C.LIBXL_MS_VM_GENID_LEN)]byte
> +
> +func (mvg *MsVmGenid) fromC(cmvg *C.libxl_ms_vm_genid) error {
> + b := 
> (*[int(C.LIBXL_MS_VM_GENID_LEN)]C.uint8_t)(unsafe.Pointer([0]))
> +
> + for i, v := range b {
> + mvg[i] = byte(v)
> + }

Sorry to come back to this -- is there a reason we can't just do
something like this?

func (u *Uuid) fromC(c *C.libxl_uuid) error {
for i := range *u {
u[i] = byte(c.uuid[i])
}

return nil
}

I.e., the only reason we seem to be doing the cast is to have an
appropriate type to range over; but we can just range over `*u` instead.

 -George

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

[Xen-devel] [PATCH v2 08/22] golang/xenlight: define MsVmGenid builtin type

2019-11-15 Thread Nick Rosbrook
From: Nick Rosbrook 

Define MsVmGenid as [int(C.LIBXL_MS_VM_GENID_LEN)]byte and implement fromC and 
toC functions.

Signed-off-by: Nick Rosbrook 
Reviewed-by: George Dunlap 
---
 tools/golang/xenlight/xenlight.go | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/tools/golang/xenlight/xenlight.go 
b/tools/golang/xenlight/xenlight.go
index eb0d309543..108b50124a 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -216,6 +216,29 @@ func (mac Mac) toC() (C.libxl_mac, error) {
return cmac, nil
 }
 
+// MsVmGenid represents a libxl_ms_vm_genid.
+type MsVmGenid [int(C.LIBXL_MS_VM_GENID_LEN)]byte
+
+func (mvg *MsVmGenid) fromC(cmvg *C.libxl_ms_vm_genid) error {
+   b := 
(*[int(C.LIBXL_MS_VM_GENID_LEN)]C.uint8_t)(unsafe.Pointer([0]))
+
+   for i, v := range b {
+   mvg[i] = byte(v)
+   }
+
+   return nil
+}
+
+func (mvg *MsVmGenid) toC() (C.libxl_ms_vm_genid, error) {
+   var cmvg C.libxl_ms_vm_genid
+
+   for i, v := range mvg {
+   cmvg.bytes[i] = C.uint8_t(v)
+   }
+
+   return cmvg, nil
+}
+
 type Context struct {
ctx*C.libxl_ctx
logger *C.xentoollog_logger_stdiostream
-- 
2.19.1


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