[orc-rt] Enable span<const char> use in SPSWrapperFunctions. (#162792)

SPS deserialization for span<const char> 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.
This commit is contained in:
Lang Hames
2025-10-10 19:38:10 +11:00
committed by GitHub
parent aa406aaa67
commit ef4598fbc6
3 changed files with 25 additions and 3 deletions

View File

@@ -110,7 +110,7 @@ public:
}
template <typename ArgTuple>
std::optional<ArgTuple> deserialize(WrapperFunctionBuffer ArgBytes) {
std::optional<ArgTuple> deserialize(const WrapperFunctionBuffer &ArgBytes) {
assert(!ArgBytes.getOutOfBandError() &&
"Should not attempt to deserialize out-of-band error");
SPSInputBuffer IB(ArgBytes.data(), ArgBytes.size());

View File

@@ -382,8 +382,7 @@ struct WrapperFunction {
if (ArgBytes.getOutOfBandError())
return Return(Session, CallCtx, ArgBytes.release());
if (auto Args =
S.arguments().template deserialize<ArgTuple>(std::move(ArgBytes)))
if (auto Args = S.arguments().template deserialize<ArgTuple>(ArgBytes))
std::apply(HandlerTraits::forwardArgsAsRequested(bind_front(
std::forward<Handler>(H),
detail::StructuredYield<RetTupleType, Serializer>(

View File

@@ -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<SPSString(SPSString)>::handle(
Session, CallCtx, Return, ArgBytes,
[](move_only_function<void(std::string)> Return, span<const char> 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<const char>.
std::string Result;
SPSWrapperFunction<SPSString(SPSString)>::call(
DirectCaller(nullptr, round_trip_string_via_span_sps_wrapper),
[&](Expected<std::string> 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,