From: Ian Campbell Subject: Re: [PATCH 28/28] libxl: ocaml: provide default records for libxl types Date: Thu, 11 Apr 2013 14:08:53 +0100 Message-ID: <1365685733.8036.124.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> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1364222729-6982-29-git-send-email-rob.hoes@citrix.com> 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-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. Ian.