[libvirt] [PATCH python] override: GetCPUModelNames should return None on failure

Right now, on failure, libvirt.py doesn't raise an exception and just returns -1 to the user. --- libvirt-override.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libvirt-override.c b/libvirt-override.c index 7f746ed..9fed299 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -2326,7 +2326,7 @@ libvirt_virConnectGetCPUModelNames(PyObject *self ATTRIBUTE_UNUSED, LIBVIRT_END_ALLOW_THREADS; if (c_retval == -1) - return VIR_PY_INT_FAIL; + return VIR_PY_NONE; if ((rv = PyList_New(c_retval)) == NULL) goto error; -- 1.8.5.3

On 03/20/2014 11:28 AM, Cole Robinson wrote:
Right now, on failure, libvirt.py doesn't raise an exception and just returns -1 to the user. --- libvirt-override.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libvirt-override.c b/libvirt-override.c index 7f746ed..9fed299 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -2326,7 +2326,7 @@ libvirt_virConnectGetCPUModelNames(PyObject *self ATTRIBUTE_UNUSED, LIBVIRT_END_ALLOW_THREADS;
if (c_retval == -1) - return VIR_PY_INT_FAIL; + return VIR_PY_NONE;
Incomplete. The error: label needs the same treatment. ACK with that fix. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 03/20/2014 01:52 PM, Eric Blake wrote:
On 03/20/2014 11:28 AM, Cole Robinson wrote:
Right now, on failure, libvirt.py doesn't raise an exception and just returns -1 to the user. --- libvirt-override.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libvirt-override.c b/libvirt-override.c index 7f746ed..9fed299 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -2326,7 +2326,7 @@ libvirt_virConnectGetCPUModelNames(PyObject *self ATTRIBUTE_UNUSED, LIBVIRT_END_ALLOW_THREADS;
if (c_retval == -1) - return VIR_PY_INT_FAIL; + return VIR_PY_NONE;
Incomplete. The error: label needs the same treatment.
ACK with that fix.
Good catch. Fixed and pushed - Cole

On 03/20/2014 11:52 AM, Eric Blake wrote:
On 03/20/2014 11:28 AM, Cole Robinson wrote:
Right now, on failure, libvirt.py doesn't raise an exception and just returns -1 to the user. --- libvirt-override.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libvirt-override.c b/libvirt-override.c index 7f746ed..9fed299 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -2326,7 +2326,7 @@ libvirt_virConnectGetCPUModelNames(PyObject *self ATTRIBUTE_UNUSED, LIBVIRT_END_ALLOW_THREADS;
if (c_retval == -1) - return VIR_PY_INT_FAIL; + return VIR_PY_NONE;
Incomplete. The error: label needs the same treatment.
ACK with that fix.
Actually, I take that back. We need a v2. If the error: label is reached, returning VIR_PY_INT_FAIL is wrong; but so is returning VIR_PY_NONE. We _want_ to return NULL in that case, because the error label is called only after a python failure (PyList_New or libvirt_constcharPtrWrap, which generally means OOM) - and python failures are distinguished by returning NULL (reserving -1/None for libvirt failures). -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (2)
-
Cole Robinson
-
Eric Blake