Skip to content

Commit c73a2cb

Browse files
committed
idl: support pass-by-reference for input/output args
1 parent 23d5954 commit c73a2cb

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

tools/exmidl.pl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
);
1313

1414
if ($gen_mode eq "CLN" || $gen_mode eq "SDP") {
15-
print "#include <$_>\n" for qw(cstring gromox/exmdb_client.hpp gromox/exmdb_rpc.hpp);
15+
print "#include <$_>\n" for qw(cstring utility gromox/exmdb_client.hpp gromox/exmdb_rpc.hpp);
1616
if ($gen_mode eq "SDP") {
1717
print "#include <$_>\n" for qw(gromox/exmdb_common_util.hpp gromox/exmdb_ext.hpp gromox/exmdb_provider_client.hpp gromox/exmdb_server.hpp);
1818
}
@@ -56,8 +56,8 @@
5656
print "\tauto &r = *r1;\n";
5757
}
5858
print "\treturn exmdb_server::$func(", join(", ", "q0->dir",
59-
(map { my($type, $field) = @$_; "q.$field"; } @$iargs),
60-
(map { my($type, $field) = @$_; "&r.$field"; } @$oargs),
59+
(map { my($type, $field) = @$_; (substr($type, -1, 1) eq "&" ? "*" : "")."q.$field"; } @$iargs),
60+
(map { my($type, $field) = @$_; (substr($type, -1, 1) eq "&" ? "" : "&")."r.$field"; } @$oargs),
6161
), ");\n}\n";
6262
next;
6363
}
@@ -68,6 +68,11 @@
6868
my($type, $field) = @$_;
6969
if (substr($type, -1, 1) eq "*") {
7070
print ", deconst($field)";
71+
} elsif (substr($type, -1, 1) eq "&") {
72+
# struct members should continue to use a pointer,
73+
# because refs are so awkward to assign (more so during
74+
# deserialization than with serialization)
75+
print ", deconst(&$field)";
7176
} else {
7277
print ", $field";
7378
}
@@ -76,7 +81,8 @@
7681
print "\tif (!exmdb_client_do_rpc(&q, &r))\n\t\treturn false;\n";
7782
for (@$oargs) {
7883
my($type, $field) = @$_;
79-
print "\t*$field = r.$field;\n";
84+
print "\t", (substr($type, -1, 1) eq "&" ? "" : "*"),
85+
"$field = std::move(r.$field);\n";
8086
}
8187
print "\treturn TRUE;\n}\n\n";
8288
}

tools/zcidl.pl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
);
1212

1313
if ($gen_mode eq "CLN") {
14-
print "#include <$_>\n" for qw(gromox/defs.h gromox/zcore_client.hpp gromox/zcore_rpc.hpp);
14+
print "#include <$_>\n" for qw(utility gromox/defs.h gromox/zcore_client.hpp gromox/zcore_rpc.hpp);
1515
print "#include \"$_\"\n" for qw(php.h);
1616
}
1717

@@ -39,8 +39,8 @@
3939
print "\tauto &r = *r1;\n";
4040
}
4141
print "\tr0->result = zs_$func(", join(", ",
42-
(map { my($type, $field) = @$_; "q.$field"; } @$iargs),
43-
(map { my($type, $field) = @$_; "&r.$field"; } @$oargs),
42+
(map { my($type, $field) = @$_; (substr($type, -1, 1) eq "&" ? "*" : "")."q.$field"; } @$iargs),
43+
(map { my($type, $field) = @$_; (substr($type, -1, 1) eq "&" ? "" : "&")."r.$field"; } @$oargs),
4444
), ");\n";
4545
print "\tbreak;\n}\n";
4646
next;
@@ -52,6 +52,8 @@
5252
my($type, $field) = @$_;
5353
if (substr($type, -1, 1) eq "*") {
5454
print ", deconst($field)";
55+
} elsif (substr($type, -1, 1) eq "&") {
56+
print ", deconst(&$field)";
5557
} else {
5658
print ", $field";
5759
}
@@ -63,7 +65,8 @@
6365
}
6466
for (@$oargs) {
6567
my($type, $field) = @$_;
66-
print "\t*$field = r.$field;\n";
68+
print "\t", (substr($type, -1, 1) eq "&" ? "" : "*"),
69+
"$field = std::move(r.$field);\n";
6770
}
6871
print "\treturn r.result;\n}\n\n";
6972
}

0 commit comments

Comments
 (0)