On RHEL 5, with libxml2-2.6.26, the build failed with:
virsh.c: In function 'vshNodeIsSuperset':
virsh.c:11951: warning: implicit declaration of function 'xmlChildElementCount'
(or if warnings aren't errors, a link failure later on).
* src/util/xml.h (virXMLChildElementCount): New prototype.
* src/util/xml.c (virXMLChildElementCount): New function.
* src/libvirt_private.syms (xml.h): Export it.
* tools/virsh.c (vshNodeIsSuperset): Use it.
---
I haven't decided yet whether this is trivial enough to push under
the build-breaker rule, but it did fix my build on RHEL 5.
src/libvirt_private.syms | 1 +
src/util/xml.c | 20 ++++++++++++++++++++
src/util/xml.h | 1 +
tools/virsh.c | 9 +++++----
4 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 99a1099..a81c230 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1400,6 +1400,7 @@ virTimeStringThenRaw;
# xml.h
+virXMLChildElementCount;
virXMLParseHelper;
virXMLPropString;
virXMLSaveFile;
diff --git a/src/util/xml.c b/src/util/xml.c
index 4e98b05..2909e85 100644
--- a/src/util/xml.c
+++ b/src/util/xml.c
@@ -833,3 +833,23 @@ virXMLSaveFile(const char *path,
return virFileRewrite(path, S_IRUSR | S_IWUSR, virXMLRewriteFile, &data);
}
+
+/* Returns the number of children of node, or -1 on error. */
+long
+virXMLChildElementCount(xmlNodePtr node)
+{
+ long ret = 0;
+ xmlNodePtr cur = NULL;
+
+ /* xmlChildElementCount returns 0 on error, which isn't helpful;
+ * besides, it is not available in libxml2 2.6. */
+ if (!node || node->type != XML_ELEMENT_NODE)
+ return -1;
+ cur = node->children;
+ while (cur) {
+ if (cur->type == XML_ELEMENT_NODE)
+ ret++;
+ cur = cur->next;
+ }
+ return ret;
+}
diff --git a/src/util/xml.h b/src/util/xml.h
index c492063..a3750fa 100644
--- a/src/util/xml.h
+++ b/src/util/xml.h
@@ -52,6 +52,7 @@ int virXPathNodeSet(const char *xpath,
xmlNodePtr **list);
char * virXMLPropString(xmlNodePtr node,
const char *name);
+long virXMLChildElementCount(xmlNodePtr node);
/* Internal function; prefer the macros below. */
xmlDocPtr virXMLParseHelper(int domcode,
diff --git a/tools/virsh.c b/tools/virsh.c
index d02be5c..a51478f 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -11919,7 +11919,7 @@ vshNodeIsSuperset(xmlNodePtr n1, xmlNodePtr n2)
bool found;
bool visited;
bool ret = false;
- unsigned long n1_child_size, n2_child_size, n1_iter;
+ long n1_child_size, n2_child_size, n1_iter;
virBitmapPtr bitmap;
if (!n1 && !n2)
@@ -11948,9 +11948,10 @@ vshNodeIsSuperset(xmlNodePtr n1, xmlNodePtr n2)
attr = attr->next;
}
- n1_child_size = xmlChildElementCount(n1);
- n2_child_size = xmlChildElementCount(n2);
- if (n1_child_size < n2_child_size)
+ n1_child_size = virXMLChildElementCount(n1);
+ n2_child_size = virXMLChildElementCount(n2);
+ if (n1_child_size < 0 || n2_child_size < 0 ||
+ n1_child_size < n2_child_size)
return false;
if (n1_child_size == 0 && n2_child_size == 0)
--
1.7.7.3