summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@redhat.com>2011-12-29 16:20:00 +0800
committerDaniel Veillard <veillard@redhat.com>2011-12-29 16:20:00 +0800
commit4ef433f8359c32411cb0a76ff276c8b02eb4e73b (patch)
tree473519d9c23c81974b324204389e64b1fe8f4e3d
parent370bcd017bbe2d55edc9123a3f3a03764c6579cc (diff)
downloadlibvirt-python-v6-4ef433f8359c32411cb0a76ff276c8b02eb4e73b.tar.gz
libvirt-python-v6-4ef433f8359c32411cb0a76ff276c8b02eb4e73b.tar.xz
libvirt-python-v6-4ef433f8359c32411cb0a76ff276c8b02eb4e73b.zip
remove a static limit on max domains in python bindings
* python/libvirt-override.c: remove the predefined array in the virConnectListDomainsID binding and call virConnectNumOfDomains to do a proper allocation
-rw-r--r--libvirt-override.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/libvirt-override.c b/libvirt-override.c
index a704e78..d2aad0f 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -1616,7 +1616,7 @@ static PyObject *
libvirt_virConnectListDomainsID(PyObject *self ATTRIBUTE_UNUSED,
PyObject *args) {
PyObject *py_retval;
- int ids[500], c_retval, i;
+ int *ids = NULL, c_retval, i;
virConnectPtr conn;
PyObject *pyobj_conn;
@@ -1626,14 +1626,33 @@ libvirt_virConnectListDomainsID(PyObject *self ATTRIBUTE_UNUSED,
conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
LIBVIRT_BEGIN_ALLOW_THREADS;
- c_retval = virConnectListDomains(conn, &ids[0], 500);
+ c_retval = virConnectNumOfDomains(conn);
LIBVIRT_END_ALLOW_THREADS;
if (c_retval < 0)
return VIR_PY_NONE;
+
+ if (c_retval) {
+ ids = malloc(sizeof(*ids) * c_retval);
+ if (!ids)
+ return VIR_PY_NONE;
+
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ c_retval = virConnectListDomains(conn, ids, c_retval);
+ LIBVIRT_END_ALLOW_THREADS;
+ if (c_retval < 0) {
+ free(ids);
+ return VIR_PY_NONE;
+ }
+ }
py_retval = PyList_New(c_retval);
- for (i = 0;i < c_retval;i++) {
- PyList_SetItem(py_retval, i, libvirt_intWrap(ids[i]));
+
+ if (ids) {
+ for (i = 0;i < c_retval;i++) {
+ PyList_SetItem(py_retval, i, libvirt_intWrap(ids[i]));
+ }
+ free(ids);
}
+
return(py_retval);
}