From: Ian Campbell Subject: Re: [PATCH 28/28] libxl: ocaml: provide default records for libxl types Date: Mon, 29 Apr 2013 15:19:42 +0100 Message-ID: <1367245182.3142.298.camel@zakaz.uk.xensource.com> References: <1364222729-6982-1-git-send-email-rob.hoes@citrix.com> <1364222729-6982-29-git-send-email-rob.hoes@citrix.com> <1365685733.8036.124.camel@zakaz.uk.xensource.com> <7EA643C653F17F4C80DE959E978F10ED010F729E01A4@LONPMAILBOX01.citrite.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <7EA643C653F17F4C80DE959E978F10ED010F729E01A4@LONPMAILBOX01.citrite.net> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Rob Hoes Cc: "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org 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.