When pass None or a empty dictionary to time, it will
report error.Allow a one-element dictionary which
contains 'seconds',setting JUST seconds will do the
sane thing of passing 0 for nseconds, instead of
erroring out.If dict have a unkown key, it will report error.
Signed-off-by: Luyao Huang <lhuang(a)redhat.com>
---
libvirt-override-virDomain.py | 6 +++---
libvirt-override.c | 41 +++++++++++++++++++++++++++++------------
2 files changed, 32 insertions(+), 15 deletions(-)
diff --git a/libvirt-override-virDomain.py b/libvirt-override-virDomain.py
index a50ec0d..2a4c4c9 100644
--- a/libvirt-override-virDomain.py
+++ b/libvirt-override-virDomain.py
@@ -66,9 +66,9 @@
if ret == -1: raise libvirtError ('virDomainGetTime() failed', dom=self)
return ret
- def setTime(self, time=None, flags=0):
- """Set guest time to the given value. @time is a dict conatining
- 'seconds' field for seconds and 'nseconds' field for nanosecons
"""
+ def setTime(self, time, flags=0):
+ """Set guest time to the given value. @time is a dict containing
+ 'seconds' field for seconds and 'nseconds' field for nanoseconds
"""
ret = libvirtmod.virDomainSetTime(self._o, time, flags)
if ret == -1: raise libvirtError ('virDomainSetTime() failed', dom=self)
return ret
diff --git a/libvirt-override.c b/libvirt-override.c
index a53b46f..1d1714a 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -7784,6 +7784,8 @@ static PyObject *
libvirt_virDomainSetTime(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
PyObject *py_retval = NULL;
PyObject *pyobj_domain;
+ PyObject *pyobj_seconds;
+ PyObject *pyobj_nseconds;
PyObject *py_dict;
virDomainPtr domain;
long long seconds = 0;
@@ -7797,25 +7799,40 @@ libvirt_virDomainSetTime(PyObject *self ATTRIBUTE_UNUSED, PyObject
*args) {
return NULL;
domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
- py_dict_size = PyDict_Size(py_dict);
+ if (!PyDict_Check(py_dict)) {
+ PyErr_Format(PyExc_TypeError, "time must be dict");
+ return NULL;
+ }
- if (py_dict_size == 2) {
- PyObject *pyobj_seconds, *pyobj_nseconds;
+ py_dict_size = PyDict_Size(py_dict);
- if (!(pyobj_seconds = PyDict_GetItemString(py_dict, "seconds")) ||
- (libvirt_longlongUnwrap(pyobj_seconds, &seconds) < 0)) {
- PyErr_Format(PyExc_LookupError, "malformed or missing
'seconds'");
+ if ((pyobj_seconds = PyDict_GetItemString(py_dict, "seconds")) != NULL) {
+ if (libvirt_longlongUnwrap(pyobj_seconds, &seconds) < 0) {
+ PyErr_Format(PyExc_LookupError, "malformed 'seconds'");
goto cleanup;
}
+ } else {
+ PyErr_Format(PyExc_LookupError, "Dictionary must contains "
+ "'seconds'");
+ goto cleanup;
+ }
- if (!(pyobj_nseconds = PyDict_GetItemString(py_dict, "nseconds")) ||
- (libvirt_uintUnwrap(pyobj_nseconds, &nseconds) < 0)) {
- PyErr_Format(PyExc_LookupError, "malformed or missing
'nseconds'");
+ if ((pyobj_nseconds = PyDict_GetItemString(py_dict, "nseconds")) != NULL)
{
+ if (libvirt_uintUnwrap(pyobj_nseconds, &nseconds) < 0) {
+ PyErr_Format(PyExc_LookupError, "malformed 'nseconds'");
goto cleanup;
}
- } else if (py_dict_size > 0) {
- PyErr_Format(PyExc_LookupError, "Dictionary must contain "
- "'seconds' and 'nseconds'");
+ } else if (py_dict_size == 1) {
+ nseconds = 0;
+ } else {
+ PyErr_Format(PyExc_LookupError, "Dictionary contains "
+ "unknown key");
+ goto cleanup;
+ }
+
+ if (py_dict_size > 2) {
+ PyErr_Format(PyExc_LookupError, "Dictionary contains "
+ "unknown key");
goto cleanup;
}
--
1.8.3.1