Re: [libvirt-python PATCH 02/23] refactor the function to not override python exceptions

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

 




On 09/24/2015 10:01 AM, Pavel Hrdina wrote:
> Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
> ---
>  libvirt-override.c | 23 ++++++++---------------
>  1 file changed, 8 insertions(+), 15 deletions(-)
> 
> diff --git a/libvirt-override.c b/libvirt-override.c
> index 4dfe332..14aa0e9 100644
> --- a/libvirt-override.c
> +++ b/libvirt-override.c
> @@ -8263,38 +8263,31 @@ libvirt_virDomainSetTime(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {

Seems as though py_retval can be removed as it's no longer needed (build
whine)



>      if (PyDict_Check(py_dict)) {
>          py_dict_size = PyDict_Size(py_dict);
>          if ((pyobj_seconds = PyDict_GetItemString(py_dict, "seconds"))) {
> -            if (libvirt_longlongUnwrap(pyobj_seconds, &seconds) < 0) {
> -                PyErr_Format(PyExc_LookupError, "malformed 'seconds'");
> -                goto cleanup;
> -            }
> +            if (libvirt_longlongUnwrap(pyobj_seconds, &seconds) < 0)
> +                return NULL;

So if this was missing - would the error indicate 'seconds' was
malformed?  Or just some generic invalid value python error? I'm
preferential to specific errors that help point me at what I did wrong.

John
>          } else {
>              PyErr_Format(PyExc_LookupError, "Dictionary must contains 'seconds'");
> -            goto cleanup;
> +            return NULL;
>          }
>  
>          if ((pyobj_nseconds = PyDict_GetItemString(py_dict, "nseconds"))) {
> -            if (libvirt_uintUnwrap(pyobj_nseconds, &nseconds) < 0) {
> -                PyErr_Format(PyExc_LookupError, "malformed 'nseconds'");
> -                goto cleanup;
> -            }
> +            if (libvirt_uintUnwrap(pyobj_nseconds, &nseconds) < 0)
> +                return NULL;
>          } else if (py_dict_size > 1) {
>              PyErr_Format(PyExc_LookupError, "Dictionary contains unknown key");
> -            goto cleanup;
> +            return NULL;
>          }
>      } else if (py_dict != Py_None || !flags) {
>          PyErr_Format(PyExc_TypeError, "time must be a dictionary "
>                       "or None with flags set");
> -        goto cleanup;
> +        return NULL;
>      }
>  
>      LIBVIRT_BEGIN_ALLOW_THREADS;
>      c_retval = virDomainSetTime(domain, seconds, nseconds, flags);
>      LIBVIRT_END_ALLOW_THREADS;
>  
> -    py_retval = libvirt_intWrap(c_retval);
> -
> - cleanup:
> -    return py_retval;
> +    return libvirt_intWrap(c_retval);
>  }
>  #endif /* LIBVIR_CHECK_VERSION(1, 2, 5) */
>  
> 

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]