[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] tools/python/pyxl: Fix reference counting of Py_(None|True|False)
# HG changeset patch # User Gianni Tedesco <gianni.tedesco@xxxxxxxxxx> # Date 1294772084 0 # Node ID 00ed5639701a2c4ca66e1d6ebc84d0eff0606a73 # Parent b0c06d6e176d31ab3742f266da05efba3770e9a6 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@xxxxxxxxxx> Committed-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> --- tools/python/genwrap.py | 5 ++++- tools/python/xen/lowlevel/xl/xl.c | 12 +++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff -r b0c06d6e176d -r 00ed5639701a tools/python/genwrap.py --- a/tools/python/genwrap.py Tue Jan 11 18:52:21 2011 +0000 +++ b/tools/python/genwrap.py Tue Jan 11 18:54:44 2011 +0000 @@ -51,7 +51,10 @@ def py_attrib_get(ty, f): l.append('static PyObject *py_%s_%s_get(Py_%s *self, void *priv)'%(ty.rawname, f.name, ty.rawname)) l.append('{') if t == TYPE_BOOL: - l.append(' return (self->obj.%s) ? Py_True : Py_False;'%f.name) + l.append(' PyObject *ret;') + l.append(' ret = (self->obj.%s) ? Py_True : Py_False;'%f.name) + l.append(' Py_INCREF(ret);') + l.append(' return ret;') elif t == TYPE_INT: l.append(' return genwrap__ll_get(self->obj.%s);'%f.name) elif t == TYPE_UINT: diff -r b0c06d6e176d -r 00ed5639701a tools/python/xen/lowlevel/xl/xl.c --- a/tools/python/xen/lowlevel/xl/xl.c Tue Jan 11 18:52:21 2011 +0000 +++ b/tools/python/xen/lowlevel/xl/xl.c Tue Jan 11 18:54:44 2011 +0000 @@ -97,8 +97,10 @@ int genwrap__string_set(PyObject *v, cha PyObject *genwrap__string_get(char **str) { - if ( NULL == *str ) + if ( NULL == *str ) { + Py_INCREF(Py_None); return Py_None; + } return PyString_FromString(*str); } @@ -377,6 +379,7 @@ static PyObject *pyxl_list_domains(XlObj if ( NULL == di ) goto err_mem; memcpy(&di->obj, cur, sizeof(di->obj)); + /* SetItem steals a reference */ PyList_SetItem(list, i, (PyObject *)di); } @@ -413,6 +416,7 @@ static PyObject *pyxl_domain_shutdown(Xl PyErr_SetString(xl_error_obj, "cannot shutdown domain"); return NULL; } + Py_INCREF(Py_None); return Py_None; } @@ -425,6 +429,7 @@ static PyObject *pyxl_domain_destroy(XlO PyErr_SetString(xl_error_obj, "cannot destroy domain"); return NULL; } + Py_INCREF(Py_None); return Py_None; } @@ -437,6 +442,7 @@ static PyObject *pyxl_domain_pause(XlObj PyErr_SetString(xl_error_obj, "cannot pause domain"); return NULL; } + Py_INCREF(Py_None); return Py_None; } @@ -449,6 +455,7 @@ static PyObject *pyxl_domain_unpause(XlO PyErr_SetString(xl_error_obj, "cannot unpause domain"); return NULL; } + Py_INCREF(Py_None); return Py_None; } @@ -462,6 +469,7 @@ static PyObject *pyxl_domain_rename(XlOb PyErr_SetString(xl_error_obj, "cannot rename domain"); return NULL; } + Py_INCREF(Py_None); return Py_None; } @@ -481,6 +489,7 @@ static PyObject *pyxl_pci_add(XlObject * PyErr_SetString(xl_error_obj, "cannot add pci device"); return NULL; } + Py_INCREF(Py_None); return Py_None; } @@ -501,6 +510,7 @@ static PyObject *pyxl_pci_del(XlObject * PyErr_SetString(xl_error_obj, "cannot remove pci device"); return NULL; } + Py_INCREF(Py_None); return Py_None; } _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |