WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] libxl: introduce flexarray_append_pair

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] libxl: introduce flexarray_append_pair
From: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
Date: Wed, 9 Mar 2011 16:54:35 +0000
Delivery-date: Wed, 09 Mar 2011 08:56:31 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Alpine 2.00 (DEB 1167 2008-08-23)
Introduce flexarray_append_pair: a simple syntactic sugar to add a pair
of pointers to a flexarray, very useful when adding pairs of strings to
xenstore.
Replace flexarray_vappend calls with flexarray_append_pair calls when
dealing with flexarrays that are going to be used with
libxl__xs_kvs_of_flexarray: NULL is a valid pointer value in these cases
while flexarray_vappend uses NULL as vargs terminator.

Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>

diff -r 65d26504e843 tools/libxl/flexarray.c
--- a/tools/libxl/flexarray.c   Wed Mar 09 16:32:04 2011 +0000
+++ b/tools/libxl/flexarray.c   Wed Mar 09 16:50:57 2011 +0000
@@ -69,6 +69,14 @@ int flexarray_append(flexarray_t *array,
     return flexarray_set(array, array->count, ptr);
 }
 
+int flexarray_append_pair(flexarray_t *array, void *ptr1, void *ptr2)
+{
+    int rc = flexarray_append(array, ptr1);
+    if (!rc)
+        rc = flexarray_append(array, ptr2);
+    return rc;
+}
+
 int flexarray_vappend(flexarray_t *array, ...)
 {
     va_list va;
diff -r 65d26504e843 tools/libxl/flexarray.h
--- a/tools/libxl/flexarray.h   Wed Mar 09 16:32:04 2011 +0000
+++ b/tools/libxl/flexarray.h   Wed Mar 09 16:50:57 2011 +0000
@@ -28,6 +28,7 @@ _hidden int flexarray_grow(flexarray_t *
 _hidden int flexarray_grow(flexarray_t *array, int extents);
 _hidden int flexarray_set(flexarray_t *array, unsigned int index, void *ptr);
 _hidden int flexarray_append(flexarray_t *array, void *ptr);
+_hidden int flexarray_append_pair(flexarray_t *array, void *ptr1, void *ptr2);
 _hidden int flexarray_vappend(flexarray_t *array, ...);
 _hidden int flexarray_get(flexarray_t *array, int index, void **ptr);
 
diff -r 65d26504e843 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Wed Mar 09 16:32:04 2011 +0000
+++ b/tools/libxl/libxl.c       Wed Mar 09 16:50:57 2011 +0000
@@ -1887,27 +1887,26 @@ int libxl_device_vfb_add(libxl_ctx *ctx,
     device.domid = vfb->domid;
     device.kind = DEVICE_VFB;
 
-    flexarray_vappend(back, "frontend-id", libxl__sprintf(&gc, "%d", 
vfb->domid), NULL);
-    flexarray_vappend(back, "online", "1", NULL);
-    flexarray_vappend(back, "state", libxl__sprintf(&gc, "%d", 1), NULL);
-    flexarray_vappend(back, "domain", libxl__domid_to_name(&gc, domid), NULL);
-    flexarray_vappend(back, "vnc", libxl__sprintf(&gc, "%d", vfb->vnc), NULL);
-    flexarray_vappend(back, "vnclisten", vfb->vnclisten, NULL);
-    flexarray_append(back, "vncpasswd");
-    flexarray_append(back, vfb->vncpasswd);
-    flexarray_vappend(back, "vncdisplay", libxl__sprintf(&gc, "%d", 
vfb->vncdisplay), NULL);
-    flexarray_vappend(back, "vncunused", libxl__sprintf(&gc, "%d", 
vfb->vncunused), NULL);
-    flexarray_vappend(back, "sdl", libxl__sprintf(&gc, "%d", vfb->sdl), NULL);
-    flexarray_vappend(back, "opengl", libxl__sprintf(&gc, "%d", vfb->opengl), 
NULL);
+    flexarray_append_pair(back, "frontend-id", libxl__sprintf(&gc, "%d", 
vfb->domid));
+    flexarray_append_pair(back, "online", "1");
+    flexarray_append_pair(back, "state", libxl__sprintf(&gc, "%d", 1));
+    flexarray_append_pair(back, "domain", libxl__domid_to_name(&gc, domid));
+    flexarray_append_pair(back, "vnc", libxl__sprintf(&gc, "%d", vfb->vnc));
+    flexarray_append_pair(back, "vnclisten", vfb->vnclisten);
+    flexarray_append_pair(back, "vncpasswd", vfb->vncpasswd);
+    flexarray_append_pair(back, "vncdisplay", libxl__sprintf(&gc, "%d", 
vfb->vncdisplay));
+    flexarray_append_pair(back, "vncunused", libxl__sprintf(&gc, "%d", 
vfb->vncunused));
+    flexarray_append_pair(back, "sdl", libxl__sprintf(&gc, "%d", vfb->sdl));
+    flexarray_append_pair(back, "opengl", libxl__sprintf(&gc, "%d", 
vfb->opengl));
     if (vfb->xauthority) {
-        flexarray_vappend(back, "xauthority", vfb->xauthority, NULL);
+        flexarray_append_pair(back, "xauthority", vfb->xauthority);
     }
     if (vfb->display) {
-        flexarray_vappend(back, "display", vfb->display, NULL);
+        flexarray_append_pair(back, "display", vfb->display);
     }
 
-    flexarray_vappend(front, "backend-id", libxl__sprintf(&gc, "%d", 
vfb->backend_domid), NULL);
-    flexarray_vappend(front, "state", libxl__sprintf(&gc, "%d", 1), NULL);
+    flexarray_append_pair(front, "backend-id", libxl__sprintf(&gc, "%d", 
vfb->backend_domid));
+    flexarray_append_pair(front, "state", libxl__sprintf(&gc, "%d", 1));
 
     libxl__device_generic_add(ctx, &device,
                              libxl__xs_kvs_of_flexarray(&gc, back, 
back->count),
diff -r 65d26504e843 tools/libxl/libxl_pci.c
--- a/tools/libxl/libxl_pci.c   Wed Mar 09 16:32:04 2011 +0000
+++ b/tools/libxl/libxl_pci.c   Wed Mar 09 16:50:57 2011 +0000
@@ -228,10 +228,10 @@ static void libxl_create_pci_backend_dev
     flexarray_append(back, libxl__sprintf(gc, "dev-%d", num));
     flexarray_append(back, libxl__sprintf(gc, PCI_BDF, pcidev->domain, 
pcidev->bus, pcidev->dev, pcidev->func));
     if (pcidev->vdevfn)
-        flexarray_vappend(back, libxl__sprintf(gc, "vdevfn-%d", num), 
libxl__sprintf(gc, "%x", pcidev->vdevfn), NULL);
+        flexarray_append_pair(back, libxl__sprintf(gc, "vdevfn-%d", num), 
libxl__sprintf(gc, "%x", pcidev->vdevfn));
     flexarray_append(back, libxl__sprintf(gc, "opts-%d", num));
     flexarray_append(back, libxl__sprintf(gc, "msitranslate=%d,power_mgmt=%d", 
pcidev->msitranslate, pcidev->power_mgmt));
-    flexarray_vappend(back, libxl__sprintf(gc, "state-%d", num), 
libxl__sprintf(gc, "%d", 1), NULL);
+    flexarray_append_pair(back, libxl__sprintf(gc, "state-%d", num), 
libxl__sprintf(gc, "%d", 1));
 }
 
 static int libxl_create_pci_backend(libxl__gc *gc, uint32_t domid, 
libxl_device_pci *pcidev, int num)
@@ -261,18 +261,17 @@ static int libxl_create_pci_backend(libx
     device.domid = domid;
     device.kind = DEVICE_PCI;
 
-    flexarray_vappend(back, "frontend-id", libxl__sprintf(gc, "%d", domid),
-                      "online", "1", "state", libxl__sprintf(gc, "%d", 1),
-                      "domain", libxl__domid_to_name(gc, domid), NULL);
+    flexarray_append_pair(back, "frontend-id", libxl__sprintf(gc, "%d", 
domid));
+    flexarray_append_pair(back, "online", "1");
+    flexarray_append_pair(back, "state", libxl__sprintf(gc, "%d", 1));
+    flexarray_append_pair(back, "domain", libxl__domid_to_name(gc, domid));
 
     for (i = 0; i < num; i++, pcidev++)
         libxl_create_pci_backend_device(gc, back, i, pcidev);
 
-    flexarray_vappend(back, "num_devs", libxl__sprintf(gc, "%d", num), NULL);
-
-    flexarray_vappend(front,
-                      "backend-id", libxl__sprintf(gc, "%d", 0),
-                      "state", libxl__sprintf(gc, "%d", 1), NULL);
+    flexarray_append_pair(back, "num_devs", libxl__sprintf(gc, "%d", num));
+    flexarray_append_pair(front, "backend-id", libxl__sprintf(gc, "%d", 0));
+    flexarray_append_pair(front, "state", libxl__sprintf(gc, "%d", 1));
 
     libxl__device_generic_add(ctx, &device,
                              libxl__xs_kvs_of_flexarray(gc, back, back->count),
@@ -311,9 +310,9 @@ static int libxl_device_pci_add_xenstore
     LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Adding new pci device to xenstore");
     num = atoi(num_devs);
     libxl_create_pci_backend_device(gc, back, num, pcidev);
-    flexarray_vappend(back, "num_devs", libxl__sprintf(gc, "%d", num + 1), 
NULL);
+    flexarray_append_pair(back, "num_devs", libxl__sprintf(gc, "%d", num + 1));
     if (!starting)
-        flexarray_vappend(back, "state", libxl__sprintf(gc, "%d", 7), NULL);
+        flexarray_append_pair(back, "state", libxl__sprintf(gc, "%d", 7));
 
 retry_transaction:
     t = xs_transaction_start(ctx->xsh);

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>