Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions orc-rt/include/orc-rt/WrapperFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ struct WFCallableTraits<RetT(ArgT, ArgTs...)> {
typedef std::tuple<ArgTs...> TailArgTuple;
};

template <typename RetT, typename... ArgTs>
struct WFCallableTraits<RetT (*)(ArgTs...)>
: public WFCallableTraits<RetT(ArgTs...)> {};

template <typename RetT, typename... ArgTs>
struct WFCallableTraits<RetT (&)(ArgTs...)>
: public WFCallableTraits<RetT(ArgTs...)> {};

template <typename ClassT, typename RetT, typename... ArgTs>
struct WFCallableTraits<RetT (ClassT::*)(ArgTs...)>
: public WFCallableTraits<RetT(ArgTs...)> {};
Expand Down
47 changes: 42 additions & 5 deletions orc-rt/unittests/SPSWrapperFunctionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,57 @@ TEST(SPSWrapperFunctionUtilsTest, TestVoidNoop) {
EXPECT_TRUE(Ran);
}

static void add_sps_wrapper(orc_rt_SessionRef Session, void *CallCtx,
orc_rt_WrapperFunctionReturn Return,
orc_rt_WrapperFunctionBuffer ArgBytes) {
static void add_via_lambda_sps_wrapper(orc_rt_SessionRef Session, void *CallCtx,
orc_rt_WrapperFunctionReturn Return,
orc_rt_WrapperFunctionBuffer ArgBytes) {
SPSWrapperFunction<int32_t(int32_t, int32_t)>::handle(
Session, CallCtx, Return, ArgBytes,
[](move_only_function<void(int32_t)> Return, int32_t X, int32_t Y) {
Return(X + Y);
});
}

TEST(SPSWrapperFunctionUtilsTest, TestAdd) {
TEST(SPSWrapperFunctionUtilsTest, TestBinaryOpViaLambda) {
int32_t Result = 0;
SPSWrapperFunction<int32_t(int32_t, int32_t)>::call(
DirectCaller(nullptr, add_sps_wrapper),
DirectCaller(nullptr, add_via_lambda_sps_wrapper),
[&](Expected<int32_t> R) { Result = cantFail(std::move(R)); }, 41, 1);
EXPECT_EQ(Result, 42);
}

static void add_via_function(move_only_function<void(int32_t)> Return,
int32_t X, int32_t Y) {
Return(X + Y);
}

static void
add_via_function_sps_wrapper(orc_rt_SessionRef Session, void *CallCtx,
orc_rt_WrapperFunctionReturn Return,
orc_rt_WrapperFunctionBuffer ArgBytes) {
SPSWrapperFunction<int32_t(int32_t, int32_t)>::handle(
Session, CallCtx, Return, ArgBytes, add_via_function);
}

TEST(SPSWrapperFunctionUtilsTest, TestBinaryOpViaFunction) {
int32_t Result = 0;
SPSWrapperFunction<int32_t(int32_t, int32_t)>::call(
DirectCaller(nullptr, add_via_function_sps_wrapper),
[&](Expected<int32_t> R) { Result = cantFail(std::move(R)); }, 41, 1);
EXPECT_EQ(Result, 42);
}

static void
add_via_function_pointer_sps_wrapper(orc_rt_SessionRef Session, void *CallCtx,
orc_rt_WrapperFunctionReturn Return,
orc_rt_WrapperFunctionBuffer ArgBytes) {
SPSWrapperFunction<int32_t(int32_t, int32_t)>::handle(
Session, CallCtx, Return, ArgBytes, &add_via_function);
}

TEST(SPSWrapperFunctionUtilsTest, TestBinaryOpViaFunctionPointer) {
int32_t Result = 0;
SPSWrapperFunction<int32_t(int32_t, int32_t)>::call(
DirectCaller(nullptr, add_via_function_pointer_sps_wrapper),
[&](Expected<int32_t> R) { Result = cantFail(std::move(R)); }, 41, 1);
EXPECT_EQ(Result, 42);
}
Loading