On 03/01/2013 03:03 AM, Guannan Ren wrote:
The subject line is long, and has a typo. I'd suggest:
python: fix bindings that don't raise an exception
For example:
>>> dom.memoryStats()
libvir: QEMU Driver error : Requested operation is not valid:\
domain is not running
There are six such python API functions like so.
The root reason is that generator.py script checks the type of return
value of a python stub function defined in libvirt-api.xml or
libvirt-override-api.xml to see whether adding the raise clause or not
s/adding/to add/
in python wrapper code in libvirt.py.
The type of return value is supposed to be C types.
For those stub functions which return python non-integer data type like
string, list, tuple, dictionary, the existing type in functions varies
from each other which leads problem like this.
Currently, in generator.py, it maintains a buggy whitelist for stub functions
returning a list type. I think it is easy to forget adding new function name
in the whitelist.
This patch makes the value of type consistent with C type "char *"
in libvirt-override-api.xml. For python, any of types could be printed
as string, so I choose "char *"in this case. And the comment in xml
s/*"in/*" in/
could explain it when adding new function definition.
<function name='virNodeGetCPUStats' file='python'>
...
- <return type='virNodeCPUStats' info='...'/>
+ <return type='char *' info='...'/>
...
</function>
---
python/generator.py | 10 ++--
python/libvirt-override-api.xml | 116 +++++++++++++++++++++-------------------
2 files changed, 66 insertions(+), 60 deletions(-)
+++ b/python/libvirt-override-api.xml
@@ -1,5 +1,13 @@
<?xml version="1.0"?>
<api name='libvir-python'>
+ <!-- This file lists libvirt API functions whose Python stubs are written by hand
+ in libvirt-override.c, but the Python-level code are still automatically
generated
+ by generator.py script.
s/by/by the/
+
+ The type of return value is supposed to be C types. If a function's stub will
return
s/C types/a C type/
+ a python non-integer data type like string, list, tuple,
dictionary, etc,
+ please using "char *" as the type of its return value.
s/using/use/
Long lines. Please wrap these two comment paragraphs to fit in 80 columns.
ACK with those changes.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library
http://libvirt.org