JNI: don't implement a signature for 'long' C++ type

On Android, `long` has the width of the system, while `jlong` is always
64 bit. If we support `long` as a signature type equivalent to `jlong`,
then it becomes possible to write code that fails to compile, or in the
worst case crashes at runtime, on a 32bit system.

Instead, support quint64, which is always the same size as jlong.

Change-Id: I60432ec7411e697b5f6e1f153216ceee0af7e0f1
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
bb10
Volker Hilsheimer 2023-10-31 11:28:51 +08:00
parent 45c6ef02e7
commit e21d35b9f7
3 changed files with 4 additions and 4 deletions

View File

@ -221,7 +221,7 @@ struct Traits {
return CTString("I");
} else if constexpr (std::is_same_v<T, jlong>) {
return CTString("J");
} else if constexpr (std::is_same_v<T, long>) {
} else if constexpr (std::is_same_v<T, quint64>) {
return CTString("J");
} else if constexpr (std::is_same_v<T, jfloat>) {
return CTString("F");

View File

@ -28,7 +28,7 @@ void QAndroidPlatformClipboard::onClipboardDataChanged(JNIEnv *env, jobject obj,
QAndroidPlatformClipboard::QAndroidPlatformClipboard()
{
m_clipboardManager = QtClipboardManager::construct(QtAndroidPrivate::context(),
reinterpret_cast<long>(this));
reinterpret_cast<jlong>(this));
}
QAndroidPlatformClipboard::~QAndroidPlatformClipboard()

View File

@ -137,7 +137,7 @@ enum class IntEnum : int {};
enum class UnsignedEnum : unsigned {};
enum class Int8Enum : int8_t {};
enum class ShortEnum : short {};
enum class LongEnum : long {};
enum class LongEnum : quint64 {};
enum class JIntEnum : jint {};
static_assert(QtJniTypes::Traits<UnscopedEnum>::signature() == "I");
@ -153,7 +153,7 @@ void tst_QJniTypes::initTestCase()
}
static bool nativeFunction(JNIEnv *, jclass, int, jstring, long)
static bool nativeFunction(JNIEnv *, jclass, int, jstring, quint64)
{
return true;
}