Re: [libvirt PATCH 2/3] gendispatch: use g_new0 instead of VIR_ALLOC

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

 



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




[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