Re: [PATCH RFC 1/2] util: Add VIR_ENUM_IMPL_LABEL

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

 



On 07/26/2018 07:49 PM, Cole Robinson wrote:
> This allows passing in a string label describing the enum, which can
> be used to autogenerate error messages
> 
> Signed-off-by: Cole Robinson <crobinso@xxxxxxxxxx>
> ---
>  src/util/virutil.c | 20 ++++++++++++++++----
>  src/util/virutil.h | 15 ++++++++++-----
>  2 files changed, 26 insertions(+), 9 deletions(-)
> 
> diff --git a/src/util/virutil.c b/src/util/virutil.c
> index a908422feb..6d23a26a74 100644
> --- a/src/util/virutil.c
> +++ b/src/util/virutil.c
> @@ -444,16 +444,22 @@ virParseVersionString(const char *str, unsigned long *version,
>  
>  int virEnumFromString(const char *const*types,
>                        unsigned int ntypes,
> -                      const char *type)
> +                      const char *type,
> +                      const char * const label)
>  {
>      size_t i;
>      if (!type)
> -        return -1;
> +        goto error;
>  
>      for (i = 0; i < ntypes; i++)
>          if (STREQ(types[i], type))
>              return i;
>  
> + error:
> +    if (label) {

If we rewrite all of our enums into _LABEL then @label is always going
to be non-NULL. But we need this check for now. We are not there yet.

> +        virReportError(VIR_ERR_INVALID_ARG,
> +                       _("Unknown '%s' value '%s'"), label, type);

@type can be NULL, therefore NULLSTR(type).

> +    }
>      return -1;
>  }
>  

Michal

--
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]

  Powered by Linux