From 8b96229da58ec89262dbc5d1249f7ee5e02b73be Mon Sep 17 00:00:00 2001 From: Ryan Ofsky Date: Tue, 3 Jun 2025 15:40:05 -0400 Subject: [PATCH 1/2] type-function.h: Fix CustomBuildField overload Fix std::function CustomBuildField overload which is incompatible with a recent change in 3a96cdc18f2d1ca202fbc91551f27097fd7ec7f6 from https://github.com/bitcoin-core/libmultiprocess/pull/172 which changed generated IPC client code to pass it an rvalue std::function reference instead of an lvalue reference. There was no test coverage for the type-function.h header earlier but the next commit adds a test which would have caught the problem in the CustomBuildField declaration. Motivation for this change is to avoid a build error in https://github.com/bitcoin/bitcoin/pull/29409 when rebased on top of https://github.com/bitcoin/bitcoin/pull/32641 which includes https://github.com/bitcoin-core/libmultiprocess/pull/172 --- include/mp/type-function.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mp/type-function.h b/include/mp/type-function.h index bf00c581..df7b280e 100644 --- a/include/mp/type-function.h +++ b/include/mp/type-function.h @@ -24,7 +24,7 @@ template void CustomBuildField(TypeList>, Priority<1>, InvokeContext& invoke_context, - Value& value, + Value&& value, Output&& output) { if (value) { From 688140b1dffc78a97a5a16f62b540a55824f4091 Mon Sep 17 00:00:00 2001 From: Ryan Ofsky Date: Tue, 3 Jun 2025 15:52:23 -0400 Subject: [PATCH 2/2] test: Add coverage for type-function.h --- test/mp/test/foo-types.h | 1 + test/mp/test/foo.capnp | 6 ++++++ test/mp/test/foo.h | 2 ++ test/mp/test/test.cpp | 2 ++ 4 files changed, 11 insertions(+) diff --git a/test/mp/test/foo-types.h b/test/mp/test/foo-types.h index 246b1948..aec5e49d 100644 --- a/test/mp/test/foo-types.h +++ b/test/mp/test/foo-types.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include diff --git a/test/mp/test/foo.capnp b/test/mp/test/foo.capnp index df0d4361..68104088 100644 --- a/test/mp/test/foo.capnp +++ b/test/mp/test/foo.capnp @@ -28,6 +28,7 @@ interface FooInterface $Proxy.wrap("mp::test::FooImplementation") { passMessage @13 (arg :FooMessage) -> (result :FooMessage); passMutable @14 (arg :FooMutable) -> (arg :FooMutable); passEnum @15 (arg :Int32) -> (result :Int32); + passFn @16 (context :Proxy.Context, fn :FooFn) -> (result :Int32); } interface FooCallback $Proxy.wrap("mp::test::FooCallback") { @@ -39,6 +40,11 @@ interface ExtendedCallback extends(FooCallback) $Proxy.wrap("mp::test::ExtendedC callExtended @0 (context :Proxy.Context, arg :Int32) -> (result :Int32); } +interface FooFn $Proxy.wrap("ProxyCallback>") { + destroy @0 (context :Proxy.Context) -> (); + call @1 (context :Proxy.Context) -> (result :Int32); +} + struct FooStruct $Proxy.wrap("mp::test::FooStruct") { name @0 :Text; setint @1 :List(Int32); diff --git a/test/mp/test/foo.h b/test/mp/test/foo.h index 1c5ee79f..468438fc 100644 --- a/test/mp/test/foo.h +++ b/test/mp/test/foo.h @@ -5,6 +5,7 @@ #ifndef MP_TEST_FOO_H #define MP_TEST_FOO_H +#include #include #include #include @@ -75,6 +76,7 @@ class FooImplementation FooMessage passMessage(FooMessage foo) { foo.message += " call"; return foo; } void passMutable(FooMutable& foo) { foo.message += " call"; } FooEnum passEnum(FooEnum foo) { return foo; } + int passFn(std::function fn) { return fn(); } std::shared_ptr m_callback; }; diff --git a/test/mp/test/test.cpp b/test/mp/test/test.cpp index 7fc64f67..b0635c4f 100644 --- a/test/mp/test/test.cpp +++ b/test/mp/test/test.cpp @@ -128,6 +128,8 @@ KJ_TEST("Call FooInterface methods") foo->passMutable(mut); KJ_EXPECT(mut.message == "init build pass call return read"); + KJ_EXPECT(foo->passFn([]{ return 10; }) == 10); + disconnect_client(); thread.join();