debuggers.hg

changeset 22772:00ed5639701a

tools/python/pyxl: Fix reference counting of Py_(None|True|False)

The incorrect refcounting causes the python interpreter to crash

Signed-off-by: Gianni Tedesco <gianni.tedesco@citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Gianni Tedesco <gianni.tedesco@citrix.com>
date Tue Jan 11 18:54:44 2011 +0000 (2011-01-11)
parents b0c06d6e176d
children 99da390ace2e
files tools/python/genwrap.py tools/python/xen/lowlevel/xl/xl.c
line diff
     1.1 --- a/tools/python/genwrap.py	Tue Jan 11 18:52:21 2011 +0000
     1.2 +++ b/tools/python/genwrap.py	Tue Jan 11 18:54:44 2011 +0000
     1.3 @@ -51,7 +51,10 @@ def py_attrib_get(ty, f):
     1.4      l.append('static PyObject *py_%s_%s_get(Py_%s *self, void *priv)'%(ty.rawname, f.name, ty.rawname))
     1.5      l.append('{')
     1.6      if t == TYPE_BOOL:
     1.7 -        l.append('    return (self->obj.%s) ? Py_True : Py_False;'%f.name)
     1.8 +        l.append('    PyObject *ret;')
     1.9 +        l.append('    ret = (self->obj.%s) ? Py_True : Py_False;'%f.name)
    1.10 +        l.append('    Py_INCREF(ret);')
    1.11 +        l.append('    return ret;')
    1.12      elif t == TYPE_INT:
    1.13          l.append('    return genwrap__ll_get(self->obj.%s);'%f.name)
    1.14      elif t == TYPE_UINT:
     2.1 --- a/tools/python/xen/lowlevel/xl/xl.c	Tue Jan 11 18:52:21 2011 +0000
     2.2 +++ b/tools/python/xen/lowlevel/xl/xl.c	Tue Jan 11 18:54:44 2011 +0000
     2.3 @@ -97,8 +97,10 @@ int genwrap__string_set(PyObject *v, cha
     2.4  
     2.5  PyObject *genwrap__string_get(char **str)
     2.6  {
     2.7 -    if ( NULL == *str )
     2.8 +    if ( NULL == *str ) {
     2.9 +        Py_INCREF(Py_None);
    2.10          return Py_None;
    2.11 +    }
    2.12      return PyString_FromString(*str);
    2.13  }
    2.14  
    2.15 @@ -377,6 +379,7 @@ static PyObject *pyxl_list_domains(XlObj
    2.16          if ( NULL == di )
    2.17              goto err_mem;
    2.18          memcpy(&di->obj, cur, sizeof(di->obj));
    2.19 +        /* SetItem steals a reference */
    2.20          PyList_SetItem(list, i, (PyObject *)di);
    2.21      }
    2.22  
    2.23 @@ -413,6 +416,7 @@ static PyObject *pyxl_domain_shutdown(Xl
    2.24          PyErr_SetString(xl_error_obj, "cannot shutdown domain");
    2.25          return NULL;
    2.26      }
    2.27 +    Py_INCREF(Py_None);
    2.28      return Py_None;
    2.29  }
    2.30  
    2.31 @@ -425,6 +429,7 @@ static PyObject *pyxl_domain_destroy(XlO
    2.32          PyErr_SetString(xl_error_obj, "cannot destroy domain");
    2.33          return NULL;
    2.34      }
    2.35 +    Py_INCREF(Py_None);
    2.36      return Py_None;
    2.37  }
    2.38  
    2.39 @@ -437,6 +442,7 @@ static PyObject *pyxl_domain_pause(XlObj
    2.40          PyErr_SetString(xl_error_obj, "cannot pause domain");
    2.41          return NULL;
    2.42      }
    2.43 +    Py_INCREF(Py_None);
    2.44      return Py_None;
    2.45  }
    2.46  
    2.47 @@ -449,6 +455,7 @@ static PyObject *pyxl_domain_unpause(XlO
    2.48          PyErr_SetString(xl_error_obj, "cannot unpause domain");
    2.49          return NULL;
    2.50      }
    2.51 +    Py_INCREF(Py_None);
    2.52      return Py_None;
    2.53  }
    2.54  
    2.55 @@ -462,6 +469,7 @@ static PyObject *pyxl_domain_rename(XlOb
    2.56          PyErr_SetString(xl_error_obj, "cannot rename domain");
    2.57          return NULL;
    2.58      }
    2.59 +    Py_INCREF(Py_None);
    2.60      return Py_None;
    2.61  }
    2.62  
    2.63 @@ -481,6 +489,7 @@ static PyObject *pyxl_pci_add(XlObject *
    2.64          PyErr_SetString(xl_error_obj, "cannot add pci device");
    2.65          return NULL;
    2.66      }
    2.67 +    Py_INCREF(Py_None);
    2.68      return Py_None;
    2.69  }
    2.70  
    2.71 @@ -501,6 +510,7 @@ static PyObject *pyxl_pci_del(XlObject *
    2.72          PyErr_SetString(xl_error_obj, "cannot remove pci device");
    2.73          return NULL;
    2.74      }
    2.75 +    Py_INCREF(Py_None);
    2.76      return Py_None;
    2.77  }
    2.78