remote generator, daemon: Combine multiple ifs in the generated code

This commit is contained in:
Matthias Bolte 2011-04-23 08:35:03 +02:00
parent 5641222eba
commit 38982f18f2
2 changed files with 50 additions and 44 deletions

View File

@ -1801,12 +1801,12 @@ remoteDispatchDomainSnapshotListNames(
rv = 0; rv = 0;
cleanup: cleanup:
if (rv < 0) if (rv < 0) {
remoteDispatchError(rerr); remoteDispatchError(rerr);
VIR_FREE(ret->names.names_val);
}
if (dom) if (dom)
virDomainFree(dom); virDomainFree(dom);
if (rv < 0)
VIR_FREE(ret->names.names_val);
return rv; return rv;
} }
@ -2631,10 +2631,10 @@ remoteDispatchListDefinedDomains(
rv = 0; rv = 0;
cleanup: cleanup:
if (rv < 0) if (rv < 0) {
remoteDispatchError(rerr); remoteDispatchError(rerr);
if (rv < 0)
VIR_FREE(ret->names.names_val); VIR_FREE(ret->names.names_val);
}
return rv; return rv;
} }
@ -2675,10 +2675,10 @@ remoteDispatchListDefinedInterfaces(
rv = 0; rv = 0;
cleanup: cleanup:
if (rv < 0) if (rv < 0) {
remoteDispatchError(rerr); remoteDispatchError(rerr);
if (rv < 0)
VIR_FREE(ret->names.names_val); VIR_FREE(ret->names.names_val);
}
return rv; return rv;
} }
@ -2719,10 +2719,10 @@ remoteDispatchListDefinedNetworks(
rv = 0; rv = 0;
cleanup: cleanup:
if (rv < 0) if (rv < 0) {
remoteDispatchError(rerr); remoteDispatchError(rerr);
if (rv < 0)
VIR_FREE(ret->names.names_val); VIR_FREE(ret->names.names_val);
}
return rv; return rv;
} }
@ -2763,10 +2763,10 @@ remoteDispatchListDefinedStoragePools(
rv = 0; rv = 0;
cleanup: cleanup:
if (rv < 0) if (rv < 0) {
remoteDispatchError(rerr); remoteDispatchError(rerr);
if (rv < 0)
VIR_FREE(ret->names.names_val); VIR_FREE(ret->names.names_val);
}
return rv; return rv;
} }
@ -2807,10 +2807,10 @@ remoteDispatchListDomains(
rv = 0; rv = 0;
cleanup: cleanup:
if (rv < 0) if (rv < 0) {
remoteDispatchError(rerr); remoteDispatchError(rerr);
if (rv < 0)
VIR_FREE(ret->ids.ids_val); VIR_FREE(ret->ids.ids_val);
}
return rv; return rv;
} }
@ -2851,10 +2851,10 @@ remoteDispatchListInterfaces(
rv = 0; rv = 0;
cleanup: cleanup:
if (rv < 0) if (rv < 0) {
remoteDispatchError(rerr); remoteDispatchError(rerr);
if (rv < 0)
VIR_FREE(ret->names.names_val); VIR_FREE(ret->names.names_val);
}
return rv; return rv;
} }
@ -2895,10 +2895,10 @@ remoteDispatchListNetworks(
rv = 0; rv = 0;
cleanup: cleanup:
if (rv < 0) if (rv < 0) {
remoteDispatchError(rerr); remoteDispatchError(rerr);
if (rv < 0)
VIR_FREE(ret->names.names_val); VIR_FREE(ret->names.names_val);
}
return rv; return rv;
} }
@ -2939,10 +2939,10 @@ remoteDispatchListNWFilters(
rv = 0; rv = 0;
cleanup: cleanup:
if (rv < 0) if (rv < 0) {
remoteDispatchError(rerr); remoteDispatchError(rerr);
if (rv < 0)
VIR_FREE(ret->names.names_val); VIR_FREE(ret->names.names_val);
}
return rv; return rv;
} }
@ -2983,10 +2983,10 @@ remoteDispatchListSecrets(
rv = 0; rv = 0;
cleanup: cleanup:
if (rv < 0) if (rv < 0) {
remoteDispatchError(rerr); remoteDispatchError(rerr);
if (rv < 0)
VIR_FREE(ret->uuids.uuids_val); VIR_FREE(ret->uuids.uuids_val);
}
return rv; return rv;
} }
@ -3027,10 +3027,10 @@ remoteDispatchListStoragePools(
rv = 0; rv = 0;
cleanup: cleanup:
if (rv < 0) if (rv < 0) {
remoteDispatchError(rerr); remoteDispatchError(rerr);
if (rv < 0)
VIR_FREE(ret->names.names_val); VIR_FREE(ret->names.names_val);
}
return rv; return rv;
} }
@ -3657,12 +3657,12 @@ remoteDispatchNodeDeviceListCaps(
rv = 0; rv = 0;
cleanup: cleanup:
if (rv < 0) if (rv < 0) {
remoteDispatchError(rerr); remoteDispatchError(rerr);
VIR_FREE(ret->names.names_val);
}
if (dev) if (dev)
virNodeDeviceFree(dev); virNodeDeviceFree(dev);
if (rv < 0)
VIR_FREE(ret->names.names_val);
return rv; return rv;
} }
@ -3839,10 +3839,10 @@ remoteDispatchNodeGetCellsFreeMemory(
rv = 0; rv = 0;
cleanup: cleanup:
if (rv < 0) if (rv < 0) {
remoteDispatchError(rerr); remoteDispatchError(rerr);
if (rv < 0)
VIR_FREE(ret->freeMems.freeMems_val); VIR_FREE(ret->freeMems.freeMems_val);
}
return rv; return rv;
} }
@ -3920,10 +3920,10 @@ remoteDispatchNodeListDevices(
rv = 0; rv = 0;
cleanup: cleanup:
if (rv < 0) if (rv < 0) {
remoteDispatchError(rerr); remoteDispatchError(rerr);
if (rv < 0)
VIR_FREE(ret->names.names_val); VIR_FREE(ret->names.names_val);
}
return rv; return rv;
} }
@ -5017,12 +5017,12 @@ remoteDispatchStoragePoolListVolumes(
rv = 0; rv = 0;
cleanup: cleanup:
if (rv < 0) if (rv < 0) {
remoteDispatchError(rerr); remoteDispatchError(rerr);
VIR_FREE(ret->names.names_val);
}
if (pool) if (pool)
virStoragePoolFree(pool); virStoragePoolFree(pool);
if (rv < 0)
VIR_FREE(ret->names.names_val);
return rv; return rv;
} }

