1
0
mirror of https://gitlab.com/libvirt/libvirt-python.git synced 2025-08-04 12:21:57 +03:00

use VIR_PY_TUPLE_GOTO

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Pavel Hrdina
2015-09-24 15:21:53 +02:00
parent a3f842eea1
commit 827ed9b4f1

View File

@ -117,12 +117,17 @@ libvirt_virDomainBlockStats(PyObject *self ATTRIBUTE_UNUSED,
if ((info = PyTuple_New(5)) == NULL) if ((info = PyTuple_New(5)) == NULL)
return NULL; return NULL;
PyTuple_SetItem(info, 0, libvirt_longlongWrap(stats.rd_req)); VIR_PY_TUPLE_SET_GOTO(info, 0, libvirt_longlongWrap(stats.rd_req), error);
PyTuple_SetItem(info, 1, libvirt_longlongWrap(stats.rd_bytes)); VIR_PY_TUPLE_SET_GOTO(info, 1, libvirt_longlongWrap(stats.rd_bytes), error);
PyTuple_SetItem(info, 2, libvirt_longlongWrap(stats.wr_req)); VIR_PY_TUPLE_SET_GOTO(info, 2, libvirt_longlongWrap(stats.wr_req), error);
PyTuple_SetItem(info, 3, libvirt_longlongWrap(stats.wr_bytes)); VIR_PY_TUPLE_SET_GOTO(info, 3, libvirt_longlongWrap(stats.wr_bytes), error);
PyTuple_SetItem(info, 4, libvirt_longlongWrap(stats.errs)); VIR_PY_TUPLE_SET_GOTO(info, 4, libvirt_longlongWrap(stats.errs), error);
return info; return info;
error:
Py_DECREF(info);
return NULL;
} }
static PyObject * static PyObject *
@ -338,15 +343,20 @@ libvirt_virDomainInterfaceStats(PyObject *self ATTRIBUTE_UNUSED,
if ((info = PyTuple_New(8)) == NULL) if ((info = PyTuple_New(8)) == NULL)
return NULL; return NULL;
PyTuple_SetItem(info, 0, libvirt_longlongWrap(stats.rx_bytes)); VIR_PY_TUPLE_SET_GOTO(info, 0, libvirt_longlongWrap(stats.rx_bytes), error);
PyTuple_SetItem(info, 1, libvirt_longlongWrap(stats.rx_packets)); VIR_PY_TUPLE_SET_GOTO(info, 1, libvirt_longlongWrap(stats.rx_packets), error);
PyTuple_SetItem(info, 2, libvirt_longlongWrap(stats.rx_errs)); VIR_PY_TUPLE_SET_GOTO(info, 2, libvirt_longlongWrap(stats.rx_errs), error);
PyTuple_SetItem(info, 3, libvirt_longlongWrap(stats.rx_drop)); VIR_PY_TUPLE_SET_GOTO(info, 3, libvirt_longlongWrap(stats.rx_drop), error);
PyTuple_SetItem(info, 4, libvirt_longlongWrap(stats.tx_bytes)); VIR_PY_TUPLE_SET_GOTO(info, 4, libvirt_longlongWrap(stats.tx_bytes), error);
PyTuple_SetItem(info, 5, libvirt_longlongWrap(stats.tx_packets)); VIR_PY_TUPLE_SET_GOTO(info, 5, libvirt_longlongWrap(stats.tx_packets), error);
PyTuple_SetItem(info, 6, libvirt_longlongWrap(stats.tx_errs)); VIR_PY_TUPLE_SET_GOTO(info, 6, libvirt_longlongWrap(stats.tx_errs), error);
PyTuple_SetItem(info, 7, libvirt_longlongWrap(stats.tx_drop)); VIR_PY_TUPLE_SET_GOTO(info, 7, libvirt_longlongWrap(stats.tx_drop), error);
return info; return info;
error:
Py_DECREF(info);
return NULL;
} }
static PyObject * static PyObject *
@ -443,12 +453,17 @@ libvirt_virDomainGetSchedulerType(PyObject *self ATTRIBUTE_UNUSED,
if ((info = PyTuple_New(2)) == NULL) if ((info = PyTuple_New(2)) == NULL)
goto cleanup; goto cleanup;
PyTuple_SetItem(info, 0, libvirt_constcharPtrWrap(c_retval)); VIR_PY_TUPLE_SET_GOTO(info, 0, libvirt_constcharPtrWrap(c_retval), error);
PyTuple_SetItem(info, 1, libvirt_intWrap((long)nparams)); VIR_PY_TUPLE_SET_GOTO(info, 1, libvirt_intWrap((long)nparams), error);
cleanup: cleanup:
VIR_FREE(c_retval); VIR_FREE(c_retval);
return info; return info;
error:
Py_CLEAR(info);
goto cleanup;
} }
static PyObject * static PyObject *
@ -1240,18 +1255,15 @@ libvirt_virDomainGetVcpus(PyObject *self ATTRIBUTE_UNUSED,
if ((pycpuinfo = PyList_New(dominfo.nrVirtCpu)) == NULL) if ((pycpuinfo = PyList_New(dominfo.nrVirtCpu)) == NULL)
goto cleanup; goto cleanup;
if (PyTuple_SetItem(pyretval, 0, pycpuinfo) < 0) VIR_PY_TUPLE_SET_GOTO(pyretval, 0, pycpuinfo, cleanup);
goto cleanup;
if ((pycpumap = PyList_New(dominfo.nrVirtCpu)) == NULL) if ((pycpumap = PyList_New(dominfo.nrVirtCpu)) == NULL)
goto cleanup; goto cleanup;
if (PyTuple_SetItem(pyretval, 1, pycpumap) < 0) VIR_PY_TUPLE_SET_GOTO(pyretval, 1, pycpumap, cleanup);
goto cleanup;
for (i = 0; i < dominfo.nrVirtCpu; i++) { for (i = 0; i < dominfo.nrVirtCpu; i++) {
PyObject *info = PyTuple_New(4); PyObject *info = PyTuple_New(4);
PyObject *item = NULL;
if (info == NULL) if (info == NULL)
goto cleanup; goto cleanup;
@ -1259,21 +1271,15 @@ libvirt_virDomainGetVcpus(PyObject *self ATTRIBUTE_UNUSED,
if (PyList_SetItem(pycpuinfo, i, info) < 0) if (PyList_SetItem(pycpuinfo, i, info) < 0)
goto cleanup; goto cleanup;
if ((item = libvirt_intWrap((long)cpuinfo[i].number)) == NULL || VIR_PY_TUPLE_SET_GOTO(info, 0, libvirt_intWrap((long)cpuinfo[i].number),
PyTuple_SetItem(info, 0, item) < 0) cleanup);
goto cleanup; VIR_PY_TUPLE_SET_GOTO(info, 1, libvirt_intWrap((long)cpuinfo[i].state),
cleanup);
if ((item = libvirt_intWrap((long)cpuinfo[i].state)) == NULL || VIR_PY_TUPLE_SET_GOTO(info, 2,
PyTuple_SetItem(info, 1, item) < 0) libvirt_ulonglongWrap((long)cpuinfo[i].cpuTime),
goto cleanup; cleanup);
VIR_PY_TUPLE_SET_GOTO(info, 3, libvirt_intWrap((long)cpuinfo[i].cpu),
if ((item = libvirt_ulonglongWrap(cpuinfo[i].cpuTime)) == NULL || cleanup);
PyTuple_SetItem(info, 2, item) < 0)
goto cleanup;
if ((item = libvirt_intWrap((long)cpuinfo[i].cpu)) == NULL ||
PyTuple_SetItem(info, 3, item) < 0)
goto cleanup;
} }
for (i = 0; i < dominfo.nrVirtCpu; i++) { for (i = 0; i < dominfo.nrVirtCpu; i++) {
PyObject *info = PyTuple_New(cpunum); PyObject *info = PyTuple_New(cpunum);
@ -1285,11 +1291,11 @@ libvirt_virDomainGetVcpus(PyObject *self ATTRIBUTE_UNUSED,
goto cleanup; goto cleanup;
for (j = 0; j < cpunum; j++) { for (j = 0; j < cpunum; j++) {
PyObject *item = NULL; VIR_PY_TUPLE_SET_GOTO(info, j,
if ((item = PyBool_FromLong(VIR_CPU_USABLE(cpumap, cpumaplen, PyBool_FromLong(VIR_CPU_USABLE(cpumap,
i, j))) == NULL || cpumaplen,
PyTuple_SetItem(info, j, item) < 0) i, j)),
goto cleanup; cleanup);
} }
} }
@ -1486,9 +1492,13 @@ libvirt_virDomainGetVcpuPinInfo(PyObject *self ATTRIBUTE_UNUSED,
PyList_SetItem(pycpumaps, vcpu, mapinfo); PyList_SetItem(pycpumaps, vcpu, mapinfo);
for (pcpu = 0; pcpu < cpunum; pcpu++) { for (pcpu = 0; pcpu < cpunum; pcpu++) {
PyTuple_SetItem(mapinfo, pcpu, VIR_PY_TUPLE_SET_GOTO(mapinfo,
PyBool_FromLong(VIR_CPU_USABLE(cpumaps, cpumaplen, pcpu,
vcpu, pcpu))); PyBool_FromLong(VIR_CPU_USABLE(cpumaps,
cpumaplen,
vcpu,
pcpu)),
cleanup);
} }
} }
@ -1612,13 +1622,23 @@ libvirt_virDomainGetEmulatorPinInfo(PyObject *self ATTRIBUTE_UNUSED,
return NULL; return NULL;
} }
for (pcpu = 0; pcpu < cpunum; pcpu++) for (pcpu = 0; pcpu < cpunum; pcpu++) {
PyTuple_SET_ITEM(pycpumap, pcpu, VIR_PY_TUPLE_SET_GOTO(pycpumap,
PyBool_FromLong(VIR_CPU_USABLE(cpumap, cpumaplen, pcpu,
0, pcpu))); PyBool_FromLong(VIR_CPU_USABLE(cpumap,
cpumaplen,
0,
pcpu)),
error);
}
cleanup:
VIR_FREE(cpumap); VIR_FREE(cpumap);
return pycpumap; return pycpumap;
error:
Py_CLEAR(pycpumap);
goto cleanup;
} }
#endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */ #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */
@ -1660,7 +1680,6 @@ libvirt_virDomainGetIOThreadInfo(PyObject *self ATTRIBUTE_UNUSED,
/* NOTE: If there are zero IOThreads we will return an empty list */ /* NOTE: If there are zero IOThreads we will return an empty list */
for (i = 0; i < niothreads; i++) { for (i = 0; i < niothreads; i++) {
PyObject *iothrtpl = NULL; PyObject *iothrtpl = NULL;
PyObject *iothrid = NULL;
PyObject *iothrmap = NULL; PyObject *iothrmap = NULL;
virDomainIOThreadInfoPtr iothr = iothrinfo[i]; virDomainIOThreadInfoPtr iothr = iothrinfo[i];
@ -1676,18 +1695,15 @@ libvirt_virDomainGetIOThreadInfo(PyObject *self ATTRIBUTE_UNUSED,
} }
/* 0: IOThread ID */ /* 0: IOThread ID */
if ((iothrid = libvirt_uintWrap(iothr->iothread_id)) == NULL || VIR_PY_TUPLE_SET_GOTO(iothrtpl, 0, libvirt_uintWrap(iothr->iothread_id),
PyTuple_SetItem(iothrtpl, 0, iothrid) < 0) { cleanup);
Py_XDECREF(iothrid);
goto cleanup;
}
/* 1: CPU map */ /* 1: CPU map */
if ((iothrmap = PyList_New(cpunum)) == NULL || if ((iothrmap = PyList_New(cpunum)) == NULL)
PyTuple_SetItem(iothrtpl, 1, iothrmap) < 0) {
Py_XDECREF(iothrmap);
goto cleanup; goto cleanup;
}
VIR_PY_TUPLE_SET_GOTO(iothrtpl, 1, iothrmap, cleanup);
for (pcpu = 0; pcpu < cpunum; pcpu++) { for (pcpu = 0; pcpu < cpunum; pcpu++) {
PyObject *pyused; PyObject *pyused;
if ((pyused = PyBool_FromLong(VIR_CPU_USED(iothr->cpumap, if ((pyused = PyBool_FromLong(VIR_CPU_USED(iothr->cpumap,
@ -1802,17 +1818,21 @@ libvirt_virGetLastError(PyObject *self ATTRIBUTE_UNUSED,
if ((info = PyTuple_New(9)) == NULL) if ((info = PyTuple_New(9)) == NULL)
return NULL; return NULL;
PyTuple_SetItem(info, 0, libvirt_intWrap((long) err->code)); VIR_PY_TUPLE_SET_GOTO(info, 0, libvirt_intWrap((long)err->code), error);
PyTuple_SetItem(info, 1, libvirt_intWrap((long) err->domain)); VIR_PY_TUPLE_SET_GOTO(info, 1, libvirt_intWrap((long)err->domain), error);
PyTuple_SetItem(info, 2, libvirt_constcharPtrWrap(err->message)); VIR_PY_TUPLE_SET_GOTO(info, 2, libvirt_constcharPtrWrap(err->message), error);
PyTuple_SetItem(info, 3, libvirt_intWrap((long) err->level)); VIR_PY_TUPLE_SET_GOTO(info, 3, libvirt_intWrap((long)err->level), error);
PyTuple_SetItem(info, 4, libvirt_constcharPtrWrap(err->str1)); VIR_PY_TUPLE_SET_GOTO(info, 4, libvirt_constcharPtrWrap(err->str1), error);
PyTuple_SetItem(info, 5, libvirt_constcharPtrWrap(err->str2)); VIR_PY_TUPLE_SET_GOTO(info, 5, libvirt_constcharPtrWrap(err->str2), error);
PyTuple_SetItem(info, 6, libvirt_constcharPtrWrap(err->str3)); VIR_PY_TUPLE_SET_GOTO(info, 6, libvirt_constcharPtrWrap(err->str3), error);
PyTuple_SetItem(info, 7, libvirt_intWrap((long) err->int1)); VIR_PY_TUPLE_SET_GOTO(info, 7, libvirt_intWrap((long)err->int1), error);
PyTuple_SetItem(info, 8, libvirt_intWrap((long) err->int2)); VIR_PY_TUPLE_SET_GOTO(info, 8, libvirt_intWrap((long)err->int2), error);
return info; return info;
error:
Py_XDECREF(info);
return NULL;
} }
static PyObject * static PyObject *
@ -1837,17 +1857,21 @@ libvirt_virConnGetLastError(PyObject *self ATTRIBUTE_UNUSED,
if ((info = PyTuple_New(9)) == NULL) if ((info = PyTuple_New(9)) == NULL)
return NULL; return NULL;
PyTuple_SetItem(info, 0, libvirt_intWrap((long) err->code)); VIR_PY_TUPLE_SET_GOTO(info, 0, libvirt_intWrap((long)err->code), error);
PyTuple_SetItem(info, 1, libvirt_intWrap((long) err->domain)); VIR_PY_TUPLE_SET_GOTO(info, 1, libvirt_intWrap((long)err->domain), error);
PyTuple_SetItem(info, 2, libvirt_constcharPtrWrap(err->message)); VIR_PY_TUPLE_SET_GOTO(info, 2, libvirt_constcharPtrWrap(err->message), error);
PyTuple_SetItem(info, 3, libvirt_intWrap((long) err->level)); VIR_PY_TUPLE_SET_GOTO(info, 3, libvirt_intWrap((long)err->level), error);
PyTuple_SetItem(info, 4, libvirt_constcharPtrWrap(err->str1)); VIR_PY_TUPLE_SET_GOTO(info, 4, libvirt_constcharPtrWrap(err->str1), error);
PyTuple_SetItem(info, 5, libvirt_constcharPtrWrap(err->str2)); VIR_PY_TUPLE_SET_GOTO(info, 5, libvirt_constcharPtrWrap(err->str2), error);
PyTuple_SetItem(info, 6, libvirt_constcharPtrWrap(err->str3)); VIR_PY_TUPLE_SET_GOTO(info, 6, libvirt_constcharPtrWrap(err->str3), error);
PyTuple_SetItem(info, 7, libvirt_intWrap((long) err->int1)); VIR_PY_TUPLE_SET_GOTO(info, 7, libvirt_intWrap((long)err->int1), error);
PyTuple_SetItem(info, 8, libvirt_intWrap((long) err->int2)); VIR_PY_TUPLE_SET_GOTO(info, 8, libvirt_intWrap((long)err->int2), error);
return info; return info;
error:
Py_XDECREF(info);
return NULL;
} }
static void static void
@ -1873,22 +1897,23 @@ libvirt_virErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx,
goto cleanup; goto cleanup;
Py_XINCREF(libvirt_virPythonErrorFuncCtxt); Py_XINCREF(libvirt_virPythonErrorFuncCtxt);
PyTuple_SetItem(list, 0, libvirt_virPythonErrorFuncCtxt); VIR_PY_TUPLE_SET_GOTO(list, 0, libvirt_virPythonErrorFuncCtxt, cleanup);
if ((info = PyTuple_New(9)) == NULL) if ((info = PyTuple_New(9)) == NULL)
goto cleanup; goto cleanup;
PyTuple_SetItem(list, 1, info); VIR_PY_TUPLE_SET_GOTO(list, 1, info, cleanup);
VIR_PY_TUPLE_SET_GOTO(info, 0, libvirt_intWrap((long)err->code), cleanup);
VIR_PY_TUPLE_SET_GOTO(info, 1, libvirt_intWrap((long)err->domain), cleanup);
VIR_PY_TUPLE_SET_GOTO(info, 2, libvirt_constcharPtrWrap(err->message), cleanup);
VIR_PY_TUPLE_SET_GOTO(info, 3, libvirt_intWrap((long)err->level), cleanup);
VIR_PY_TUPLE_SET_GOTO(info, 4, libvirt_constcharPtrWrap(err->str1), cleanup);
VIR_PY_TUPLE_SET_GOTO(info, 5, libvirt_constcharPtrWrap(err->str2), cleanup);
VIR_PY_TUPLE_SET_GOTO(info, 6, libvirt_constcharPtrWrap(err->str3), cleanup);
VIR_PY_TUPLE_SET_GOTO(info, 7, libvirt_intWrap((long)err->int1), cleanup);
VIR_PY_TUPLE_SET_GOTO(info, 8, libvirt_intWrap((long)err->int2), cleanup);
PyTuple_SetItem(info, 0, libvirt_intWrap((long) err->code));
PyTuple_SetItem(info, 1, libvirt_intWrap((long) err->domain));
PyTuple_SetItem(info, 2, libvirt_constcharPtrWrap(err->message));
PyTuple_SetItem(info, 3, libvirt_intWrap((long) err->level));
PyTuple_SetItem(info, 4, libvirt_constcharPtrWrap(err->str1));
PyTuple_SetItem(info, 5, libvirt_constcharPtrWrap(err->str2));
PyTuple_SetItem(info, 6, libvirt_constcharPtrWrap(err->str3));
PyTuple_SetItem(info, 7, libvirt_intWrap((long) err->int1));
PyTuple_SetItem(info, 8, libvirt_intWrap((long) err->int2));
/* TODO pass conn and dom if available */ /* TODO pass conn and dom if available */
result = PyEval_CallObject(libvirt_virPythonErrorFuncHandler, list); result = PyEval_CallObject(libvirt_virPythonErrorFuncHandler, list);
Py_XDECREF(result); Py_XDECREF(result);
@ -1960,14 +1985,15 @@ virConnectCredCallbackWrapper(virConnectCredentialPtr cred,
if ((pycred = PyTuple_New(ncred)) == NULL) if ((pycred = PyTuple_New(ncred)) == NULL)
goto cleanup; goto cleanup;
PyTuple_SetItem(list, 0, pycred); VIR_PY_TUPLE_SET_GOTO(list, 0, pycred, cleanup);
for (i = 0; i < ncred; i++) { for (i = 0; i < ncred; i++) {
PyObject *pycreditem; PyObject *pycreditem;
if ((pycreditem = PyList_New(5)) == NULL) if ((pycreditem = PyList_New(5)) == NULL)
goto cleanup; goto cleanup;
PyTuple_SetItem(pycred, i, pycreditem); VIR_PY_TUPLE_SET_GOTO(pycred, i, pycreditem, cleanup);
PyList_SetItem(pycreditem, 0, libvirt_intWrap((long) cred[i].type)); PyList_SetItem(pycreditem, 0, libvirt_intWrap((long) cred[i].type));
PyList_SetItem(pycreditem, 1, libvirt_constcharPtrWrap(cred[i].prompt)); PyList_SetItem(pycreditem, 1, libvirt_constcharPtrWrap(cred[i].prompt));
if (cred[i].challenge) { if (cred[i].challenge) {
@ -1986,7 +2012,7 @@ virConnectCredCallbackWrapper(virConnectCredentialPtr cred,
} }
Py_XINCREF(pycbdata); Py_XINCREF(pycbdata);
PyTuple_SetItem(list, 1, pycbdata); VIR_PY_TUPLE_SET_GOTO(list, 1, pycbdata, cleanup);
PyErr_Clear(); PyErr_Clear();
pyret = PyEval_CallObject(pycb, list); pyret = PyEval_CallObject(pycb, list);
@ -5215,9 +5241,6 @@ libvirt_virEventAddHandleFunc(int fd,
virFreeCallback ff) virFreeCallback ff)
{ {
PyObject *result; PyObject *result;
PyObject *cb_obj;
PyObject *ff_obj;
PyObject *opaque_obj;
PyObject *python_cb = NULL; PyObject *python_cb = NULL;
PyObject *cb_args = NULL; PyObject *cb_args = NULL;
PyObject *pyobj_args = NULL; PyObject *pyobj_args = NULL;
@ -5228,8 +5251,8 @@ libvirt_virEventAddHandleFunc(int fd,
if ((pyobj_args = PyTuple_New(4)) == NULL) if ((pyobj_args = PyTuple_New(4)) == NULL)
goto cleanup; goto cleanup;
PyTuple_SetItem(pyobj_args, 0, libvirt_intWrap(fd)); VIR_PY_TUPLE_SET_GOTO(pyobj_args, 0, libvirt_intWrap(fd), cleanup);
PyTuple_SetItem(pyobj_args, 1, libvirt_intWrap(event)); VIR_PY_TUPLE_SET_GOTO(pyobj_args, 1, libvirt_intWrap(event), cleanup);
/* Lookup the python callback */ /* Lookup the python callback */
python_cb = libvirt_lookupPythonFunc("_eventInvokeHandleCallback"); python_cb = libvirt_lookupPythonFunc("_eventInvokeHandleCallback");
@ -5238,20 +5261,16 @@ libvirt_virEventAddHandleFunc(int fd,
} }
Py_INCREF(python_cb); Py_INCREF(python_cb);
PyTuple_SetItem(pyobj_args, 2, python_cb); VIR_PY_TUPLE_SET_GOTO(pyobj_args, 2, python_cb, cleanup);
if ((cb_args = PyTuple_New(3)) == NULL) if ((cb_args = PyTuple_New(3)) == NULL)
goto cleanup; goto cleanup;
PyTuple_SetItem(pyobj_args, 3, cb_args); VIR_PY_TUPLE_SET_GOTO(pyobj_args, 3, cb_args, cleanup);
/* create tuple for cb */ VIR_PY_TUPLE_SET_GOTO(cb_args, 0, libvirt_virEventHandleCallbackWrap(cb), cleanup);
cb_obj = libvirt_virEventHandleCallbackWrap(cb); VIR_PY_TUPLE_SET_GOTO(cb_args, 1, libvirt_virVoidPtrWrap(opaque), cleanup);
ff_obj = libvirt_virFreeCallbackWrap(ff); VIR_PY_TUPLE_SET_GOTO(cb_args, 2, libvirt_virFreeCallbackWrap(ff), cleanup);
opaque_obj = libvirt_virVoidPtrWrap(opaque);
PyTuple_SetItem(cb_args, 0, cb_obj);
PyTuple_SetItem(cb_args, 1, opaque_obj);
PyTuple_SetItem(cb_args, 2, ff_obj);
result = PyEval_CallObject(addHandleObj, pyobj_args); result = PyEval_CallObject(addHandleObj, pyobj_args);
if (!result) { if (!result) {
@ -5283,8 +5302,8 @@ libvirt_virEventUpdateHandleFunc(int watch,
if ((pyobj_args = PyTuple_New(2)) == NULL) if ((pyobj_args = PyTuple_New(2)) == NULL)
goto cleanup; goto cleanup;
PyTuple_SetItem(pyobj_args, 0, libvirt_intWrap(watch)); VIR_PY_TUPLE_SET_GOTO(pyobj_args, 0, libvirt_intWrap(watch), cleanup);
PyTuple_SetItem(pyobj_args, 1, libvirt_intWrap(event)); VIR_PY_TUPLE_SET_GOTO(pyobj_args, 1, libvirt_intWrap(event), cleanup);
result = PyEval_CallObject(updateHandleObj, pyobj_args); result = PyEval_CallObject(updateHandleObj, pyobj_args);
if (!result) { if (!result) {
@ -5315,7 +5334,7 @@ libvirt_virEventRemoveHandleFunc(int watch)
if ((pyobj_args = PyTuple_New(1)) == NULL) if ((pyobj_args = PyTuple_New(1)) == NULL)
goto cleanup; goto cleanup;
PyTuple_SetItem(pyobj_args, 0, libvirt_intWrap(watch)); VIR_PY_TUPLE_SET_GOTO(pyobj_args, 0, libvirt_intWrap(watch), cleanup);
result = PyEval_CallObject(removeHandleObj, pyobj_args); result = PyEval_CallObject(removeHandleObj, pyobj_args);
if (!result) { if (!result) {
@ -5350,9 +5369,6 @@ libvirt_virEventAddTimeoutFunc(int timeout,
void *opaque, void *opaque,
virFreeCallback ff) virFreeCallback ff)
{ {
PyObject *cb_obj;
PyObject *ff_obj;
PyObject *opaque_obj;
PyObject *result = NULL; PyObject *result = NULL;
PyObject *python_cb = NULL; PyObject *python_cb = NULL;
PyObject *cb_args = NULL; PyObject *cb_args = NULL;
@ -5364,7 +5380,7 @@ libvirt_virEventAddTimeoutFunc(int timeout,
if ((pyobj_args = PyTuple_New(3)) == NULL) if ((pyobj_args = PyTuple_New(3)) == NULL)
goto cleanup; goto cleanup;
PyTuple_SetItem(pyobj_args, 0, libvirt_intWrap(timeout)); VIR_PY_TUPLE_SET_GOTO(pyobj_args, 0, libvirt_intWrap(timeout), cleanup);
/* Lookup the python callback */ /* Lookup the python callback */
python_cb = libvirt_lookupPythonFunc("_eventInvokeTimeoutCallback"); python_cb = libvirt_lookupPythonFunc("_eventInvokeTimeoutCallback");
@ -5372,20 +5388,16 @@ libvirt_virEventAddTimeoutFunc(int timeout,
goto cleanup; goto cleanup;
} }
Py_INCREF(python_cb); Py_INCREF(python_cb);
PyTuple_SetItem(pyobj_args, 1, python_cb); VIR_PY_TUPLE_SET_GOTO(pyobj_args, 1, python_cb, cleanup);
if ((cb_args = PyTuple_New(3)) == NULL) if ((cb_args = PyTuple_New(3)) == NULL)
goto cleanup; goto cleanup;
PyTuple_SetItem(pyobj_args, 2, cb_args); VIR_PY_TUPLE_SET_GOTO(pyobj_args, 2, cb_args, cleanup);
/* create tuple for cb */ VIR_PY_TUPLE_SET_GOTO(cb_args, 0, libvirt_virEventTimeoutCallbackWrap(cb), cleanup);
cb_obj = libvirt_virEventTimeoutCallbackWrap(cb); VIR_PY_TUPLE_SET_GOTO(cb_args, 1, libvirt_virVoidPtrWrap(opaque), cleanup);
ff_obj = libvirt_virFreeCallbackWrap(ff); VIR_PY_TUPLE_SET_GOTO(cb_args, 2, libvirt_virFreeCallbackWrap(ff), cleanup);
opaque_obj = libvirt_virVoidPtrWrap(opaque);
PyTuple_SetItem(cb_args, 0, cb_obj);
PyTuple_SetItem(cb_args, 1, opaque_obj);
PyTuple_SetItem(cb_args, 2, ff_obj);
result = PyEval_CallObject(addTimeoutObj, pyobj_args); result = PyEval_CallObject(addTimeoutObj, pyobj_args);
if (!result) { if (!result) {
@ -5415,8 +5427,8 @@ libvirt_virEventUpdateTimeoutFunc(int timer,
if ((pyobj_args = PyTuple_New(2)) == NULL) if ((pyobj_args = PyTuple_New(2)) == NULL)
goto cleanup; goto cleanup;
PyTuple_SetItem(pyobj_args, 0, libvirt_intWrap(timer)); VIR_PY_TUPLE_SET_GOTO(pyobj_args, 0, libvirt_intWrap(timer), cleanup);
PyTuple_SetItem(pyobj_args, 1, libvirt_intWrap(timeout)); VIR_PY_TUPLE_SET_GOTO(pyobj_args, 1, libvirt_intWrap(timeout), cleanup);
result = PyEval_CallObject(updateTimeoutObj, pyobj_args); result = PyEval_CallObject(updateTimeoutObj, pyobj_args);
if (!result) { if (!result) {
@ -5446,7 +5458,7 @@ libvirt_virEventRemoveTimeoutFunc(int timer)
if ((pyobj_args = PyTuple_New(1)) == NULL) if ((pyobj_args = PyTuple_New(1)) == NULL)
goto cleanup; goto cleanup;
PyTuple_SetItem(pyobj_args, 0, libvirt_intWrap(timer)); VIR_PY_TUPLE_SET_GOTO(pyobj_args, 0, libvirt_intWrap(timer), cleanup);
result = PyEval_CallObject(removeTimeoutObj, pyobj_args); result = PyEval_CallObject(removeTimeoutObj, pyobj_args);
if (!result) { if (!result) {
@ -6114,11 +6126,12 @@ libvirt_virConnectDomainEventGraphicsCallback(virConnectPtr conn ATTRIBUTE_UNUSE
PyList_SetItem(pyobj_subject, i, pair); PyList_SetItem(pyobj_subject, i, pair);
PyTuple_SetItem(pair, 0, VIR_PY_TUPLE_SET_GOTO(pair, 0,
libvirt_constcharPtrWrap(subject->identities[i].type)); libvirt_constcharPtrWrap(subject->identities[i].type),
PyTuple_SetItem(pair, 1, cleanup);
libvirt_constcharPtrWrap(subject->identities[i].name)); VIR_PY_TUPLE_SET_GOTO(pair, 1,
libvirt_constcharPtrWrap(subject->identities[i].name),
cleanup);
} }
/* Call the Callback Dispatcher */ /* Call the Callback Dispatcher */
@ -7647,8 +7660,6 @@ libvirt_virNodeGetCPUMap(PyObject *self ATTRIBUTE_UNUSED,
PyObject *ret = NULL; PyObject *ret = NULL;
PyObject *pycpumap = NULL; PyObject *pycpumap = NULL;
PyObject *pyused = NULL; PyObject *pyused = NULL;
PyObject *pycpunum = NULL;
PyObject *pyonline = NULL;
int i_retval; int i_retval;
unsigned char *cpumap = NULL; unsigned char *cpumap = NULL;
unsigned int online = 0; unsigned int online = 0;
@ -7671,16 +7682,13 @@ libvirt_virNodeGetCPUMap(PyObject *self ATTRIBUTE_UNUSED,
goto error; goto error;
/* 0: number of CPUs */ /* 0: number of CPUs */
if ((pycpunum = libvirt_intWrap(i_retval)) == NULL || VIR_PY_TUPLE_SET_GOTO(ret, 0, libvirt_intWrap(i_retval), error);
PyTuple_SetItem(ret, 0, pycpunum) < 0)
goto error;
/* 1: CPU map */ /* 1: CPU map */
if ((pycpumap = PyList_New(i_retval)) == NULL) if ((pycpumap = PyList_New(i_retval)) == NULL)
goto error; goto error;
if (PyTuple_SetItem(ret, 1, pycpumap) < 0) VIR_PY_TUPLE_SET_GOTO(ret, 1, pycpumap, error);
goto error;
for (i = 0; i < i_retval; i++) { for (i = 0; i < i_retval; i++) {
if ((pyused = PyBool_FromLong(VIR_CPU_USED(cpumap, i))) == NULL) if ((pyused = PyBool_FromLong(VIR_CPU_USED(cpumap, i))) == NULL)
@ -7690,9 +7698,7 @@ libvirt_virNodeGetCPUMap(PyObject *self ATTRIBUTE_UNUSED,
} }
/* 2: number of online CPUs */ /* 2: number of online CPUs */
if ((pyonline = libvirt_uintWrap(online)) == NULL || VIR_PY_TUPLE_SET_GOTO(ret, 2, libvirt_uintWrap(online), error);
PyTuple_SetItem(ret, 2, pyonline) < 0)
goto error;
cleanup: cleanup:
VIR_FREE(cpumap); VIR_FREE(cpumap);
@ -8196,7 +8202,6 @@ convertDomainStatsRecord(virDomainStatsRecordPtr *records,
{ {
PyObject *py_retval; PyObject *py_retval;
PyObject *py_record; PyObject *py_record;
PyObject *py_record_domain = NULL;
PyObject *py_record_stats = NULL; PyObject *py_record_stats = NULL;
size_t i; size_t i;
@ -8212,20 +8217,15 @@ convertDomainStatsRecord(virDomainStatsRecordPtr *records,
/* libvirt_virDomainPtrWrap steals the object */ /* libvirt_virDomainPtrWrap steals the object */
virDomainRef(records[i]->dom); virDomainRef(records[i]->dom);
if (!(py_record_domain = libvirt_virDomainPtrWrap(records[i]->dom))) { VIR_PY_TUPLE_SET_GOTO(py_record, 0,
virDomainFree(records[i]->dom); libvirt_virDomainPtrWrap(records[i]->dom),
goto error; error);
}
if (PyTuple_SetItem(py_record, 0, py_record_domain) < 0)
goto error;
if (!(py_record_stats = getPyVirTypedParameter(records[i]->params, if (!(py_record_stats = getPyVirTypedParameter(records[i]->params,
records[i]->nparams))) records[i]->nparams)))
goto error; goto error;
VIR_PY_TUPLE_SET_GOTO(py_record, 1, py_record_stats, error);
if (PyTuple_SetItem(py_record, 1, py_record_stats) < 0)
goto error;
} }
return py_retval; return py_retval;
@ -8460,15 +8460,17 @@ libvirt_virDomainGetFSInfo(PyObject *self ATTRIBUTE_UNUSED,
PyList_SetItem(py_retval, i, info); PyList_SetItem(py_retval, i, info);
PyTuple_SetItem(info, 0, libvirt_constcharPtrWrap(fs->mountpoint)); VIR_PY_TUPLE_SET_GOTO(info, 0,
PyTuple_SetItem(info, 1, libvirt_constcharPtrWrap(fs->name)); libvirt_constcharPtrWrap(fs->mountpoint), error);
PyTuple_SetItem(info, 2, libvirt_constcharPtrWrap(fs->fstype)); VIR_PY_TUPLE_SET_GOTO(info, 1,
libvirt_constcharPtrWrap(fs->name), error);
VIR_PY_TUPLE_SET_GOTO(info, 2,
libvirt_constcharPtrWrap(fs->fstype), error);
alias = PyList_New(0); alias = PyList_New(0);
if (alias == NULL) if (alias == NULL)
goto error; goto error;
VIR_PY_TUPLE_SET_GOTO(info, 3, alias, error);
PyTuple_SetItem(info, 3, alias);
for (j = 0; j < fs->ndevAlias; j++) for (j = 0; j < fs->ndevAlias; j++)
if (PyList_Append(alias, if (PyList_Append(alias,