[PATCH 12/22] remote generator, daemon: Combine multiple ifs in the generated code

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

 



---
 daemon/remote_dispatch_bodies.c |   66 +++++++++++++++++++-------------------
 daemon/remote_generator.pl      |   28 ++++++++++------
 2 files changed, 50 insertions(+), 44 deletions(-)

diff --git a/daemon/remote_dispatch_bodies.c b/daemon/remote_dispatch_bodies.c
index 89f0bc4..50432f9 100644
--- a/daemon/remote_dispatch_bodies.c
+++ b/daemon/remote_dispatch_bodies.c
@@ -1800,12 +1800,12 @@ remoteDispatchDomainSnapshotListNames(
     rv = 0;
 
 cleanup:
-    if (rv < 0)
+    if (rv < 0) {
         remoteDispatchError(rerr);
+        VIR_FREE(ret->names.names_val);
+    }
     if (dom)
         virDomainFree(dom);
-    if (rv < 0)
-        VIR_FREE(ret->names.names_val);
     return rv;
 }
 
@@ -2630,10 +2630,10 @@ remoteDispatchListDefinedDomains(
     rv = 0;
 
 cleanup:
-    if (rv < 0)
+    if (rv < 0) {
         remoteDispatchError(rerr);
-    if (rv < 0)
         VIR_FREE(ret->names.names_val);
+    }
     return rv;
 }
 
@@ -2674,10 +2674,10 @@ remoteDispatchListDefinedInterfaces(
     rv = 0;
 
 cleanup:
-    if (rv < 0)
+    if (rv < 0) {
         remoteDispatchError(rerr);
-    if (rv < 0)
         VIR_FREE(ret->names.names_val);
+    }
     return rv;
 }
 
@@ -2718,10 +2718,10 @@ remoteDispatchListDefinedNetworks(
     rv = 0;
 
 cleanup:
-    if (rv < 0)
+    if (rv < 0) {
         remoteDispatchError(rerr);
-    if (rv < 0)
         VIR_FREE(ret->names.names_val);
+    }
     return rv;
 }
 
@@ -2762,10 +2762,10 @@ remoteDispatchListDefinedStoragePools(
     rv = 0;
 
 cleanup:
-    if (rv < 0)
+    if (rv < 0) {
         remoteDispatchError(rerr);
-    if (rv < 0)
         VIR_FREE(ret->names.names_val);
+    }
     return rv;
 }
 
@@ -2806,10 +2806,10 @@ remoteDispatchListDomains(
     rv = 0;
 
 cleanup:
-    if (rv < 0)
+    if (rv < 0) {
         remoteDispatchError(rerr);
-    if (rv < 0)
         VIR_FREE(ret->ids.ids_val);
+    }
     return rv;
 }
 
@@ -2850,10 +2850,10 @@ remoteDispatchListInterfaces(
     rv = 0;
 
 cleanup:
-    if (rv < 0)
+    if (rv < 0) {
         remoteDispatchError(rerr);
-    if (rv < 0)
         VIR_FREE(ret->names.names_val);
+    }
     return rv;
 }
 
@@ -2894,10 +2894,10 @@ remoteDispatchListNetworks(
     rv = 0;
 
 cleanup:
-    if (rv < 0)
+    if (rv < 0) {
         remoteDispatchError(rerr);
-    if (rv < 0)
         VIR_FREE(ret->names.names_val);
+    }
     return rv;
 }
 
@@ -2938,10 +2938,10 @@ remoteDispatchListNWFilters(
     rv = 0;
 
 cleanup:
-    if (rv < 0)
+    if (rv < 0) {
         remoteDispatchError(rerr);
-    if (rv < 0)
         VIR_FREE(ret->names.names_val);
+    }
     return rv;
 }
 
@@ -2982,10 +2982,10 @@ remoteDispatchListSecrets(
     rv = 0;
 
 cleanup:
-    if (rv < 0)
+    if (rv < 0) {
         remoteDispatchError(rerr);
-    if (rv < 0)
         VIR_FREE(ret->uuids.uuids_val);
+    }
     return rv;
 }
 
@@ -3026,10 +3026,10 @@ remoteDispatchListStoragePools(
     rv = 0;
 
 cleanup:
-    if (rv < 0)
+    if (rv < 0) {
         remoteDispatchError(rerr);
-    if (rv < 0)
         VIR_FREE(ret->names.names_val);
+    }
     return rv;
 }
 
