[libvirt] [PATCH 5/7] util: Add ADD_ARG_RETURN_ON_ERROR

Daniel P. Berrangé berrange at redhat.com
Thu Jan 2 14:04:00 UTC 2020


On Thu, Jan 02, 2020 at 02:57:56PM +0100, Fabiano Fidêncio wrote:
> Similarly to ADD_ARG, let's create an ADD_ARG_RETURN_ON_ERROR macro
> which will simply return instead of going to a cleanup label.
> 
> By doing this, we can get rid of a few cleanup labels spread in the
> code.
> 
> Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
> ---
>  src/util/virfirewall.c | 25 +++++++++++++------------
>  1 file changed, 13 insertions(+), 12 deletions(-)
> 
> diff --git a/src/util/virfirewall.c b/src/util/virfirewall.c
> index 6dace18bc4..d632f72502 100644
> --- a/src/util/virfirewall.c
> +++ b/src/util/virfirewall.c
> @@ -328,6 +328,16 @@ void virFirewallFree(virFirewallPtr firewall)
>          rule->args[rule->argsLen++] = g_strdup(str); \
>      } while (0)
>  
> +#define ADD_ARG_RETURN_ON_ERROR(rule, str) \
> +    do { \
> +        if (VIR_RESIZE_N(rule->args, \
> +                         rule->argsAlloc, \
> +                         rule->argsLen, 1) < 0) \
> +            return; \
> + \
> +        rule->args[rule->argsLen++] = g_strdup(str); \
> +    } while (0)

IMHO this is missing the benefit of using glib since VIR_RESIZE_N
will never fail now. We should get rid of "ADD_ARG" entirely, and
just put a g_realloc() call directly in the place it is needed
without any macros. Likewise for the next patch.


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|




More information about the libvir-list mailing list