xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Ian Campbell <ian.campbell@citrix.com>
To: Olaf Hering <olaf@aepfle.de>, Wei Liu <wei.liu2@citrix.com>
Cc: xen-devel@lists.xen.org
Subject: Re: new idl helper, append to Array
Date: Thu, 4 Feb 2016 09:58:14 +0000	[thread overview]
Message-ID: <1454579894.25207.144.camel@citrix.com> (raw)
In-Reply-To: <20160204092353.GA17709@aepfle.de>

On Thu, 2016-02-04 at 10:23 +0100, Olaf Hering wrote:
> 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()?

If something can be autogenerated without too much trouble then I see no
reason not to do so.

I'd go with libxl_<type>_list_append as the naming scheme, which fits in
with libxl_<type>_list_free (which probably ought to be autogenerated too,
but isn't). So:

libxl_device_vscsidev_list_append(libxl_ctx *ctx,
                                  libxl_device_vscsidev *dev, int nr,
				  libxl_device_vscsidev *new);
(if you intend for this to be internal then s/^libxl_/&_/ and
s/libxl_ctx \*ctx/libxl__gc *gc/)

Oh, I see you want it to take the type containing the array, that could
work to, you'd need to call it libxl_<type>_append_<field>, so

libxl_device_vscsictrl_append_vscsidevs

which looks a bit odd (since the field name is plural and the IDL has no
way to find the singular). We could live with that, or s/append/append_to/
or make it varargs and take perhaps multiple new entries and a NULL
terminator.

I think the append_to variant is probably least gross.

Looks like various places such as libxl__append_nic_list_of_type could make
use of this helper too. As could xl_cmdimpl.c for ARRAY_EXTEND_INIT perhaps
(using it everywhere isn't mandatory of course, but if you feel inclined it
would be nice)

> 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.

Indeed.

> 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);

Wei, is it necessary to init the dst before copy into it?

>     ctrl->num_vscsidevs++;
>     rc = 0;
> out:
>     return rc;
> }
> 
> 
> Olaf

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

  reply	other threads:[~2016-02-04  9:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-04  9:23 new idl helper, append to Array Olaf Hering
2016-02-04  9:58 ` Ian Campbell [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1454579894.25207.144.camel@citrix.com \
    --to=ian.campbell@citrix.com \
    --cc=olaf@aepfle.de \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).