Skip to content

Commit ef4598f

Browse files
authored
[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.
1 parent aa406aa commit ef4598f

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

orc-rt/include/orc-rt/SPSWrapperFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ template <typename... SPSArgTs> struct WFSPSHelper {
110110
}
111111

112112
template <typename ArgTuple>
113-
std::optional<ArgTuple> deserialize(WrapperFunctionBuffer ArgBytes) {
113+
std::optional<ArgTuple> deserialize(const WrapperFunctionBuffer &ArgBytes) {
114114
assert(!ArgBytes.getOutOfBandError() &&
115115
"Should not attempt to deserialize out-of-band error");
116116
SPSInputBuffer IB(ArgBytes.data(), ArgBytes.size());

orc-rt/include/orc-rt/WrapperFunction.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,7 @@ struct WrapperFunction {
382382
if (ArgBytes.getOutOfBandError())
383383
return Return(Session, CallCtx, ArgBytes.release());
384384

385-
if (auto Args =
386-
S.arguments().template deserialize<ArgTuple>(std::move(ArgBytes)))
385+
if (auto Args = S.arguments().template deserialize<ArgTuple>(ArgBytes))
387386
std::apply(HandlerTraits::forwardArgsAsRequested(bind_front(
388387
std::forward<Handler>(H),
389388
detail::StructuredYield<RetTupleType, Serializer>(

orc-rt/unittests/SPSWrapperFunctionTest.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,29 @@ TEST(SPSWrapperFunctionUtilsTest, BinaryOpViaFunctionPointer) {
9595
EXPECT_EQ(Result, 42);
9696
}
9797

98+
static void
99+
round_trip_string_via_span_sps_wrapper(orc_rt_SessionRef Session, void *CallCtx,
100+
orc_rt_WrapperFunctionReturn Return,
101+
orc_rt_WrapperFunctionBuffer ArgBytes) {
102+
SPSWrapperFunction<SPSString(SPSString)>::handle(
103+
Session, CallCtx, Return, ArgBytes,
104+
[](move_only_function<void(std::string)> Return, span<const char> S) {
105+
Return({S.data(), S.size()});
106+
});
107+
}
108+
109+
TEST(SPSWrapperFunctionUtilsTest, RoundTripStringViaSpan) {
110+
/// Test that the SPSWrapperFunction<...>::handle call in
111+
/// round_trip_string_via_span_sps_wrapper can deserialize into a usable
112+
/// span<const char>.
113+
std::string Result;
114+
SPSWrapperFunction<SPSString(SPSString)>::call(
115+
DirectCaller(nullptr, round_trip_string_via_span_sps_wrapper),
116+
[&](Expected<std::string> R) { Result = cantFail(std::move(R)); },
117+
std::string_view("hello, world!"));
118+
EXPECT_EQ(Result, "hello, world!");
119+
}
120+
98121
static void improbable_feat_sps_wrapper(orc_rt_SessionRef Session,
99122
void *CallCtx,
100123
orc_rt_WrapperFunctionReturn Return,

0 commit comments

Comments
 (0)