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

[Xen-devel] [PATCH 2/9] golang/xenlight: Do proper nil / NULL conversions for builtin Bitmap type


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: George Dunlap <george.dunlap@xxxxxxxxxx>
  • Date: Fri, 27 Dec 2019 16:32:17 +0000
  • Authentication-results: esa3.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
  • Cc: Nick Rosbrook <rosbrookn@xxxxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>
  • Delivery-date: Fri, 27 Dec 2019 16:32:59 +0000
  • Ironport-sdr: NOrYm6dHLDNUooZs4DMZGl+2tEflhqKMomBjOly/399JKxSDBkfis1rrWGf32dCSMTMCBBOpCN xyN3R+tTO97bYwNsoqKJ6lKlwWBGVq/QSk3M5hcuiThfJNtK8XR3zOZXValUBy8+epXLPz18TV 06ggJKwBdFXP8YLnUbJWD21r3IQEsC/ik7GkYwCuU0pn6AfwURz8whYVOxV7uoXLJvA1RrbBU5 llw334gtHao1H7t1u8j/+YnxsGCTYtI9h/DhRqXrbOfk5KLuAVXG7+9pFn84QD0BlH0O6ZPTba rug=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Similar to the autogenerated types, but for `builtin` Bitmap type.

Signed-off-by: George Dunlap <george.dunlap@xxxxxxxxxx>
---
CC: Nick Rosbrook <rosbrookn@xxxxxxxxxxxx>
---
 tools/golang/xenlight/xenlight.go | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/tools/golang/xenlight/xenlight.go 
b/tools/golang/xenlight/xenlight.go
index 237f26bce9..e18f0f35f8 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -408,15 +408,17 @@ type Bitmap struct {
 }
 
 func (bm *Bitmap) fromC(cbm *C.libxl_bitmap) error {
-       // Alloc a Go slice for the bytes
-       size := int(cbm.size)
-       bm.bitmap = make([]C.uint8_t, size)
+       bm.bitmap = nil
+       if size := int(cbm.size); size > 0 {
+               // Alloc a Go slice for the bytes
+               bm.bitmap = make([]C.uint8_t, size)
 
-       // Make a slice pointing to the C array
-       cs := (*[1 << 30]C.uint8_t)(unsafe.Pointer(cbm._map))[:size:size]
+               // Make a slice pointing to the C array
+               cs := (*[1 << 
30]C.uint8_t)(unsafe.Pointer(cbm._map))[:size:size]
 
-       // And copy the C array into the Go array
-       copy(bm.bitmap, cs)
+               // And copy the C array into the Go array
+               copy(bm.bitmap, cs)
+       }
 
        return nil
 }
@@ -426,10 +428,12 @@ func (bm *Bitmap) toC() (C.libxl_bitmap, error) {
 
        size := len(bm.bitmap)
        cbm.size = C.uint32_t(size)
-       cbm._map = (*C.uint8_t)(C.malloc(C.ulong(cbm.size) * C.sizeof_uint8_t))
-       cs := (*[1 << 31]C.uint8_t)(unsafe.Pointer(cbm._map))[:size:size]
+       if cbm.size > 0 {
+               cbm._map = (*C.uint8_t)(C.malloc(C.ulong(cbm.size) * 
C.sizeof_uint8_t))
+               cs := (*[1 << 
31]C.uint8_t)(unsafe.Pointer(cbm._map))[:size:size]
 
-       copy(cs, bm.bitmap)
+               copy(cs, bm.bitmap)
+       }
 
        return cbm, nil
 }
-- 
2.24.0


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