mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 02:30:03 +01:00
xend: Fix Py_BuildValue() invocation (don't use I specifier).
Various error-handlign cleanup and fix a reference leakage. Signed-off-by: Keir Fraser <keir@xensource.com>
This commit is contained in:
1 parent
5515b59042
commit
2cea532bee
1 file changed
+26
-16
@@ -50,17 +50,21 @@ static PyObject *pyxc_error_to_exception(void)
|
||||
const xc_error *err = xc_get_last_error();
|
||||
const char *desc = xc_error_code_to_desc(err->code);
|
||||
|
||||
if (err->code == XC_ERROR_NONE)
|
||||
if ( err->code == XC_ERROR_NONE )
|
||||
return PyErr_SetFromErrno(xc_error_obj);
|
||||
|
||||
if (err->message[0] != '\0')
|
||||
if ( err->message[0] != '\0' )
|
||||
pyerr = Py_BuildValue("(iss)", err->code, desc, err->message);
|
||||
else
|
||||
pyerr = Py_BuildValue("(is)", err->code, desc);
|
||||
|
||||
xc_clear_last_error();
|
||||
|
||||
PyErr_SetObject(xc_error_obj, pyerr);
|
||||
if ( pyerr != NULL )
|
||||
{
|
||||
PyErr_SetObject(xc_error_obj, pyerr);
|
||||
Py_DECREF(pyerr);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -70,13 +74,13 @@ static PyObject *pyxc_domain_dumpcore(XcObject *self, PyObject *args)
|
||||
uint32_t dom;
|
||||
char *corefile;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "is", &dom, &corefile))
|
||||
if ( !PyArg_ParseTuple(args, "is", &dom, &corefile) )
|
||||
return NULL;
|
||||
|
||||
if ( (corefile == NULL) || (corefile[0] == '\0') )
|
||||
return NULL;
|
||||
|
||||
if (xc_domain_dumpcore(self->xc_handle, dom, corefile) != 0)
|
||||
if ( xc_domain_dumpcore(self->xc_handle, dom, corefile) != 0 )
|
||||
return pyxc_error_to_exception();
|
||||
|
||||
Py_INCREF(zero);
|
||||
@@ -168,10 +172,10 @@ static PyObject *pyxc_domain_shutdown(XcObject *self, PyObject *args)
|
||||
{
|
||||
uint32_t dom, reason;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "ii", &dom, &reason))
|
||||
if ( !PyArg_ParseTuple(args, "ii", &dom, &reason) )
|
||||
return NULL;
|
||||
|
||||
if (xc_domain_shutdown(self->xc_handle, dom, reason) != 0)
|
||||
if ( xc_domain_shutdown(self->xc_handle, dom, reason) != 0 )
|
||||
return pyxc_error_to_exception();
|
||||
|
||||
Py_INCREF(zero);
|
||||
@@ -183,10 +187,10 @@ static PyObject *pyxc_domain_resume(XcObject *self, PyObject *args)
|
||||
uint32_t dom;
|
||||
int fast;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "ii", &dom, &fast))
|
||||
if ( !PyArg_ParseTuple(args, "ii", &dom, &fast) )
|
||||
return NULL;
|
||||
|
||||
if (xc_domain_resume(self->xc_handle, dom, fast) != 0)
|
||||
if ( xc_domain_resume(self->xc_handle, dom, fast) != 0 )
|
||||
return pyxc_error_to_exception();
|
||||
|
||||
Py_INCREF(zero);
|
||||
@@ -282,7 +286,7 @@ static PyObject *pyxc_domain_getinfo(XcObject *self,
|
||||
PyObject *args,
|
||||
PyObject *kwds)
|
||||
{
|
||||
PyObject *list, *info_dict;
|
||||
PyObject *list, *info_dict, *pyhandle;
|
||||
|
||||
uint32_t first_dom = 0;
|
||||
int max_doms = 1024, nr_doms, i, j;
|
||||
@@ -308,12 +312,9 @@ static PyObject *pyxc_domain_getinfo(XcObject *self,
|
||||
list = PyList_New(nr_doms);
|
||||
for ( i = 0 ; i < nr_doms; i++ )
|
||||
{
|
||||
PyObject *pyhandle = PyList_New(sizeof(xen_domain_handle_t));
|
||||
for ( j = 0; j < sizeof(xen_domain_handle_t); j++ )
|
||||
PyList_SetItem(pyhandle, j, PyInt_FromLong(info[i].handle[j]));
|
||||
info_dict = Py_BuildValue(
|
||||
"{s:i,s:I,s:I,s:i,s:i,s:i,s:i,s:i,s:i,s:i"
|
||||
",s:k,s:L,s:k,s:i,s:I}",
|
||||
"{s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i"
|
||||
",s:k,s:L,s:k,s:i,s:i}",
|
||||
"domid", (int)info[i].domid,
|
||||
"online_vcpus", info[i].nr_online_vcpus,
|
||||
"max_vcpu_id", info[i].max_vcpu_id,
|
||||
@@ -324,12 +325,21 @@ static PyObject *pyxc_domain_getinfo(XcObject *self,
|
||||
"paused", info[i].paused,
|
||||
"blocked", info[i].blocked,
|
||||
"running", info[i].running,
|
||||
|
||||
"mem_kb", info[i].nr_pages*(XC_PAGE_SIZE/1024),
|
||||
"cpu_time", (long long)info[i].cpu_time,
|
||||
"maxmem_kb", info[i].max_memkb,
|
||||
"ssidref", (int)info[i].ssidref,
|
||||
"shutdown_reason", info[i].shutdown_reason);
|
||||
pyhandle = PyList_New(sizeof(xen_domain_handle_t));
|
||||
if ( (pyhandle == NULL) || (info_dict == NULL) )
|
||||
{
|
||||
Py_DECREF(list);
|
||||
if ( pyhandle != NULL ) { Py_DECREF(pyhandle); }
|
||||
if ( info_dict != NULL ) { Py_DECREF(info_dict); }
|
||||
return NULL;
|
||||
}
|
||||
for ( j = 0; j < sizeof(xen_domain_handle_t); j++ )
|
||||
PyList_SetItem(pyhandle, j, PyInt_FromLong(info[i].handle[j]));
|
||||
PyDict_SetItemString(info_dict, "handle", pyhandle);
|
||||
Py_DECREF(pyhandle);
|
||||
PyList_SetItem(list, i, info_dict);
|
||||
|
||||