[Libvir] python/libvir.c returning wrong value on error?

Daniel Veillard veillard at redhat.com
Thu Feb 7 09:49:19 UTC 2008


On Wed, Feb 06, 2008 at 05:35:09PM -0500, Cole Robinson wrote:
> Daniel P. Berrange wrote:
> > On Wed, Feb 06, 2008 at 03:18:13PM -0500, Cole Robinson wrote:
> >> Hi all,
> >>
> >> Looking at python/libvir.c, all the custom functions return VIR_PY_NONE
> >> on error. This unfortunately doesn't map well to some of the
> >> generated python bindings which expect an error val of -1. So if these
> >> commands fail, no exception will be thrown at the python level.
> >> (Ex. virDomainGetAutostart, virDomainGetVcpus and their python equiv.)
> >>
> >> I'm wondering where the fix should be: in python/libvir.c, changing
> >> these error return values, or in the generator somewhere?
> > 
> > The fix should be in the libvir.c file - I didn't write this custom
> > bindings correctly. Simply remove the line
> > 
> >     if (c_retval < 0)
> >         return VIR_PY_NONE;
> > 
> > So 'c_retval' will get propagated back to the pure python layer which
> > will do the -1 check
> > 
> > Regards,
> > Dan.
> 
> Hmm, I don't think any of the cases where there is an error actually
> end up returning c_retval, its always python wrapped contents of
> something passed by reference, so I don't know how that would work.
> 
> The patch below seems to do the job: I tested it with the autostart
> function on a xen domain (which errors as its not supported) and it
> now correctly throws an exception from the python bindings.

  Okay, this is similar to changing a void public API to an int returning
one, it makes sense, and should be no problem, patch is very clean, so
great ! I applied it and commited it to CVS,

  thanks !

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
veillard at redhat.com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/




More information about the libvir-list mailing list