Skip to content

Commit

Permalink
Make WrapForVoidReturn take a function pointer instead of a function …
Browse files Browse the repository at this point in the history
…template argument

Summary: Rather than inlining this code into every `FunctionWrapper`, we let every `FunctionWrapper` with the same signature call into this code and pass a different function pointer.

Reviewed By: cjhopman

Differential Revision: D19049680

fbshipit-source-id: 10a32b6b696bf00e0d9b8a78ff7b1cd40563abbf
  • Loading branch information
swolchok authored and facebook-github-bot committed Dec 27, 2019
1 parent f016be1 commit de256fd
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions first-party/fbjni/cxx/fbjni/detail/Registration-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ struct CreateDefault<void> {
template <typename R>
using Converter = Convert<typename std::decay<R>::type>;

template <typename F, F func, typename R, typename... Args>
template <typename F, typename R, typename... Args>
struct WrapForVoidReturn {
static typename Converter<R>::jniType call(Args&&... args) {
static typename Converter<R>::jniType call(Args&&... args, F func) {
return Converter<R>::toJniRet(func(std::forward<Args>(args)...));
}
};

template <typename F, F func, typename... Args>
struct WrapForVoidReturn<F, func, void, Args...> {
static void call(Args&&... args) {
template <typename F, typename... Args>
struct WrapForVoidReturn<F, void, Args...> {
static void call(Args&&... args, F func) {
func(std::forward<Args>(args)...);
}
};
Expand All @@ -86,8 +86,8 @@ struct FunctionWrapper {
JNI_ENTRY_POINT static jniRet call(JNIEnv* env, jobject obj, typename Converter<Args>::jniType... args) {
detail::JniEnvCacher jec(env);
try {
return WrapForVoidReturn<F, func, R, JniType<C>, Args...>::call(
static_cast<JniType<C>>(obj), Converter<Args>::fromJni(args)...);
return WrapForVoidReturn<F, R, JniType<C>, Args...>::call(
static_cast<JniType<C>>(obj), Converter<Args>::fromJni(args)..., func);
} catch (...) {
translatePendingCppExceptionToJavaException();
return CreateDefault<jniRet>::create();
Expand Down

0 comments on commit de256fd

Please sign in to comment.