[libvirt] [PATCH] remove a static limit on max domains in python bindings

Daniel Veillard veillard at redhat.com
Thu Dec 29 08:22:17 UTC 2011


On Thu, Dec 29, 2011 at 12:36:14PM +0800, Osier Yang wrote:
> On 2011年12月29日 09:56, Daniel Veillard wrote:
> >* python/libvirt-override.c: remove the predefined array in the
> >   virConnectListDomainsID binding and call virConnectNumOfDomains
> >   to do a proper allocation
> >
> >diff --git a/python/libvirt-override.c b/python/libvirt-override.c
> >index 8a643a3..2dea16b 100644
> >--- a/python/libvirt-override.c
> >+++ b/python/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,34 @@ 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)
> 
> Intention problems, should be caused by TAB use.

  yeah, apparently I forgot to copy my .vimrc to the laptop :)

> >+	    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);
> >  }
> >
> >Daniel
> 
> ACK with the TAB use replaced by 4 white spaces.

  Thanks, fixed and commited,

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel at veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/




More information about the libvir-list mailing list