mirror of
https://github.com/intel/llvm.git
synced 2026-01-13 02:38:07 +08:00
[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:
@@ -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());
|
||||
|
||||
@@ -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>(
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user