Re: [libvirt] [PATCH v2] python: add virDomainGetCPUStats python binding API

2012-03-21 Thread Guannan Ren
On 03/21/2012 10:01 PM, Eric Blake wrote: Only if we want to be sticklers. For reference, in C, void foo(bool x); can be called with a bool (foo(true) or foo(false)), an int (foo(1) or foo(0)), a pointer (foo("") or foo(NULL)). That is, C gives you automatic conversion. In Java, you _have_

Re: [libvirt] [PATCH v2] python: add virDomainGetCPUStats python binding API

2012-03-21 Thread Eric Blake
On 03/21/2012 07:47 AM, Guannan Ren wrote: > I get your points, sorry I don't express my idea clearly. > According to my experience, for PyObject_IsTrue, all of non-null > objects > belongs to True, null objects like {}, ""(str) ,None, False > counts as False, Correct. > it

Re: [libvirt] [PATCH v2] python: add virDomainGetCPUStats python binding API

2012-03-21 Thread Guannan Ren
On 03/21/2012 09:23 PM, Eric Blake wrote: On 03/21/2012 07:22 AM, Guannan Ren wrote: On 03/21/2012 08:07 PM, Eric Blake wrote: Maybe we need a wrapper: int libvirt_boolUnwrap(PyObject *obj, bool *value) { int ret = PyObject_IsTrue(obj); if (ret< 0) return ret; *va

Re: [libvirt] [PATCH v2] python: add virDomainGetCPUStats python binding API

2012-03-21 Thread Eric Blake
On 03/21/2012 07:22 AM, Guannan Ren wrote: > On 03/21/2012 08:07 PM, Eric Blake wrote: >> Maybe we need a wrapper: >> >> int libvirt_boolUnwrap(PyObject *obj, bool *value) { >> int ret = PyObject_IsTrue(obj); >> if (ret< 0) >> return ret; >> *value = ret> 0; >> return

Re: [libvirt] [PATCH v2] python: add virDomainGetCPUStats python binding API

2012-03-21 Thread Guannan Ren
On 03/21/2012 08:07 PM, Eric Blake wrote: Maybe we need a wrapper: int libvirt_boolUnwrap(PyObject *obj, bool *value) { int ret = PyObject_IsTrue(obj); if (ret< 0) return ret; *value = ret> 0; return 0; } and then callers become: if (libvirt_boolUnwrap(value

Re: [libvirt] [PATCH v2] python: add virDomainGetCPUStats python binding API

2012-03-21 Thread Eric Blake
On 03/21/2012 01:35 AM, Guannan Ren wrote: > will become: > if (PyBool_Check(value)) { Why do we have to require a PyBool? My reading of PyObject_IsTrue is that it can convert other python objects to a boolean truth value, which is more flexible. > temp->value.

Re: [libvirt] [PATCH v2] python: add virDomainGetCPUStats python binding API

2012-03-21 Thread Guannan Ren
On 03/20/2012 01:36 AM, Eric Blake wrote: On 03/18/2012 04:41 AM, Guannan Ren wrote: +if (totalbool == Py_False) { Per other code in libvirt-override.c, you can't compare totalbool (type PyObject) with Py_False, at least not on all compilers. You need something like this instead:

Re: [libvirt] [PATCH v2] python: add virDomainGetCPUStats python binding API

2012-03-19 Thread Eric Blake
On 03/18/2012 04:41 AM, Guannan Ren wrote: >>> +if (totalbool == Py_False) { >> Per other code in libvirt-override.c, you can't compare totalbool (type >> PyObject) with Py_False, at least not on all compilers. You need >> something like this instead: >> >> /* Hack - Python's def

Re: [libvirt] [PATCH v2] python: add virDomainGetCPUStats python binding API

2012-03-18 Thread Guannan Ren
On 03/17/2012 01:42 AM, Eric Blake wrote: On 03/16/2012 11:26 AM, Eric Blake wrote: + +if (!nparams) { +if ((cpu = PyDict_New()) == NULL) { +error = NULL; Initialize error to NULL at the front, and you won't have to set it here. +goto failed

Re: [libvirt] [PATCH v2] python: add virDomainGetCPUStats python binding API

2012-03-18 Thread Guannan Ren
On 03/17/2012 01:26 AM, Eric Blake wrote: On 03/14/2012 07:03 AM, Guannan Ren wrote: dom.getCPUStats(True, 0) [{'cpu_time': 92913537401L, 'system_time': 547000L, 'user_time': 31000L}] dom.getCPUStats(False, 0) [{'cpu_time': 39476858499L}, {'cpu_time': 1062704837

Re: [libvirt] [PATCH v2] python: add virDomainGetCPUStats python binding API

2012-03-16 Thread Eric Blake
On 03/16/2012 11:26 AM, Eric Blake wrote: > >> + >> +if (!nparams) { >> +if ((cpu = PyDict_New()) == NULL) { >> +error = NULL; > > Initialize error to NULL at the front, and you won't have to set it here. > >> +goto failed; >> +} >>

Re: [libvirt] [PATCH v2] python: add virDomainGetCPUStats python binding API

2012-03-16 Thread Eric Blake
On 03/14/2012 07:03 AM, Guannan Ren wrote: > dom.getCPUStats(True, 0) > [{'cpu_time': 92913537401L, 'system_time': 547000L, 'user_time': > 31000L}] > > dom.getCPUStats(False, 0) > [{'cpu_time': 39476858499L}, {'cpu_time': 10627048370L}, {'cpu_time': > 21270945682L}, {

Re: [libvirt] [PATCH v2] python: add virDomainGetCPUStats python binding API

2012-03-15 Thread Guannan Ren
Is there anyone who would like to review this :) On 03/14/2012 09:03 PM, Guannan Ren wrote: dom.getCPUStats(True, 0) [{'cpu_time': 92913537401L, 'system_time': 547000L, 'user_time': 31000L}] dom.getCPUStats(False, 0) [{'cpu_time': 39476858499L}, {'cpu_time'

[libvirt] [PATCH v2] python: add virDomainGetCPUStats python binding API

2012-03-14 Thread Guannan Ren
dom.getCPUStats(True, 0) [{'cpu_time': 92913537401L, 'system_time': 547000L, 'user_time': 31000L}] dom.getCPUStats(False, 0) [{'cpu_time': 39476858499L}, {'cpu_time': 10627048370L}, {'cpu_time': 21270945682L}, {'cpu_time': 21556420641L}] *generator.py Add a new n