xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* new idl helper, append to Array
@ 2016-02-04  9:23 Olaf Hering
  2016-02-04  9:58 ` Ian Campbell
  0 siblings, 1 reply; 7+ messages in thread
From: Olaf Hering @ 2016-02-04  9:23 UTC (permalink / raw)
  To: Ian Campbell; +Cc: xen-devel

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-02-05 10:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-04  9:23 new idl helper, append to Array Olaf Hering
2016-02-04  9:58 ` Ian Campbell
2016-02-04 10:07   ` Olaf Hering
2016-02-04 10:48     ` Wei Liu
2016-02-05  9:55     ` Olaf Hering
2016-02-05 10:06       ` Ian Campbell
2016-02-04 10:45   ` Wei Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).