[libvirt PATCH 2/3] gendispatch: use g_new0 instead of VIR_ALLOC
Michal Prívozník
mprivozn at redhat.com
Thu Oct 1 13:50:23 UTC 2020
On 9/30/20 4:10 PM, Ján Tomko wrote:
> Take the easy way out and use typeof, because my life
> is too short to spend it reading gendispatch.pl.
>
> Signed-off-by: Ján Tomko <jtomko at redhat.com>
> ---
> src/rpc/gendispatch.pl | 16 +++++++---------
> 1 file changed, 7 insertions(+), 9 deletions(-)
Fair enough. We are not storing the type in a usable form anyway. The
moment we learn the type we push a variable declaration of that type it
onto @vars_list (if needed) and forget it instantly.
Michal
>
> diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl
> index 0b2ae59910..91575f4d34 100755
> --- a/src/rpc/gendispatch.pl
> +++ b/src/rpc/gendispatch.pl
> @@ -797,8 +797,7 @@ elsif ($mode eq "server") {
> push(@free_list, " VIR_FREE($1);");
> push(@free_list_on_error, "VIR_FREE($1_p);");
> push(@prepare_ret_list,
> - "if (VIR_ALLOC($1_p) < 0)\n" .
> - " goto cleanup;\n" .
> + "$1_p = g_new0(char *, 1);\n" .
> "\n" .
> " *$1_p = g_strdup($1);\n");
>
> @@ -1126,9 +1125,9 @@ elsif ($mode eq "server") {
>
> if ($single_ret_as_list) {
> print " /* Allocate return buffer. */\n";
> - print " if (VIR_ALLOC_N(ret->$single_ret_list_name.${single_ret_list_name}_val," .
> - " args->$single_ret_list_max_var) < 0)\n";
> - print " goto cleanup;\n";
> + print " ret->$single_ret_list_name.${single_ret_list_name}_val =\n";
> + print " g_new0(typeof(*ret->$single_ret_list_name.${single_ret_list_name}_val), " .
> + "args->$single_ret_list_max_var); \n";
Drop the space before newline though.
Michal
More information about the libvir-list
mailing list