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

[Xen-devel] [PATCH 07/24] golang/xenlight: define StringList builtin type



From: Nick Rosbrook <rosbrookn@xxxxxxxxxxxx>

Define StringList as []string an implement fromC and toC functions.

Signed-off-by: Nick Rosbrook <rosbrookn@xxxxxxxxxxxx>
---
Cc: George Dunlap <george.dunlap@xxxxxxxxxx>
Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Cc: Wei Liu <wl@xxxxxxx>

 tools/golang/xenlight/xenlight.go | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/tools/golang/xenlight/xenlight.go 
b/tools/golang/xenlight/xenlight.go
index 09fcdca5d1..a3a1836d31 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -234,6 +234,35 @@ func (kvl KeyValueList) toC() (C.libxl_key_value_list, 
error) {
        return ckvl, nil
 }
 
+// StringList represents a libxl_string_list.
+type StringList []string
+
+func (sl StringList) fromC(csl *C.libxl_string_list) error {
+       size := int(C.libxl_string_list_length(csl))
+       list := (*[1 << 30]*C.char)(unsafe.Pointer(csl))[:size:size]
+
+       sl = make([]string, size)
+
+       for i, v := range list {
+               sl[i] = C.GoString(v)
+       }
+
+       return nil
+}
+
+func (sl StringList) toC() (C.libxl_string_list, error) {
+       var char *C.char
+       size := len(sl)
+       csl := (C.libxl_string_list)(C.malloc(C.ulong(size) * 
C.ulong(unsafe.Sizeof(char))))
+       clist := (*[1 << 30]*C.char)(unsafe.Pointer(csl))[:size:size]
+
+       for i, v := range sl {
+               clist[i] = C.CString(v)
+       }
+
+       return csl, nil
+}
+
 // Bitmap represents a libxl_bitmap.
 //
 // Implement the Go bitmap type such that the underlying data can
-- 
2.19.1


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