Merge "Remove NULL from native/jni"
commit
7e8cf3c093
|
@ -35,7 +35,7 @@ static jint latinime_Keyboard_setProximityInfo(JNIEnv *env, jobject object,
|
||||||
jintArray keyHeightArray, jintArray keyCharCodeArray,
|
jintArray keyHeightArray, jintArray keyCharCodeArray,
|
||||||
jfloatArray sweetSpotCenterXArray, jfloatArray sweetSpotCenterYArray,
|
jfloatArray sweetSpotCenterXArray, jfloatArray sweetSpotCenterYArray,
|
||||||
jfloatArray sweetSpotRadiusArray) {
|
jfloatArray sweetSpotRadiusArray) {
|
||||||
jint *proximityChars = env->GetIntArrayElements(proximityCharsArray, NULL);
|
jint *proximityChars = env->GetIntArrayElements(proximityCharsArray, 0);
|
||||||
jint *keyXCoordinates = safeGetIntArrayElements(env, keyXCoordinateArray);
|
jint *keyXCoordinates = safeGetIntArrayElements(env, keyXCoordinateArray);
|
||||||
jint *keyYCoordinates = safeGetIntArrayElements(env, keyYCoordinateArray);
|
jint *keyYCoordinates = safeGetIntArrayElements(env, keyYCoordinateArray);
|
||||||
jint *keyWidths = safeGetIntArrayElements(env, keyWidthArray);
|
jint *keyWidths = safeGetIntArrayElements(env, keyWidthArray);
|
||||||
|
|
|
@ -48,13 +48,13 @@ static jint latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
|
||||||
jint maxAlternatives) {
|
jint maxAlternatives) {
|
||||||
PROF_OPEN;
|
PROF_OPEN;
|
||||||
PROF_START(66);
|
PROF_START(66);
|
||||||
const char *sourceDirChars = env->GetStringUTFChars(sourceDir, NULL);
|
const char *sourceDirChars = env->GetStringUTFChars(sourceDir, 0);
|
||||||
if (sourceDirChars == NULL) {
|
if (sourceDirChars == 0) {
|
||||||
LOGE("DICT: Can't get sourceDir string");
|
LOGE("DICT: Can't get sourceDir string");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int fd = 0;
|
int fd = 0;
|
||||||
void *dictBuf = NULL;
|
void *dictBuf = 0;
|
||||||
int adjust = 0;
|
int adjust = 0;
|
||||||
#ifdef USE_MMAP_FOR_DICTIONARY
|
#ifdef USE_MMAP_FOR_DICTIONARY
|
||||||
/* mmap version */
|
/* mmap version */
|
||||||
|
@ -67,7 +67,7 @@ static jint latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
|
||||||
adjust = dictOffset % pagesize;
|
adjust = dictOffset % pagesize;
|
||||||
int adjDictOffset = dictOffset - adjust;
|
int adjDictOffset = dictOffset - adjust;
|
||||||
int adjDictSize = dictSize + adjust;
|
int adjDictSize = dictSize + adjust;
|
||||||
dictBuf = mmap(NULL, sizeof(char) * adjDictSize, PROT_READ, MAP_PRIVATE, fd, adjDictOffset);
|
dictBuf = mmap(0, sizeof(char) * adjDictSize, PROT_READ, MAP_PRIVATE, fd, adjDictOffset);
|
||||||
if (dictBuf == MAP_FAILED) {
|
if (dictBuf == MAP_FAILED) {
|
||||||
LOGE("DICT: Can't mmap dictionary. errno=%d", errno);
|
LOGE("DICT: Can't mmap dictionary. errno=%d", errno);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -75,9 +75,9 @@ static jint latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
|
||||||
dictBuf = (void *)((char *)dictBuf + adjust);
|
dictBuf = (void *)((char *)dictBuf + adjust);
|
||||||
#else // USE_MMAP_FOR_DICTIONARY
|
#else // USE_MMAP_FOR_DICTIONARY
|
||||||
/* malloc version */
|
/* malloc version */
|
||||||
FILE *file = NULL;
|
FILE *file = 0;
|
||||||
file = fopen(sourceDirChars, "rb");
|
file = fopen(sourceDirChars, "rb");
|
||||||
if (file == NULL) {
|
if (file == 0) {
|
||||||
LOGE("DICT: Can't fopen sourceDir. sourceDirChars=%s errno=%d", sourceDirChars, errno);
|
LOGE("DICT: Can't fopen sourceDir. sourceDirChars=%s errno=%d", sourceDirChars, errno);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ static jint latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
|
||||||
LOGE("DICT: dictBuf is null");
|
LOGE("DICT: dictBuf is null");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Dictionary *dictionary = NULL;
|
Dictionary *dictionary = 0;
|
||||||
if (BinaryFormat::UNKNOWN_FORMAT == BinaryFormat::detectFormat((uint8_t*)dictBuf)) {
|
if (BinaryFormat::UNKNOWN_FORMAT == BinaryFormat::detectFormat((uint8_t*)dictBuf)) {
|
||||||
LOGE("DICT: dictionary format is unknown, bad magic number");
|
LOGE("DICT: dictionary format is unknown, bad magic number");
|
||||||
#ifdef USE_MMAP_FOR_DICTIONARY
|
#ifdef USE_MMAP_FOR_DICTIONARY
|
||||||
|
@ -133,12 +133,12 @@ static int latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jobject object,
|
||||||
if (!dictionary) return 0;
|
if (!dictionary) return 0;
|
||||||
ProximityInfo *pInfo = (ProximityInfo*)proximityInfo;
|
ProximityInfo *pInfo = (ProximityInfo*)proximityInfo;
|
||||||
|
|
||||||
int *xCoordinates = env->GetIntArrayElements(xCoordinatesArray, NULL);
|
int *xCoordinates = env->GetIntArrayElements(xCoordinatesArray, 0);
|
||||||
int *yCoordinates = env->GetIntArrayElements(yCoordinatesArray, NULL);
|
int *yCoordinates = env->GetIntArrayElements(yCoordinatesArray, 0);
|
||||||
|
|
||||||
int *frequencies = env->GetIntArrayElements(frequencyArray, NULL);
|
int *frequencies = env->GetIntArrayElements(frequencyArray, 0);
|
||||||
int *inputCodes = env->GetIntArrayElements(inputArray, NULL);
|
int *inputCodes = env->GetIntArrayElements(inputArray, 0);
|
||||||
jchar *outputChars = env->GetCharArrayElements(outputArray, NULL);
|
jchar *outputChars = env->GetCharArrayElements(outputArray, 0);
|
||||||
|
|
||||||
int count = dictionary->getSuggestions(pInfo, xCoordinates, yCoordinates, inputCodes,
|
int count = dictionary->getSuggestions(pInfo, xCoordinates, yCoordinates, inputCodes,
|
||||||
arraySize, flags, (unsigned short*) outputChars, frequencies);
|
arraySize, flags, (unsigned short*) outputChars, frequencies);
|
||||||
|
@ -159,10 +159,10 @@ static int latinime_BinaryDictionary_getBigrams(JNIEnv *env, jobject object, jin
|
||||||
Dictionary *dictionary = (Dictionary*)dict;
|
Dictionary *dictionary = (Dictionary*)dict;
|
||||||
if (!dictionary) return 0;
|
if (!dictionary) return 0;
|
||||||
|
|
||||||
jchar *prevWord = env->GetCharArrayElements(prevWordArray, NULL);
|
jchar *prevWord = env->GetCharArrayElements(prevWordArray, 0);
|
||||||
int *inputCodes = env->GetIntArrayElements(inputArray, NULL);
|
int *inputCodes = env->GetIntArrayElements(inputArray, 0);
|
||||||
jchar *outputChars = env->GetCharArrayElements(outputArray, NULL);
|
jchar *outputChars = env->GetCharArrayElements(outputArray, 0);
|
||||||
int *frequencies = env->GetIntArrayElements(frequencyArray, NULL);
|
int *frequencies = env->GetIntArrayElements(frequencyArray, 0);
|
||||||
|
|
||||||
int count = dictionary->getBigrams((unsigned short*) prevWord, prevWordLength, inputCodes,
|
int count = dictionary->getBigrams((unsigned short*) prevWord, prevWordLength, inputCodes,
|
||||||
inputArraySize, (unsigned short*) outputChars, frequencies, maxWordLength, maxBigrams,
|
inputArraySize, (unsigned short*) outputChars, frequencies, maxWordLength, maxBigrams,
|
||||||
|
@ -181,7 +181,7 @@ static jboolean latinime_BinaryDictionary_isValidWord(JNIEnv *env, jobject objec
|
||||||
Dictionary *dictionary = (Dictionary*)dict;
|
Dictionary *dictionary = (Dictionary*)dict;
|
||||||
if (!dictionary) return (jboolean) false;
|
if (!dictionary) return (jboolean) false;
|
||||||
|
|
||||||
jchar *word = env->GetCharArrayElements(wordArray, NULL);
|
jchar *word = env->GetCharArrayElements(wordArray, 0);
|
||||||
jboolean result = dictionary->isValidWord((unsigned short*) word, wordLength);
|
jboolean result = dictionary->isValidWord((unsigned short*) word, wordLength);
|
||||||
env->ReleaseCharArrayElements(wordArray, word, JNI_ABORT);
|
env->ReleaseCharArrayElements(wordArray, word, JNI_ABORT);
|
||||||
|
|
||||||
|
|
|
@ -32,14 +32,14 @@ using namespace latinime;
|
||||||
* Returns the JNI version on success, -1 on failure.
|
* Returns the JNI version on success, -1 on failure.
|
||||||
*/
|
*/
|
||||||
jint JNI_OnLoad(JavaVM* vm, void* reserved) {
|
jint JNI_OnLoad(JavaVM* vm, void* reserved) {
|
||||||
JNIEnv* env = NULL;
|
JNIEnv* env = 0;
|
||||||
jint result = -1;
|
jint result = -1;
|
||||||
|
|
||||||
if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
|
if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
|
||||||
LOGE("ERROR: GetEnv failed");
|
LOGE("ERROR: GetEnv failed");
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
assert(env != NULL);
|
assert(env != 0);
|
||||||
|
|
||||||
if (!register_BinaryDictionary(env)) {
|
if (!register_BinaryDictionary(env)) {
|
||||||
LOGE("ERROR: BinaryDictionary native registration failed");
|
LOGE("ERROR: BinaryDictionary native registration failed");
|
||||||
|
@ -63,7 +63,7 @@ namespace latinime {
|
||||||
int registerNativeMethods(JNIEnv* env, const char* className, JNINativeMethod* methods,
|
int registerNativeMethods(JNIEnv* env, const char* className, JNINativeMethod* methods,
|
||||||
int numMethods) {
|
int numMethods) {
|
||||||
jclass clazz = env->FindClass(className);
|
jclass clazz = env->FindClass(className);
|
||||||
if (clazz == NULL) {
|
if (clazz == 0) {
|
||||||
LOGE("Native registration unable to find class '%s'", className);
|
LOGE("Native registration unable to find class '%s'", className);
|
||||||
return JNI_FALSE;
|
return JNI_FALSE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,17 +29,17 @@ int registerNativeMethods(JNIEnv *env, const char *className, JNINativeMethod *m
|
||||||
|
|
||||||
inline jint *safeGetIntArrayElements(JNIEnv *env, jintArray jArray) {
|
inline jint *safeGetIntArrayElements(JNIEnv *env, jintArray jArray) {
|
||||||
if (jArray) {
|
if (jArray) {
|
||||||
return env->GetIntArrayElements(jArray, NULL);
|
return env->GetIntArrayElements(jArray, 0);
|
||||||
} else {
|
} else {
|
||||||
return NULL;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline jfloat *safeGetFloatArrayElements(JNIEnv *env, jfloatArray jArray) {
|
inline jfloat *safeGetFloatArrayElements(JNIEnv *env, jfloatArray jArray) {
|
||||||
if (jArray) {
|
if (jArray) {
|
||||||
return env->GetFloatArrayElements(jArray, NULL);
|
return env->GetFloatArrayElements(jArray, 0);
|
||||||
} else {
|
} else {
|
||||||
return NULL;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue