[libvirt] [PATCH] Change return value of VIR_DRV_SUPPORTS_FEATURE to bool

Eric Blake eblake at redhat.com
Fri Dec 3 14:59:23 UTC 2010


On 12/03/2010 01:48 AM, Jiri Denemark wrote:
> virDrvSupportsFeature API is allowed to return -1 on error while all but
> one uses of VIR_DRV_SUPPORTS_FEATURE only check for (non)zero return
> value. Let's make this macro return zero on error, which is what
> everyone expects anyway.
> ---
>  src/driver.h  |    8 ++++----
>  src/libvirt.c |    5 ++++-
>  2 files changed, 8 insertions(+), 5 deletions(-)

That is, if you care about the possibility of an error, call the
function directly; and if you use the macro, then you don't care about
errors and are happy treating an error the same as not present.

Seems reasonable.

> 
> diff --git a/src/driver.h b/src/driver.h
> index b770e5e..e797a75 100644
> --- a/src/driver.h
> +++ b/src/driver.h
> @@ -52,12 +52,12 @@ typedef enum {
>   * Note that you must check for errors.

However, this comment is no longer applicable.  So you'll need a v2 that
fixes the documentation, and make it explicit that the macro ignores
errors, as well as a cross-reference to the actual function for someone
that cares about errors.

>   *
>   * Returns:
> - *   >= 1  Feature is supported.
> + *   != 0  Feature is supported.
>   *   0     Feature is not supported.
> - *   -1    Error.
>   */
> -# define VIR_DRV_SUPPORTS_FEATURE(drv,conn,feature)                      \
> -    ((drv)->supports_feature ? (drv)->supports_feature((conn),(feature)) : 0)
> +# define VIR_DRV_SUPPORTS_FEATURE(drv,conn,feature)                         \
> +    ((drv)->supports_feature ?                                              \
> +        (drv)->supports_feature((conn), (feature)) > 0 : 0)
>  

-- 
Eric Blake   eblake at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20101203/de2e876d/attachment-0001.sig>


More information about the libvir-list mailing list