direct-io.hg

changeset 14428:7521c87983e0

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>
author Keir Fraser <keir@xensource.com>
date Sun Mar 18 16:49:52 2007 +0000 (2007-03-18)
parents 9df276596cbb
children 2b58c9e32549
files tools/python/xen/lowlevel/xc/xc.c
line diff
     1.1 --- a/tools/python/xen/lowlevel/xc/xc.c	Sun Mar 18 12:06:50 2007 +0000
     1.2 +++ b/tools/python/xen/lowlevel/xc/xc.c	Sun Mar 18 16:49:52 2007 +0000
     1.3 @@ -50,17 +50,21 @@ static PyObject *pyxc_error_to_exception
     1.4      const xc_error *err = xc_get_last_error();
     1.5      const char *desc = xc_error_code_to_desc(err->code);
     1.6  
     1.7 -    if (err->code == XC_ERROR_NONE)
     1.8 +    if ( err->code == XC_ERROR_NONE )
     1.9          return PyErr_SetFromErrno(xc_error_obj);
    1.10  
    1.11 -    if (err->message[0] != '\0')
    1.12 +    if ( err->message[0] != '\0' )
    1.13  	pyerr = Py_BuildValue("(iss)", err->code, desc, err->message);
    1.14      else
    1.15  	pyerr = Py_BuildValue("(is)", err->code, desc);
    1.16  
    1.17      xc_clear_last_error();
    1.18  
    1.19 -    PyErr_SetObject(xc_error_obj, pyerr);
    1.20 +    if ( pyerr != NULL )
    1.21 +    {
    1.22 +        PyErr_SetObject(xc_error_obj, pyerr);
    1.23 +        Py_DECREF(pyerr);
    1.24 +    }
    1.25  
    1.26      return NULL;
    1.27  }
    1.28 @@ -70,13 +74,13 @@ static PyObject *pyxc_domain_dumpcore(Xc
    1.29      uint32_t dom;
    1.30      char *corefile;
    1.31  
    1.32 -    if (!PyArg_ParseTuple(args, "is", &dom, &corefile))
    1.33 +    if ( !PyArg_ParseTuple(args, "is", &dom, &corefile) )
    1.34          return NULL;
    1.35  
    1.36      if ( (corefile == NULL) || (corefile[0] == '\0') )
    1.37          return NULL;
    1.38  
    1.39 -    if (xc_domain_dumpcore(self->xc_handle, dom, corefile) != 0)
    1.40 +    if ( xc_domain_dumpcore(self->xc_handle, dom, corefile) != 0 )
    1.41          return pyxc_error_to_exception();
    1.42      
    1.43      Py_INCREF(zero);
    1.44 @@ -168,10 +172,10 @@ static PyObject *pyxc_domain_shutdown(Xc
    1.45  {
    1.46      uint32_t dom, reason;
    1.47  
    1.48 -    if (!PyArg_ParseTuple(args, "ii", &dom, &reason))
    1.49 +    if ( !PyArg_ParseTuple(args, "ii", &dom, &reason) )
    1.50        return NULL;
    1.51  
    1.52 -    if (xc_domain_shutdown(self->xc_handle, dom, reason) != 0)
    1.53 +    if ( xc_domain_shutdown(self->xc_handle, dom, reason) != 0 )
    1.54          return pyxc_error_to_exception();
    1.55      
    1.56      Py_INCREF(zero);
    1.57 @@ -183,10 +187,10 @@ static PyObject *pyxc_domain_resume(XcOb
    1.58      uint32_t dom;
    1.59      int fast;
    1.60  
    1.61 -    if (!PyArg_ParseTuple(args, "ii", &dom, &fast))
    1.62 +    if ( !PyArg_ParseTuple(args, "ii", &dom, &fast) )
    1.63          return NULL;
    1.64  
    1.65 -    if (xc_domain_resume(self->xc_handle, dom, fast) != 0)
    1.66 +    if ( xc_domain_resume(self->xc_handle, dom, fast) != 0 )
    1.67          return pyxc_error_to_exception();
    1.68  
    1.69      Py_INCREF(zero);
    1.70 @@ -282,7 +286,7 @@ static PyObject *pyxc_domain_getinfo(XcO
    1.71                                       PyObject *args,
    1.72                                       PyObject *kwds)
    1.73  {
    1.74 -    PyObject *list, *info_dict;
    1.75 +    PyObject *list, *info_dict, *pyhandle;
    1.76  
    1.77      uint32_t first_dom = 0;
    1.78      int max_doms = 1024, nr_doms, i, j;
    1.79 @@ -308,12 +312,9 @@ static PyObject *pyxc_domain_getinfo(XcO
    1.80      list = PyList_New(nr_doms);
    1.81      for ( i = 0 ; i < nr_doms; i++ )
    1.82      {
    1.83 -        PyObject *pyhandle = PyList_New(sizeof(xen_domain_handle_t));
    1.84 -        for ( j = 0; j < sizeof(xen_domain_handle_t); j++ )
    1.85 -            PyList_SetItem(pyhandle, j, PyInt_FromLong(info[i].handle[j]));
    1.86          info_dict = Py_BuildValue(
    1.87 -            "{s:i,s:I,s:I,s:i,s:i,s:i,s:i,s:i,s:i,s:i"
    1.88 -            ",s:k,s:L,s:k,s:i,s:I}",
    1.89 +            "{s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i"
    1.90 +            ",s:k,s:L,s:k,s:i,s:i}",
    1.91              "domid",           (int)info[i].domid,
    1.92              "online_vcpus",    info[i].nr_online_vcpus,
    1.93              "max_vcpu_id",     info[i].max_vcpu_id,
    1.94 @@ -324,12 +325,21 @@ static PyObject *pyxc_domain_getinfo(XcO
    1.95              "paused",          info[i].paused,
    1.96              "blocked",         info[i].blocked,
    1.97              "running",         info[i].running,
    1.98 -            
    1.99              "mem_kb",          info[i].nr_pages*(XC_PAGE_SIZE/1024),
   1.100              "cpu_time",        (long long)info[i].cpu_time,
   1.101              "maxmem_kb",       info[i].max_memkb,
   1.102              "ssidref",         (int)info[i].ssidref,
   1.103              "shutdown_reason", info[i].shutdown_reason);
   1.104 +        pyhandle = PyList_New(sizeof(xen_domain_handle_t));
   1.105 +        if ( (pyhandle == NULL) || (info_dict == NULL) )
   1.106 +        {
   1.107 +            Py_DECREF(list);
   1.108 +            if ( pyhandle  != NULL ) { Py_DECREF(pyhandle);  }
   1.109 +            if ( info_dict != NULL ) { Py_DECREF(info_dict); }
   1.110 +            return NULL;
   1.111 +        }
   1.112 +        for ( j = 0; j < sizeof(xen_domain_handle_t); j++ )
   1.113 +            PyList_SetItem(pyhandle, j, PyInt_FromLong(info[i].handle[j]));
   1.114          PyDict_SetItemString(info_dict, "handle", pyhandle);
   1.115          Py_DECREF(pyhandle);
   1.116          PyList_SetItem(list, i, info_dict);