From mboxrd@z Thu Jan 1 00:00:00 1970 From: Olaf Hering Subject: new idl helper, append to Array Date: Thu, 4 Feb 2016 10:23:53 +0100 Message-ID: <20160204092353.GA17709@aepfle.de> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Campbell Cc: xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org Ian, in my pvscsi code I have two copies of a helper function which appends yet another instance of something to an Array, as shown below. This is similar to the _copy variant. Is it worth to let gentypes generate such a helper, like libxl_device_vscsictrl_append_vscsidev()? While writing this I realize that libxl__realloc will not return, so my helper can be converted from returning int to void, and all the locals can be removed. static int vscsi_append_dev(libxl__gc *gc, libxl_device_vscsictrl *ctrl, libxl_device_vscsidev *dev) { int rc; libxl_device_vscsidev *devs; devs = libxl__realloc(NOGC, ctrl->vscsidevs, sizeof(*dev) * (ctrl->num_vscsidevs + 1)); if (!devs) { rc = ERROR_NOMEM; goto out; } ctrl->vscsidevs = devs; libxl_device_vscsidev_init(ctrl->vscsidevs + ctrl->num_vscsidevs); libxl_device_vscsidev_copy(CTX, ctrl->vscsidevs + ctrl->num_vscsidevs, dev); ctrl->num_vscsidevs++; rc = 0; out: return rc; } Olaf