@@ -3656,12 +3656,12 @@ remoteDispatchNodeDeviceListCaps(
     rv = 0;
 
 cleanup:
-    if (rv < 0)
+    if (rv < 0) {
         remoteDispatchError(rerr);
+        VIR_FREE(ret->names.names_val);
+    }
     if (dev)
         virNodeDeviceFree(dev);
-    if (rv < 0)
-        VIR_FREE(ret->names.names_val);
     return rv;
 }
 
@@ -3838,10 +3838,10 @@ remoteDispatchNodeGetCellsFreeMemory(
     rv = 0;
 
 cleanup:
-    if (rv < 0)
+    if (rv < 0) {
         remoteDispatchError(rerr);
-    if (rv < 0)
         VIR_FREE(ret->freeMems.freeMems_val);
+    }
     return rv;
 }
 
@@ -3919,10 +3919,10 @@ remoteDispatchNodeListDevices(
     rv = 0;
 
 cleanup:
-    if (rv < 0)
+    if (rv < 0) {
         remoteDispatchError(rerr);
-    if (rv < 0)
         VIR_FREE(ret->names.names_val);
+    }
     return rv;
 }
 
@@ -5016,12 +5016,12 @@ remoteDispatchStoragePoolListVolumes(
     rv = 0;
 
 cleanup:
-    if (rv < 0)
+    if (rv < 0) {
         remoteDispatchError(rerr);
+        VIR_FREE(ret->names.names_val);
+    }
     if (pool)
         virStoragePoolFree(pool);
-    if (rv < 0)
-        VIR_FREE(ret->names.names_val);
     return rv;
 }
 
diff --git a/daemon/remote_generator.pl b/daemon/remote_generator.pl
index 2ddfdc0..1fd4627 100755
--- a/daemon/remote_generator.pl
+++ b/daemon/remote_generator.pl
@@ -332,6 +332,7 @@ elsif ($opt_b) {
         my @args_list = ();
         my @ret_list = ();
         my @free_list = ();
+        my @free_list_on_error = ("remoteDispatchError(rerr);");
 
         if ($calls{$_}->{args} ne "void") {
             # node device is special, as it's identified by name
@@ -424,9 +425,7 @@ elsif ($opt_b) {
                 if ($ret_member =~ m/remote_nonnull_string (\S+)<(\S+)>;/) {
                     push(@vars_list, "int len");
                     push(@ret_list, "ret->$1.$1_len = len;");
-                    push(@free_list,
-                         "    if (rv < 0)\n" .
-                         "        VIR_FREE(ret->$1.$1_val);");
+                    push(@free_list_on_error, "VIR_FREE(ret->$1.$1_val);");
                     $single_ret_var = "len";
                     $single_ret_by_ref = 0;
                     $single_ret_check = " < 0";
@@ -466,9 +465,7 @@ elsif ($opt_b) {
                 } elsif ($ret_member =~ m/int (\S+)<(\S+)>;/) {
                     push(@vars_list, "int len");
                     push(@ret_list, "ret->$1.$1_len = len;");
-                    push(@free_list,
-                         "    if (rv < 0)\n" .
-                         "        VIR_FREE(ret->$1.$1_val);");
+                    push(@free_list_on_error, "VIR_FREE(ret->$1.$1_val);");
                     $single_ret_var = "len";
                     $single_ret_by_ref = 0;
                     $single_ret_check = " < 0";
@@ -501,9 +498,7 @@ elsif ($opt_b) {
                 } elsif ($ret_member =~ m/hyper (\S+)<(\S+)>;/) {
                     push(@vars_list, "int len");
                     push(@ret_list, "ret->$1.$1_len = len;");
-                    push(@free_list,
-                         "    if (rv < 0)\n" .
-                         "        VIR_FREE(ret->$1.$1_val);");
+                    push(@free_list_on_error, "VIR_FREE(ret->$1.$1_val);");
                     $single_ret_var = "len";
                     $single_ret_by_ref = 0;
                     $single_ret_as_list = 1;
@@ -642,8 +637,19 @@ elsif ($opt_b) {
         print "    rv = 0;\n";
         print "\n";
         print "cleanup:\n";
-        print "    if (rv < 0)\n";
-        print "        remoteDispatchError(rerr);\n";
+        print "    if (rv < 0)";
+
+        if (scalar(@free_list_on_error) > 1) {
+            print " {";
+        }
+
+        print "\n        ";
+        print join("\n        ", @free_list_on_error);
+        print "\n";
+
+        if (scalar(@free_list_on_error) > 1) {
+            print "    }\n";
+        }
 
         print join("\n", @free_list);
 
-- 
1.7.0.4

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