[Libvirt-cim] [PATCH] [RFC] Change interface of cu_return_instance{, name}s

Dan Smith danms at us.ibm.com
Mon Nov 19 19:57:54 UTC 2007


# HG changeset patch
# User Dan Smith <danms at us.ibm.com>
# Date 1195505862 28800
# Node ID f2c751be5069df9eb23a8bdbaafd5d55b3fd24e9
# Parent  25497386647b6e757ed5c8893f2a4c648543829b
[RFC] Change interface of cu_return_instance{,name}s
to use instance lists instead of null-terminated arrays.  These
functions existed before we had instance lists, and need to be
updated.

This will require another wide-sweeping (but trivial) change to libvirt-cim

Signed-off-by: Dan Smith <danms at us.ibm.com>

diff -r 25497386647b -r f2c751be5069 instance_util.c
--- a/instance_util.c	Mon Nov 19 08:00:42 2007 -0800
+++ b/instance_util.c	Mon Nov 19 12:57:42 2007 -0800
@@ -24,15 +24,15 @@
 #include "libcmpiutil.h"
 
 unsigned int cu_return_instances(const CMPIResult *results,
-                                 CMPIInstance ** const list)
+                                 const struct inst_list *list)
 {
         unsigned int i;
 
         if (list == NULL)
                 return 0;
 
-        for (i = 0; list[i] != NULL; i++)
-                CMReturnInstance(results, list[i]);
+        for (i = 0; i < list->cur; i++)
+                CMReturnInstance(results, list->list[i]);
 
         return i;
 }
@@ -54,19 +54,17 @@ bool cu_return_instance_name(const CMPIR
 }
 
 unsigned int cu_return_instance_names(const CMPIResult *results,
-                                      CMPIInstance ** const list)
+                                      const struct inst_list *list)
 {
         unsigned int i;
-        unsigned int c = 0;
 
         if (list == NULL)
                 return 0;
 
-        for (i = 0; list[i] != NULL; i++)
-                if (cu_return_instance_name(results, list[i]))
-                        c++;
+        for (i = 0; i < list->cur; i++)
+                cu_return_instance_name(results, list->list[i]);
 
-        return c;
+        return i;
 }
 
 static bool _compare_data(const CMPIData *a, const CMPIData *b)
diff -r 25497386647b -r f2c751be5069 libcmpiutil.h
--- a/libcmpiutil.h	Mon Nov 19 08:00:42 2007 -0800
+++ b/libcmpiutil.h	Mon Nov 19 12:57:42 2007 -0800
@@ -139,15 +139,18 @@ int cu_get_u16_path(const CMPIObjectPath
                     const char *key,
                     uint16_t *target);
 
+/* Forward declaration */
+struct inst_list;
+
 /**
  * Return a list of instances
  *
- * @param list A NULL-terminated list of instances
  * @param results The result list to populate
+ * @param list A list of instances to return
  * @returns The number of instances returned
  */
 unsigned int cu_return_instances(const CMPIResult *results,
-                                 CMPIInstance ** const list);
+                                 const struct inst_list *list);
 
 /**
  * Return an instance object path
@@ -163,13 +166,12 @@ bool cu_return_instance_name(const CMPIR
 /**
  * Return the object paths of a list of instances
  *
- * @param list A NULL-terminated list of instances
  * @param results The result list to populate
- * @param op The object path
+ * @param list A list of instances to return (names of)
  * @returns The number of instance names returned
  */
 unsigned int cu_return_instance_names(const CMPIResult *results,
-                                      CMPIInstance ** const list);
+                                      const struct inst_list *list);
 
 /**
  * Get a string property of an instance
diff -r 25497386647b -r f2c751be5069 std_association.c
--- a/std_association.c	Mon Nov 19 08:00:42 2007 -0800
+++ b/std_association.c	Mon Nov 19 12:57:42 2007 -0800
@@ -217,9 +217,9 @@ static CMPIStatus do_assoc(struct std_as
         }
 
         if (names_only)
-                cu_return_instance_names(results, list.list);
+                cu_return_instance_names(results, &list);
         else
-                cu_return_instances(results, list.list);
+                cu_return_instances(results, &list);
 
  out:
         inst_list_free(&list);




More information about the Libvirt-cim mailing list