Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit afd641f

Browse files
authored
[orc-rt] Make WrapperFunctionResult constructor explicit. (#176298)
The WrapperFunctionBuffer(orc_rt_WrapperFunctionBuffer) constructor takes ownership of the underlying buffer (if one exists). Making the constructor explicit makes this clearer at the call site. This mirrors a similar change to the LLVM-side API in dec5d66.
1 parent 10fea27 commit afd641f

7 files changed

Lines changed: 26 additions & 14 deletions

File tree

orc-rt/include/orc-rt/AllocAction.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct AllocActionFunction {
5757
return WrapperFunctionBuffer::createOutOfBandError(
5858
"Could not deserialize allocation action argument buffer");
5959

60-
return std::apply(std::forward<Handler>(H), std::move(Args)).release();
60+
return std::apply(std::forward<Handler>(H), std::move(Args));
6161
}
6262
};
6363

@@ -69,7 +69,7 @@ struct AllocAction {
6969

7070
[[nodiscard]] WrapperFunctionBuffer operator()() {
7171
assert(Fn && "Attempt to call null action");
72-
return Fn(ArgData.data(), ArgData.size());
72+
return WrapperFunctionBuffer(Fn(ArgData.data(), ArgData.size()));
7373
}
7474

7575
explicit operator bool() const noexcept { return !!Fn; }

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,16 @@ template <typename SPSSig> struct SPSWrapperFunction {
131131
WrapperFunctionSPSSerializer<SPSSig>(),
132132
std::forward<Handler>(H));
133133
}
134+
135+
/// Convenience override that takes ArgBytes as an
136+
/// orc_rt_WrapperFunctionBuffer.
137+
template <typename Handler>
138+
static void handle(orc_rt_SessionRef S, uint64_t CallId,
139+
orc_rt_WrapperFunctionReturn Return,
140+
orc_rt_WrapperFunctionBuffer ArgBytes, Handler &&H) {
141+
handle(S, CallId, Return, WrapperFunctionBuffer(ArgBytes),
142+
std::forward<Handler>(H));
143+
}
134144
};
135145

136146
} // namespace orc_rt

orc-rt/include/orc-rt/Session.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,8 @@ class Session {
156156
if (auto TmpCA = CA)
157157
CA->callController(std::move(OnComplete), T, std::move(ArgBytes));
158158
else
159-
OnComplete(
160-
WrapperFunctionBuffer::createOutOfBandError("no controller attached")
161-
.release());
159+
OnComplete(WrapperFunctionBuffer::createOutOfBandError(
160+
"no controller attached"));
162161
}
163162

164163
private:

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class WrapperFunctionBuffer {
3434
/// Create a WrapperFunctionBuffer from a WrapperFunctionBuffer. This
3535
/// instance takes ownership of the result object and will automatically
3636
/// call dispose on the result upon destruction.
37-
WrapperFunctionBuffer(orc_rt_WrapperFunctionBuffer B) : B(B) {}
37+
explicit WrapperFunctionBuffer(orc_rt_WrapperFunctionBuffer B) : B(B) {}
3838

3939
WrapperFunctionBuffer(const WrapperFunctionBuffer &) = delete;
4040
WrapperFunctionBuffer &operator=(const WrapperFunctionBuffer &) = delete;
@@ -78,22 +78,25 @@ class WrapperFunctionBuffer {
7878
/// Create a WrapperFunctionBuffer with the given size and return a pointer
7979
/// to the underlying memory.
8080
static WrapperFunctionBuffer allocate(size_t Size) {
81-
return orc_rt_WrapperFunctionBufferAllocate(Size);
81+
return WrapperFunctionBuffer(orc_rt_WrapperFunctionBufferAllocate(Size));
8282
}
8383

8484
/// Copy from the given char range.
8585
static WrapperFunctionBuffer copyFrom(const char *Source, size_t Size) {
86-
return orc_rt_CreateWrapperFunctionBufferFromRange(Source, Size);
86+
return WrapperFunctionBuffer(
87+
orc_rt_CreateWrapperFunctionBufferFromRange(Source, Size));
8788
}
8889

8990
/// Copy from the given null-terminated string (includes the null-terminator).
9091
static WrapperFunctionBuffer copyFrom(const char *Source) {
91-
return orc_rt_CreateWrapperFunctionBufferFromString(Source);
92+
return WrapperFunctionBuffer(
93+
orc_rt_CreateWrapperFunctionBufferFromString(Source));
9294
}
9395

9496
/// Create an out-of-band error by copying the given string.
9597
static WrapperFunctionBuffer createOutOfBandError(const char *Msg) {
96-
return orc_rt_CreateWrapperFunctionBufferFromOutOfBandError(Msg);
98+
return WrapperFunctionBuffer(
99+
orc_rt_CreateWrapperFunctionBufferFromOutOfBandError(Msg));
97100
}
98101

99102
/// If this value is an out-of-band error then this returns the error message,

orc-rt/lib/executor/Session.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void Session::shutdownComplete() {
100100

101101
void Session::wrapperReturn(orc_rt_SessionRef S, uint64_t CallId,
102102
orc_rt_WrapperFunctionBuffer ResultBytes) {
103-
unwrap(S)->sendWrapperResult(CallId, ResultBytes);
103+
unwrap(S)->sendWrapperResult(CallId, WrapperFunctionBuffer(ResultBytes));
104104
}
105105

106106
} // namespace orc_rt

orc-rt/unittests/DirectCaller.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class DirectCaller {
2727
std::unique_ptr<DirectResultSender>(
2828
reinterpret_cast<DirectResultSender *>(
2929
static_cast<uintptr_t>(CallId)))
30-
->send(S, ResultBytes);
30+
->send(S, orc_rt::WrapperFunctionBuffer(ResultBytes));
3131
}
3232
};
3333

orc-rt/unittests/SessionTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ class MockControllerAccess : public Session::ControllerAccess {
227227
orc_rt_WrapperFunctionBuffer ResultBytes) {
228228
// Abuse "session" to refer to the ControllerAccess object.
229229
// We can just re-use sendFunctionResult for this.
230-
reinterpret_cast<MockControllerAccess *>(S)->sendWrapperResult(CallId,
231-
ResultBytes);
230+
reinterpret_cast<MockControllerAccess *>(S)->sendWrapperResult(
231+
CallId, WrapperFunctionBuffer(ResultBytes));
232232
}
233233

234234
Session &SS;

0 commit comments

Comments
 (0)