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

Re: [Xen-devel] [RFC] Generating Go bindings for libxl

Hi George,

I made some more progress on gengotypes.py [1].

First, I implemented the KeyedUnion translation that we talked about. 
You can see an example of the generated code in [2].

Second, I took a first pass at the C-to-Go type marshaling. I defined a
"marshaler" interface in [3], which allows the convenience function
`func fromC(m marshaler, ctype interface{}) (err error)`. My primary 
motivation for this interface is to allow the generated code to call panic
rather than checking for and handling errors. However, the previously
mentioned convenience function will recover from those panics and return
the appropriate error. So, each generated struct implements this interface.
See the generated code in [4].

You'll also notice in [4] that I defined C structs in the cgo preamble which
correspond to the Go KeyedUnion structs, e.g. DomainBuildInfoTypeUnionPv.
Since cgo treats C unions a byte slice, we need to do an unsafe.Pointer 
to some struct to be able to access the fields of a union. So, I thought it 
make the most sense to do the cast to a C type, and then convert those fields
to Go types accordingly. See [5] for example.

What are your thoughts on these implementations so far?

I was able to write a couple examples to demonstrate the generated code is 
working, but I had to make some small changes to the existing code WRT
libxl builtin types (not committed to my branch). So, I thought we should decide
how these builtin types will be defined in Go. This is what I was thinking so 

Defbool (?)
Domid (already exists)
Devid => int
Uuid => [16]byte
Mac => [6]byte
Bitmap (already exists)
CpuidPolicyList (?)
StringList => [ ]string
KeyValueList => map[string]string
Hwcap (already exists, but should be re-factored to be like Bitmap to hide the 
C type)
MsVmGenid => [16]byte
EvLink (?)



[1] https://github.com/enr0n/xen/blob/gen-go-types/tools/golang/gengotypes.py
Xen-devel mailing list



Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.