Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/mp/gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,8 @@ static void Generate(kj::StringPtr src_prefix,
std::ostringstream server_invoke_start;
std::ostringstream server_invoke_end;
int argc = 0;
for (const auto& field : fields) {
if (field.skip) continue;
auto build_field = [&](const Field& field) {
if (field.skip) return;

const auto& f = field.param_is_set ? field.param : field.result;
auto field_name = f.getProto().getName();
Expand Down Expand Up @@ -589,6 +589,16 @@ static void Generate(kj::StringPtr src_prefix,
server_invoke_start << ", Accessor<" << base_name << "_fields::" << Cap(field_name) << ", "
<< field_flags.str() << ">>(";
server_invoke_end << ")";
};

for (const auto& field : fields) {
if (!field.retval) build_field(field);
}
// C++ return values appear after all method parameters in FunctionTraits.
// Keep this order even when the Cap'n Proto result field is declared
// earlier for wire compatibility.
for (const auto& field : fields) {
if (field.retval) build_field(field);
}

const std::string static_str{is_construct || is_destroy ? "static " : ""};
Expand Down
1 change: 1 addition & 0 deletions test/mp/test/foo.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface FooInterface $Proxy.wrap("mp::test::FooImplementation") {
add @0 (a :Int32, b :Int32) -> (result :Int32);
addOut @19 (a :Int32, b :Int32) -> (ret :Int32);
addInOut @20 (x :Int32, sum :Int32) -> (sum :Int32);
addResultOut @23 (value :Int32) -> (result :Int32, text :Text);
mapSize @1 (map :List(Pair(Text, Text))) -> (result :Int32);
pass @2 (arg :FooStruct) -> (result :FooStruct);
raise @3 (arg :FooStruct) -> (error :FooStruct $Proxy.exception("mp::test::FooStruct"));
Expand Down
1 change: 1 addition & 0 deletions test/mp/test/foo.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class FooImplementation
int add(int a, int b) { return a + b; }
void addOut(int a, int b, int& out) { out = a + b; }
void addInOut(int x, int& sum) { sum += x; }
int addResultOut(int value, std::string& text) { text = std::to_string(value); return value + 1; }
int mapSize(const std::map<std::string, std::string>& map) { return map.size(); }
FooStruct pass(FooStruct foo) { return foo; }
void raise(FooStruct foo) { throw foo; }
Expand Down
3 changes: 3 additions & 0 deletions test/mp/test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ KJ_TEST("Call FooInterface methods")
KJ_EXPECT(ret == 7);
foo->addInOut(3, ret);
KJ_EXPECT(ret == 10);
std::string text;
KJ_EXPECT(foo->addResultOut(41, text) == 42);
KJ_EXPECT(text == "41");

FooStruct in;
in.name = "name";
Expand Down
Loading