View File

@ -333,6 +333,7 @@ elsif ($opt_b) {
my @args_list = (); my @args_list = ();
my @ret_list = (); my @ret_list = ();
my @free_list = (); my @free_list = ();
my @free_list_on_error = ("remoteDispatchError(rerr);");
if ($calls{$_}->{args} ne "void") { if ($calls{$_}->{args} ne "void") {
# node device is special, as it's identified by name # node device is special, as it's identified by name
@ -425,9 +426,7 @@ elsif ($opt_b) {
if ($ret_member =~ m/remote_nonnull_string (\S+)<(\S+)>;/) { if ($ret_member =~ m/remote_nonnull_string (\S+)<(\S+)>;/) {
push(@vars_list, "int len"); push(@vars_list, "int len");
push(@ret_list, "ret->$1.$1_len = len;"); push(@ret_list, "ret->$1.$1_len = len;");
push(@free_list, push(@free_list_on_error, "VIR_FREE(ret->$1.$1_val);");
" if (rv < 0)\n" .
" VIR_FREE(ret->$1.$1_val);");
$single_ret_var = "len"; $single_ret_var = "len";
$single_ret_by_ref = 0; $single_ret_by_ref = 0;
$single_ret_check = " < 0"; $single_ret_check = " < 0";
@ -467,9 +466,7 @@ elsif ($opt_b) {
} elsif ($ret_member =~ m/int (\S+)<(\S+)>;/) { } elsif ($ret_member =~ m/int (\S+)<(\S+)>;/) {
push(@vars_list, "int len"); push(@vars_list, "int len");
push(@ret_list, "ret->$1.$1_len = len;"); push(@ret_list, "ret->$1.$1_len = len;");
push(@free_list, push(@free_list_on_error, "VIR_FREE(ret->$1.$1_val);");
" if (rv < 0)\n" .
" VIR_FREE(ret->$1.$1_val);");
$single_ret_var = "len"; $single_ret_var = "len";
$single_ret_by_ref = 0; $single_ret_by_ref = 0;
$single_ret_check = " < 0"; $single_ret_check = " < 0";
@ -502,9 +499,7 @@ elsif ($opt_b) {
} elsif ($ret_member =~ m/hyper (\S+)<(\S+)>;/) { } elsif ($ret_member =~ m/hyper (\S+)<(\S+)>;/) {
push(@vars_list, "int len"); push(@vars_list, "int len");
push(@ret_list, "ret->$1.$1_len = len;"); push(@ret_list, "ret->$1.$1_len = len;");
push(@free_list, push(@free_list_on_error, "VIR_FREE(ret->$1.$1_val);");
" if (rv < 0)\n" .
" VIR_FREE(ret->$1.$1_val);");
$single_ret_var = "len"; $single_ret_var = "len";
$single_ret_by_ref = 0; $single_ret_by_ref = 0;
$single_ret_as_list = 1; $single_ret_as_list = 1;
@ -643,8 +638,19 @@ elsif ($opt_b) {
print " rv = 0;\n"; print " rv = 0;\n";
print "\n"; print "\n";
print "cleanup:\n"; print "cleanup:\n";
print " if (rv < 0)\n"; print " if (rv < 0)";
print " remoteDispatchError(rerr);\n";
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); print join("\n", @free_list);