JNI: simplify implementation of native function wrappers

When declaring native callback functions with the JNI type system, then
we actually register a helper function with variadic arguments, and
implement that to forward the arguments to the declared function, which
then might use higher-level types as arguments. We deduce those
higher-level types through a variadic template, and use std::tuple as
well as std::apply to generate the calls.

Simplify the implementation by using std::make_tuple, and replace
q20:remove_cvref_t with std::decay_t; this is what std::make_tuple uses,
and we don't need to maintain functions and arrays as such.

Found during 6.7 header review.

Task-number: QTBUG-119952
Change-Id: I7cd206c6b372c2ec62a10feb5f9253f5607f01a9
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit 76cf922980cf0cde7cb03f4bec8f17eab94a5767)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Volker Hilsheimer 2024-01-30 15:19:23 +01:00 committed by Qt Cherry-pick Bot
parent e20f2a6c8b
commit db5e112419

View File

@ -96,20 +96,18 @@ struct JNITypeForArgImpl<QString>
};
template <typename Arg>
using JNITypeForArg = typename JNITypeForArgImpl<q20::remove_cvref_t<Arg>>::Type;
using JNITypeForArg = typename JNITypeForArgImpl<std::decay_t<Arg>>::Type;
template <typename Arg, typename Type>
static inline auto methodArgFromVarArg(Type &&t)
{
return JNITypeForArgImpl<q20::remove_cvref_t<Arg>>::fromVarArg(std::move(t));
return JNITypeForArgImpl<std::decay_t<Arg>>::fromVarArg(std::move(t));
}
// Turn a va_list into a tuple of typed arguments
template <typename ...Args>
static constexpr auto makeTupleFromArgsHelper(va_list args)
{
return std::tuple<q20::remove_cvref_t<Args>...>{
methodArgFromVarArg<q20::remove_cvref_t<Args>>(va_arg(args, JNITypeForArg<Args>))...
};
return std::tuple(methodArgFromVarArg<Args>(va_arg(args, JNITypeForArg<Args>))...);
}
template <typename Ret, typename ...Args>