From de256fd38a87c6aafed26eff7178413792b914cf Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Fri, 27 Dec 2019 15:04:55 -0800 Subject: [PATCH] Make WrapForVoidReturn take a function pointer instead of a function 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 --- .../fbjni/cxx/fbjni/detail/Registration-inl.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/first-party/fbjni/cxx/fbjni/detail/Registration-inl.h b/first-party/fbjni/cxx/fbjni/detail/Registration-inl.h index 3c8a8a6c171..defd3d666c6 100644 --- a/first-party/fbjni/cxx/fbjni/detail/Registration-inl.h +++ b/first-party/fbjni/cxx/fbjni/detail/Registration-inl.h @@ -51,16 +51,16 @@ struct CreateDefault { template using Converter = Convert::type>; -template +template struct WrapForVoidReturn { - static typename Converter::jniType call(Args&&... args) { + static typename Converter::jniType call(Args&&... args, F func) { return Converter::toJniRet(func(std::forward(args)...)); } }; -template -struct WrapForVoidReturn { - static void call(Args&&... args) { +template +struct WrapForVoidReturn { + static void call(Args&&... args, F func) { func(std::forward(args)...); } }; @@ -86,8 +86,8 @@ struct FunctionWrapper { JNI_ENTRY_POINT static jniRet call(JNIEnv* env, jobject obj, typename Converter::jniType... args) { detail::JniEnvCacher jec(env); try { - return WrapForVoidReturn, Args...>::call( - static_cast>(obj), Converter::fromJni(args)...); + return WrapForVoidReturn, Args...>::call( + static_cast>(obj), Converter::fromJni(args)..., func); } catch (...) { translatePendingCppExceptionToJavaException(); return CreateDefault::create();