qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH 02/88] cocci: add more g_new() transformations


From: Markus Armbruster
Subject: Re: [Qemu-devel] [PATCH 02/88] cocci: add more g_new() transformations
Date: Mon, 09 Oct 2017 09:28:48 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux)

The commit message should explain the additional transformations briefly
and informally.  In particular, why they're a good idea.  Same for PATCH
3-5.

Philippe Mathieu-Daudé <address@hidden> writes:

> Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
> ---
>  scripts/coccinelle/g_new.cocci | 73 
> ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 73 insertions(+)
>
> diff --git a/scripts/coccinelle/g_new.cocci b/scripts/coccinelle/g_new.cocci
> index 1e57685a6b..c767325a21 100644
> --- a/scripts/coccinelle/g_new.cocci
> +++ b/scripts/coccinelle/g_new.cocci
> @@ -80,6 +80,49 @@ expression p, n;
>  -g_try_realloc(p, sizeof(T) * (n))
>  +g_try_renew(T, p, n)
>  
> +@@
> +type T;
> +expression n;
> +@@
> +(
> +-g_malloc_n(n, sizeof(T))
> ++g_new(T, n)
> +|
> +-g_malloc0_n(n, sizeof(T))
> ++g_new0(T, n)
> +|
> +-g_try_malloc_n(n, sizeof(T))
> ++g_try_new(T, n)
> +|
> +-g_try_malloc0_n(n, sizeof(T))
> ++g_try_new0(T, n)
> +)
> +
> +@@
> +type T;
> +identifier m;
> +@@
> +T *m;
> +...
> +(
> +-m = g_malloc(sizeof(*m));
> ++m = g_new(T, 1);
> +|
> +-m = g_malloc0(sizeof(*m));
> ++m = g_new0(T, 1);
> +|
> +-m = g_try_malloc(sizeof(*m));
> ++m = g_try_new(T, 1);
> +|
> +-m = g_try_malloc0(sizeof(*m));
> ++m = g_try_new0(T, 1);
> +)
> +
> +////////////////////////////////////////

Please scratch this line.  Overly elaborate comment decoration.

> +//
> +// last transformations: cleanups
> +//
> +
>  // drop superfluous cast
>  @@
>  type T;
> @@ -99,3 +142,33 @@ expression p, n;
>  @@
>  -(T *)g_renew(T, p, n)
>  +g_renew(T, p, n)
> +@@
> +type T;
> +expression n;
> +@@
> +(
> +-(T *)g_try_new(T, n)
> ++g_try_new(T, n)
> +|
> +-(T *)g_try_new0(T, n)
> ++g_try_new0(T, n)
> +)
> +
> +// drop superfluous parenthesis
> +@@
> +type T;
> +expression c;
> +@@
> +(
> +-g_new(T, (c))
> ++g_new(T, c)
> +|
> +-g_try_new(T, (c))
> ++g_try_new(T, c)
> +|
> +-g_new0(T, (c))
> ++g_new0(T, c)
> +|
> +-g_try_new0(T, (c))
> ++g_try_new0(T, c)
> +)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]