|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH RFC 3/8] golang/xenlight: Add host-related functionality
On 18/01/17 19:56, Ronald Rojas wrote:
> Add calls for the following host-related functionality:
> - libxl_get_max_cpus
> - libxl_get_online_cpus
> - libxl_get_max_nodes
> - libxl_get_free_memory
> - libxl_get_physinfo
> - libxl_get_version_info
>
> Include Golang versions of the following structs:
> - libxl_physinfo as Physinfo
> - libxl_version_info as VersionInfo
> - libxl_hwcap as Hwcap
>
> Signed-off-by: Ronald Rojas <ronladred@xxxxxxxxx>
This looks good, and I think could be checked in once rebased on
previous changes. One comment for future direction...
> ---
> tools/golang/xenlight/xenlight.go | 185
> ++++++++++++++++++++++++++++++++++++++
> 1 file changed, 185 insertions(+)
>
> diff --git a/tools/golang/xenlight/xenlight.go
> b/tools/golang/xenlight/xenlight.go
> index d58f8b8..6b04850 100644
> --- a/tools/golang/xenlight/xenlight.go
> +++ b/tools/golang/xenlight/xenlight.go
> @@ -109,6 +109,62 @@ type Context struct {
> ctx *C.libxl_ctx
> }
>
> +type Hwcap []C.uint32_t
> +
> +func hwcapCToGo(chwcap C.libxl_hwcap) (ghwcap Hwcap) {
> + // Alloc a Go slice for the bytes
> + size := 8
> + ghwcap = make([]C.uint32_t, size)
> +
> + // Make a slice pointing to the C array
> + mapslice := (*[1 <<
> 30]C.uint32_t)(unsafe.Pointer(&chwcap[0]))[:size:size]
> +
> + // And copy the C array into the Go array
> + copy(ghwcap, mapslice)
> +
> + return
> +}
In my own copy of the library, I was experimenting with using methods to
do this, rather than making standalone functions that embed the name in
the type. Something like this:
func (c C.libxl_dominfo) toGo() (g Dominfo) {
g.Uuid = Uuid(c.uuid)
[etc]
}
That way you can do cdi.toGo() rather than dominfoCToGo(cdi). The
syntax looks a lot cleaner and more consistent.
What do you think?
-George
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |