From db5e112419c4b14185c32320994c9fa7dd68cd97 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 30 Jan 2024 15:19:23 +0100 Subject: [PATCH] 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 (cherry picked from commit 76cf922980cf0cde7cb03f4bec8f17eab94a5767) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/kernel/qjnitypes.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/corelib/kernel/qjnitypes.h b/src/corelib/kernel/qjnitypes.h index 56af657fa30..71c4db670ce 100644 --- a/src/corelib/kernel/qjnitypes.h +++ b/src/corelib/kernel/qjnitypes.h @@ -96,20 +96,18 @@ struct JNITypeForArgImpl }; template -using JNITypeForArg = typename JNITypeForArgImpl>::Type; +using JNITypeForArg = typename JNITypeForArgImpl>::Type; template static inline auto methodArgFromVarArg(Type &&t) { - return JNITypeForArgImpl>::fromVarArg(std::move(t)); + return JNITypeForArgImpl>::fromVarArg(std::move(t)); } // Turn a va_list into a tuple of typed arguments template static constexpr auto makeTupleFromArgsHelper(va_list args) { - return std::tuple...>{ - methodArgFromVarArg>(va_arg(args, JNITypeForArg))... - }; + return std::tuple(methodArgFromVarArg(va_arg(args, JNITypeForArg))...); } template