From bd64ecbc163e057e68fe3cf455065e29e25643bc Mon Sep 17 00:00:00 2001 From: LoveSy Date: Tue, 23 Jul 2024 03:01:05 +0800 Subject: [PATCH] Fix array manipulation --- .../src/main/jni/include/utils/jni_helper.hpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lsplant/src/main/jni/include/utils/jni_helper.hpp b/lsplant/src/main/jni/include/utils/jni_helper.hpp index 89284cd..1bca68c 100644 --- a/lsplant/src/main/jni/include/utils/jni_helper.hpp +++ b/lsplant/src/main/jni/include/utils/jni_helper.hpp @@ -1057,6 +1057,18 @@ public: return *this; } + template + JObjectArrayElement &operator=(ScopedLocalRef &&s) { + reset(s.release()); + return *this; + } + + template + JObjectArrayElement &operator=(ScopedLocalRef &s) { + reset(s.clone()); + return *this; + } + JObjectArrayElement &operator=(jobject s) { reset(env_->NewLocalRef(s)); return *this; @@ -1215,9 +1227,7 @@ public: jobjectArray get() const { return local_ref_; } JObjectArrayElement operator[](size_t index) { - return JObjectArrayElement( - env_, local_ref_, index, - JNI_SafeInvoke(env_, &JNIEnv::GetObjectArrayElement, local_ref_, index)); + return JObjectArrayElement(env_, local_ref_, index, size_); } const ScopedLocalRef operator[](size_t index) const {