Merge "Add explicit NULL check to latinime_Keyboard_setProximityInfo() and ProximityInfo::ProximityInfo()."
commit
e76dbffe00
|
@ -33,21 +33,21 @@ static jint latinime_Keyboard_setProximityInfo(JNIEnv *env, jobject object,
|
|||
jint gridHeight, jintArray proximityCharsArray, jint keyCount,
|
||||
jintArray keyXCoordinateArray, jintArray keyYCoordinateArray, jintArray keyWidthArray,
|
||||
jintArray keyHeightArray, jintArray keyCharCodeArray) {
|
||||
jint* proximityChars = env->GetIntArrayElements(proximityCharsArray, NULL);
|
||||
jint* keyXCoordinates = env->GetIntArrayElements(keyXCoordinateArray, NULL);
|
||||
jint* keyYCoordinates = env->GetIntArrayElements(keyYCoordinateArray, NULL);
|
||||
jint* keyWidths = env->GetIntArrayElements(keyWidthArray, NULL);
|
||||
jint* keyHeights = env->GetIntArrayElements(keyHeightArray, NULL);
|
||||
jint* keyCharCodes = env->GetIntArrayElements(keyCharCodeArray, NULL);
|
||||
jint *proximityChars = env->GetIntArrayElements(proximityCharsArray, NULL);
|
||||
jint *keyXCoordinates = safeGetIntArrayElements(env, keyXCoordinateArray);
|
||||
jint *keyYCoordinates = safeGetIntArrayElements(env, keyYCoordinateArray);
|
||||
jint *keyWidths = safeGetIntArrayElements(env, keyWidthArray);
|
||||
jint *keyHeights = safeGetIntArrayElements(env, keyHeightArray);
|
||||
jint *keyCharCodes = safeGetIntArrayElements(env, keyCharCodeArray);
|
||||
ProximityInfo *proximityInfo = new ProximityInfo(maxProximityCharsSize, displayWidth,
|
||||
displayHeight, gridWidth, gridHeight, (const uint32_t *)proximityChars,
|
||||
keyCount, (const int32_t *)keyXCoordinates, (const int32_t *)keyYCoordinates,
|
||||
(const int32_t *)keyWidths, (const int32_t *)keyHeights, (const int32_t *)keyCharCodes);
|
||||
env->ReleaseIntArrayElements(keyCharCodeArray, keyCharCodes, 0);
|
||||
env->ReleaseIntArrayElements(keyHeightArray, keyHeights, 0);
|
||||
env->ReleaseIntArrayElements(keyWidthArray, keyWidths, 0);
|
||||
env->ReleaseIntArrayElements(keyYCoordinateArray, keyYCoordinates, 0);
|
||||
env->ReleaseIntArrayElements(keyXCoordinateArray, keyXCoordinates, 0);
|
||||
displayHeight, gridWidth, gridHeight, (const uint32_t*)proximityChars,
|
||||
keyCount, (const int32_t*)keyXCoordinates, (const int32_t*)keyYCoordinates,
|
||||
(const int32_t*)keyWidths, (const int32_t*)keyHeights, (const int32_t*)keyCharCodes);
|
||||
safeReleaseIntArrayElements(env, keyCharCodeArray, keyCharCodes);
|
||||
safeReleaseIntArrayElements(env, keyHeightArray, keyHeights);
|
||||
safeReleaseIntArrayElements(env, keyWidthArray, keyWidths);
|
||||
safeReleaseIntArrayElements(env, keyYCoordinateArray, keyYCoordinates);
|
||||
safeReleaseIntArrayElements(env, keyXCoordinateArray, keyXCoordinates);
|
||||
env->ReleaseIntArrayElements(proximityCharsArray, proximityChars, 0);
|
||||
return (jint)proximityInfo;
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ static JNINativeMethod sKeyboardMethods[] = {
|
|||
};
|
||||
|
||||
int register_ProximityInfo(JNIEnv *env) {
|
||||
const char* const kClassPathName = "com/android/inputmethod/keyboard/ProximityInfo";
|
||||
const char *const kClassPathName = "com/android/inputmethod/keyboard/ProximityInfo";
|
||||
return registerNativeMethods(env, kClassPathName, sKeyboardMethods,
|
||||
sizeof(sKeyboardMethods) / sizeof(sKeyboardMethods[0]));
|
||||
}
|
||||
|
|
|
@ -18,13 +18,29 @@
|
|||
#ifndef LATINIME_JNI_COMMON_H
|
||||
#define LATINIME_JNI_COMMON_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "jni.h"
|
||||
|
||||
namespace latinime {
|
||||
|
||||
int registerNativeMethods(JNIEnv* env, const char* className, JNINativeMethod* methods,
|
||||
int registerNativeMethods(JNIEnv *env, const char *className, JNINativeMethod *methods,
|
||||
int numMethods);
|
||||
|
||||
inline jint *safeGetIntArrayElements(JNIEnv *env, jintArray jArray) {
|
||||
if (jArray) {
|
||||
return env->GetIntArrayElements(jArray, NULL);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
inline void safeReleaseIntArrayElements(JNIEnv *env, jintArray jArray, jint *cArray) {
|
||||
if (jArray) {
|
||||
env->ReleaseIntArrayElements(jArray, cArray, 0);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace latinime
|
||||
|
||||
#endif // LATINIME_JNI_COMMON_H
|
||||
|
|
|
@ -26,6 +26,14 @@
|
|||
|
||||
namespace latinime {
|
||||
|
||||
inline void copyOrFillZero(void *to, const void *from, size_t size) {
|
||||
if (from) {
|
||||
memcpy(to, from, size);
|
||||
} else {
|
||||
memset(to, 0, size);
|
||||
}
|
||||
}
|
||||
|
||||
ProximityInfo::ProximityInfo(const int maxProximityCharsSize, const int keyboardWidth,
|
||||
const int keyboardHeight, const int gridWidth, const int gridHeight,
|
||||
const uint32_t *proximityCharsArray, const int keyCount, const int32_t *keyXCoordinates,
|
||||
|
@ -43,16 +51,11 @@ ProximityInfo::ProximityInfo(const int maxProximityCharsSize, const int keyboard
|
|||
}
|
||||
memcpy(mProximityCharsArray, proximityCharsArray, len * sizeof(mProximityCharsArray[0]));
|
||||
|
||||
if (KEY_COUNT > 0) {
|
||||
if (DEBUG_PROXIMITY_INFO) {
|
||||
LOGI("Create key coordinate array %d", keyCount);
|
||||
}
|
||||
memcpy(mKeyXCoordinates, keyXCoordinates, KEY_COUNT * sizeof(mKeyXCoordinates[0]));
|
||||
memcpy(mKeyYCoordinates, keyYCoordinates, KEY_COUNT * sizeof(mKeyYCoordinates[0]));
|
||||
memcpy(mKeyWidths, keyWidths, KEY_COUNT * sizeof(mKeyWidths[0]));
|
||||
memcpy(mKeyHeights, keyHeights, KEY_COUNT * sizeof(mKeyHeights[0]));
|
||||
memcpy(mKeyCharCodes, keyCharCodes, KEY_COUNT * sizeof(mKeyCharCodes[0]));
|
||||
}
|
||||
copyOrFillZero(mKeyXCoordinates, keyXCoordinates, KEY_COUNT * sizeof(mKeyXCoordinates[0]));
|
||||
copyOrFillZero(mKeyYCoordinates, keyYCoordinates, KEY_COUNT * sizeof(mKeyYCoordinates[0]));
|
||||
copyOrFillZero(mKeyWidths, keyWidths, KEY_COUNT * sizeof(mKeyWidths[0]));
|
||||
copyOrFillZero(mKeyHeights, keyHeights, KEY_COUNT * sizeof(mKeyHeights[0]));
|
||||
copyOrFillZero(mKeyCharCodes, keyCharCodes, KEY_COUNT * sizeof(mKeyCharCodes[0]));
|
||||
|
||||
initializeCodeToGroup();
|
||||
initializeCodeToKeyIndex();
|
||||
|
|
Loading…
Reference in New Issue