Skip to content

Commit 59030c6

Browse files
committed
Merge #181: type-function.h: Fix CustomBuildField overload
688140b test: Add coverage for type-function.h (Ryan Ofsky) 8b96229 type-function.h: Fix CustomBuildField overload (Ryan Ofsky) Pull request description: Fix `std::function` `CustomBuildField` overload which is incompatible with a recent change in 3a96cdc from #172 which changed generated IPC client code to pass it an rvalue `std::function` reference instead of an lvalue reference. Motivation for this change is to avoid a build error in bitcoin/bitcoin#29409, when rebased on top of bitcoin/bitcoin#32641 which includes #172. ACKs for top commit: TheCharlatan: ACK 688140b Tree-SHA512: aeb5cbea0b4aaf7f84c4c30255546f367c4c6ca154c831f648f6ba03599b23beb7032477599671c10da790ff2ff592ae8ce3098bee294b431cfca82b1530f42d
2 parents 27c7e8e + 688140b commit 59030c6

File tree

5 files changed

+12
-1
lines changed

5 files changed

+12
-1
lines changed

include/mp/type-function.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ template <typename Value, typename FnR, typename... FnParams, typename Output>
2424
void CustomBuildField(TypeList<std::function<FnR(FnParams...)>>,
2525
Priority<1>,
2626
InvokeContext& invoke_context,
27-
Value& value,
27+
Value&& value,
2828
Output&& output)
2929
{
3030
if (value) {

test/mp/test/foo-types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <mp/proxy-types.h>
99
#include <mp/type-context.h>
1010
#include <mp/type-decay.h>
11+
#include <mp/type-function.h>
1112
#include <mp/type-interface.h>
1213
#include <mp/type-map.h>
1314
#include <mp/type-message.h>

test/mp/test/foo.capnp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ interface FooInterface $Proxy.wrap("mp::test::FooImplementation") {
2828
passMessage @13 (arg :FooMessage) -> (result :FooMessage);
2929
passMutable @14 (arg :FooMutable) -> (arg :FooMutable);
3030
passEnum @15 (arg :Int32) -> (result :Int32);
31+
passFn @16 (context :Proxy.Context, fn :FooFn) -> (result :Int32);
3132
}
3233

3334
interface FooCallback $Proxy.wrap("mp::test::FooCallback") {
@@ -39,6 +40,11 @@ interface ExtendedCallback extends(FooCallback) $Proxy.wrap("mp::test::ExtendedC
3940
callExtended @0 (context :Proxy.Context, arg :Int32) -> (result :Int32);
4041
}
4142

43+
interface FooFn $Proxy.wrap("ProxyCallback<std::function<int()>>") {
44+
destroy @0 (context :Proxy.Context) -> ();
45+
call @1 (context :Proxy.Context) -> (result :Int32);
46+
}
47+
4248
struct FooStruct $Proxy.wrap("mp::test::FooStruct") {
4349
name @0 :Text;
4450
setint @1 :List(Int32);

test/mp/test/foo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifndef MP_TEST_FOO_H
66
#define MP_TEST_FOO_H
77

8+
#include <functional>
89
#include <map>
910
#include <memory>
1011
#include <string>
@@ -75,6 +76,7 @@ class FooImplementation
7576
FooMessage passMessage(FooMessage foo) { foo.message += " call"; return foo; }
7677
void passMutable(FooMutable& foo) { foo.message += " call"; }
7778
FooEnum passEnum(FooEnum foo) { return foo; }
79+
int passFn(std::function<int()> fn) { return fn(); }
7880
std::shared_ptr<FooCallback> m_callback;
7981
};
8082

test/mp/test/test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ KJ_TEST("Call FooInterface methods")
128128
foo->passMutable(mut);
129129
KJ_EXPECT(mut.message == "init build pass call return read");
130130

131+
KJ_EXPECT(foo->passFn([]{ return 10; }) == 10);
132+
131133
disconnect_client();
132134
thread.join();
133135

0 commit comments

Comments
 (0)