From 6d60b8b7f1f51a12b8d12d190687465845a2c806 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Fri, 10 Oct 2025 17:54:50 +1100 Subject: [PATCH] [orc-rt] Enable span use in SPSWrapperFunctions. SPS deserialization for span produces a value that points directly into the argument buffer for efficiency. This was broken by an unnecessary std::move of the buffer inside WrapperFunction, which this commit removes. --- orc-rt/include/orc-rt/SPSWrapperFunction.h | 2 +- orc-rt/include/orc-rt/WrapperFunction.h | 3 +-- orc-rt/unittests/SPSWrapperFunctionTest.cpp | 23 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/orc-rt/include/orc-rt/SPSWrapperFunction.h b/orc-rt/include/orc-rt/SPSWrapperFunction.h index 824e009306e2a..dc688223d9924 100644 --- a/orc-rt/include/orc-rt/SPSWrapperFunction.h +++ b/orc-rt/include/orc-rt/SPSWrapperFunction.h @@ -110,7 +110,7 @@ template struct WFSPSHelper { } template - std::optional deserialize(WrapperFunctionBuffer ArgBytes) { + std::optional deserialize(const WrapperFunctionBuffer &ArgBytes) { assert(!ArgBytes.getOutOfBandError() && "Should not attempt to deserialize out-of-band error"); SPSInputBuffer IB(ArgBytes.data(), ArgBytes.size()); diff --git a/orc-rt/include/orc-rt/WrapperFunction.h b/orc-rt/include/orc-rt/WrapperFunction.h index c43f1c5b4a753..6e8b84e980dc0 100644 --- a/orc-rt/include/orc-rt/WrapperFunction.h +++ b/orc-rt/include/orc-rt/WrapperFunction.h @@ -382,8 +382,7 @@ struct WrapperFunction { if (ArgBytes.getOutOfBandError()) return Return(Session, CallCtx, ArgBytes.release()); - if (auto Args = - S.arguments().template deserialize(std::move(ArgBytes))) + if (auto Args = S.arguments().template deserialize(ArgBytes)) std::apply(HandlerTraits::forwardArgsAsRequested(bind_front( std::forward(H), detail::StructuredYield( diff --git a/orc-rt/unittests/SPSWrapperFunctionTest.cpp b/orc-rt/unittests/SPSWrapperFunctionTest.cpp index d0f06e8d31451..ed085f2fef76c 100644 --- a/orc-rt/unittests/SPSWrapperFunctionTest.cpp +++ b/orc-rt/unittests/SPSWrapperFunctionTest.cpp @@ -95,6 +95,29 @@ TEST(SPSWrapperFunctionUtilsTest, BinaryOpViaFunctionPointer) { EXPECT_EQ(Result, 42); } +static void +round_trip_string_via_span_sps_wrapper(orc_rt_SessionRef Session, void *CallCtx, + orc_rt_WrapperFunctionReturn Return, + orc_rt_WrapperFunctionBuffer ArgBytes) { + SPSWrapperFunction::handle( + Session, CallCtx, Return, ArgBytes, + [](move_only_function Return, span S) { + Return({S.data(), S.size()}); + }); +} + +TEST(SPSWrapperFunctionUtilsTest, RoundTripStringViaSpan) { + /// Test that the SPSWrapperFunction<...>::handle call in + /// round_trip_string_via_span_sps_wrapper can deserialize into a usable + /// span. + std::string Result; + SPSWrapperFunction::call( + DirectCaller(nullptr, round_trip_string_via_span_sps_wrapper), + [&](Expected R) { Result = cantFail(std::move(R)); }, + std::string_view("hello, world!")); + EXPECT_EQ(Result, "hello, world!"); +} + static void improbable_feat_sps_wrapper(orc_rt_SessionRef Session, void *CallCtx, orc_rt_WrapperFunctionReturn Return,