[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 01 of 10] pyxl: Fix reference counting of Py_(None|True|False)
tools/python/genwrap.py | 5 ++++- tools/python/xen/lowlevel/xl/xl.c | 12 +++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) # HG changeset patch # User Gianni Tedesco <gianni.tedesco@xxxxxxxxxx> # Date 1294761665 0 # Node ID 9ae3901ab42fd0458cf6150014e1f376a25493b5 # Parent 719ba64edad1d7226cd927bcfa65fff087544995 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> diff -r 719ba64edad1 -r 9ae3901ab42f tools/python/genwrap.py --- a/tools/python/genwrap.py Tue Jan 11 16:01:05 2011 +0000 +++ b/tools/python/genwrap.py Tue Jan 11 16:01:05 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 719ba64edad1 -r 9ae3901ab42f tools/python/xen/lowlevel/xl/xl.c --- a/tools/python/xen/lowlevel/xl/xl.c Tue Jan 11 16:01:05 2011 +0000 +++ b/tools/python/xen/lowlevel/xl/xl.c Tue Jan 11 16:01:05 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-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |