[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libvir] Python bindings, errors & exceptions

Daniel Veillard wrote:
On Fri, Mar 23, 2007 at 01:28:36PM +0000, Richard W.M. Jones wrote:
Daniel P. Berrange wrote:
Actually looks like it is the generated code actually. The generator.py
appears to only add in the 'raise libvirtError' stuff if the return value
is a virConnectPtr/virDomainPtr/virNeworkPtr  object - any other function
with a non-object return value gives back None upon error.
The generator.py code as it stands doesn't deal with the case where a function is prototyped (in C) as returning 'int'.

If I were to modify generator.py so that it adds the check for functions returning int, then it doesn't work because there is not enough information from just the C return type to tell what the Python return type will be.

  Right and that's why the automatic generator does not raise exception
automatically. For example getMaxMem could return -1 to mean unlimited
(e.g. on Domain 0) which is a correct return code in my opinion and
should not be considered and error, while getMem returning -1 should
really mean an error occured.
  No way automatic code could catch the subtle difference.

getMaxMem definitely sounds like a problem. I wouldn't have spotted that on my own.

We could do some run-time type magic in the generated wrapper, although that seems evil.

  At best keep a list of functions where one would not want to generate
exception automatically.

Yes, I'm working on this.



Emerging Technologies, Red Hat  http://et.redhat.com/~rjones/
64 Baker Street, London, W1U 7DF     Mobile: +44 7866 314 421
 "[Negative numbers] darken the very whole doctrines of the equations
 and make dark of the things which are in their nature excessively
 obvious and simple" (Francis Maseres FRS, mathematician, 1759)

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]