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

Re: [Xen-devel] [PATCH 28/28] libxl: ocaml: provide default records for libxl types



On Mon, 2013-04-29 at 15:13 +0100, Rob Hoes wrote:
> > On Mon, 2013-03-25 at 14:45 +0000, Rob Hoes wrote:
> > > Libxl functions such as libxl_domain_create_new take large structs of
> > > configuration parameters. Often, we would like to use the default
> > > values for many of these parameters.
> > >
> > > This commit makes OCaml records of defaults available for all libxl
> > > struct and keyed-union types, which can be used as a base to construct
> > > your own records, and to selectively override parameters where needed.
> > >
> > > For example, a Domain_create_info record can now be created as follows:
> > >
> > > let c_info = Xenlight.Domain_create_info.({ default with
> > >   ty = Xenlight.DOMAIN_TYPE_PV;
> > >   name = Some vm_name;
> > >   uuid = vm_uuid;
> > > }) in
> > 
> > This is a clever approach (and I expect good idiomatic ocaml?) but you need
> > to handle the init_val IDL field for all types since not everything should 
> > be
> > set to zero (e.g. some of the UInt subtypes don't default to 0, see MemKB
> > for one).
> > 
> > I wonder if a better alternative might be to use a C binding to call
> > libxl_TYPE_init() and convert that to an ocaml value? This would mean one
> > less place to change in the future as well.
> 
> I see. In that case, it indeed seems better to turn "default" into a
> function that calls a libxl *_init() function and converts it to an
> ocaml value, rather than having static defaults. With that, the only
> thing that changes in the example above is that "()" is added after
> "default".

I'm fine with that if you are.

Ian.


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

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