Re: [ocaml PATCH] Cast virError* enums to int for comparisons with 0

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

 



On Fri, Nov 02, 2018 at 03:52:23PM +0100, Pino Toscano wrote:
> The actual type of an enum in C is implementation defined when there are
> no negative values, and thus it can be int, or uint.  This is the case
> of the virError* enums in libvirt, as they do not have negative values.
> 
> Hence, to avoid hitting tautological comparison errors when checking
> their rage, temporarly cast the enum values to int when checking they

s/rage/range/

The patch itself is fine:

ACK.

Rich.

> are not negative.  The check is there to ensure the value is within the
> range of the OCaml type used to represent it.
> 
> Signed-off-by: Pino Toscano <ptoscano@xxxxxxxxxx>
> ---
>  libvirt/libvirt_c_epilogue.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/libvirt/libvirt_c_epilogue.c b/libvirt/libvirt_c_epilogue.c
> index 29656a4..4e75d2f 100644
> --- a/libvirt/libvirt_c_epilogue.c
> +++ b/libvirt/libvirt_c_epilogue.c
> @@ -153,7 +153,7 @@ Val_err_number (virErrorNumber code)
>    CAMLparam0 ();
>    CAMLlocal1 (rv);
>  
> -  if (0 <= code && code <= MAX_VIR_CODE)
> +  if (0 <= (int) code && code <= MAX_VIR_CODE)
>      rv = Val_int (code);
>    else {
>      rv = caml_alloc (1, 0);	/* VIR_ERR_UNKNOWN (code) */
> @@ -169,7 +169,7 @@ Val_err_domain (virErrorDomain code)
>    CAMLparam0 ();
>    CAMLlocal1 (rv);
>  
> -  if (0 <= code && code <= MAX_VIR_DOMAIN)
> +  if (0 <= (int) code && code <= MAX_VIR_DOMAIN)
>      rv = Val_int (code);
>    else {
>      rv = caml_alloc (1, 0);	/* VIR_FROM_UNKNOWN (code) */
> @@ -185,7 +185,7 @@ Val_err_level (virErrorLevel code)
>    CAMLparam0 ();
>    CAMLlocal1 (rv);
>  
> -  if (0 <= code && code <= MAX_VIR_LEVEL)
> +  if (0 <= (int) code && code <= MAX_VIR_LEVEL)
>      rv = Val_int (code);
>    else {
>      rv = caml_alloc (1, 0);	/* VIR_ERR_UNKNOWN_LEVEL (code) */
> -- 
> 2.17.2
> 
> --
> libvir-list mailing list
> libvir-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/libvir-list

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html

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