Use more idiomatic and implicit pointer dereference

This commit is contained in:
Ebrahim Byagowi 2019-04-22 22:05:27 +04:30 committed by Peter Osterlund
parent e975dd5ff4
commit 80e8183757
3 changed files with 28 additions and 28 deletions

View File

@ -31,7 +31,7 @@ JNICALL Java_org_petero_droidfish_tb_GtbProbe_init(
JNIEnv* env, jclass cls, jstring jTbPath)
{
initOk = false;
const char* tbPath = (*env).GetStringUTFChars(jTbPath, NULL);
const char* tbPath = env->GetStringUTFChars(jTbPath, NULL);
if (!tbPath)
return false;
@ -39,12 +39,12 @@ JNICALL Java_org_petero_droidfish_tb_GtbProbe_init(
tbpaths_done(paths);
paths = tbpaths_init();
if (paths == NULL) {
(*env).ReleaseStringUTFChars(jTbPath, tbPath);
env->ReleaseStringUTFChars(jTbPath, tbPath);
return false;
}
paths = tbpaths_add(paths, tbPath);
if (paths == NULL) {
(*env).ReleaseStringUTFChars(jTbPath, tbPath);
env->ReleaseStringUTFChars(jTbPath, tbPath);
return false;
}
@ -61,7 +61,7 @@ JNICALL Java_org_petero_droidfish_tb_GtbProbe_init(
}
isInitialized = true;
(*env).ReleaseStringUTFChars(jTbPath, tbPath);
env->ReleaseStringUTFChars(jTbPath, tbPath);
initOk = true;
return true;
}
@ -79,7 +79,7 @@ JNICALL Java_org_petero_droidfish_tb_GtbProbe_probeHard(
{
if (!initOk)
return false;
if ((*env).GetArrayLength(result) < 2)
if (env->GetArrayLength(result) < 2)
return false;
const int MAXLEN = 17;
@ -88,29 +88,29 @@ JNICALL Java_org_petero_droidfish_tb_GtbProbe_probeHard(
unsigned char bp[MAXLEN];
unsigned int bs[MAXLEN];
int len = (*env).GetArrayLength(whiteSquares);
jint* jiPtr = (*env).GetIntArrayElements(whiteSquares, NULL);
int len = env->GetArrayLength(whiteSquares);
jint* jiPtr = env->GetIntArrayElements(whiteSquares, NULL);
for (int i = 0; i < min(len, MAXLEN); i++)
ws[i] = jiPtr[i];
(*env).ReleaseIntArrayElements(whiteSquares, jiPtr, 0);
env->ReleaseIntArrayElements(whiteSquares, jiPtr, 0);
len = (*env).GetArrayLength(blackSquares);
jiPtr = (*env).GetIntArrayElements(blackSquares, NULL);
len = env->GetArrayLength(blackSquares);
jiPtr = env->GetIntArrayElements(blackSquares, NULL);
for (int i = 0; i < min(len, MAXLEN); i++)
bs[i] = jiPtr[i];
(*env).ReleaseIntArrayElements(blackSquares, jiPtr, 0);
env->ReleaseIntArrayElements(blackSquares, jiPtr, 0);
len = (*env).GetArrayLength(whitePieces);
jbyte* jcPtr = (*env).GetByteArrayElements(whitePieces, NULL);
len = env->GetArrayLength(whitePieces);
jbyte* jcPtr = env->GetByteArrayElements(whitePieces, NULL);
for (int i = 0; i < min(len, MAXLEN); i++)
wp[i] = jcPtr[i];
(*env).ReleaseByteArrayElements(whitePieces, jcPtr, 0);
env->ReleaseByteArrayElements(whitePieces, jcPtr, 0);
len = (*env).GetArrayLength(blackPieces);
jcPtr = (*env).GetByteArrayElements(blackPieces, NULL);
len = env->GetArrayLength(blackPieces);
jcPtr = env->GetByteArrayElements(blackPieces, NULL);
for (int i = 0; i < min(len, MAXLEN); i++)
bp[i] = jcPtr[i];
(*env).ReleaseByteArrayElements(blackPieces, jcPtr, 0);
env->ReleaseByteArrayElements(blackPieces, jcPtr, 0);
unsigned int tbInfo;
unsigned int plies;
@ -125,6 +125,6 @@ JNICALL Java_org_petero_droidfish_tb_GtbProbe_probeHard(
res[0] = tbInfo;
res[1] = plies;
(*env).SetIntArrayRegion(result, 0, 2, res);
env->SetIntArrayRegion(result, 0, 2, res);
return ret != 0;
}

View File

@ -30,11 +30,11 @@
*/
extern "C" JNIEXPORT jboolean JNICALL Java_org_petero_droidfish_engine_EngineUtil_chmod
(JNIEnv *env, jclass, jstring jExePath) {
const char* exePath = (*env).GetStringUTFChars(jExePath, NULL);
const char* exePath = env->GetStringUTFChars(jExePath, NULL);
if (!exePath)
return false;
bool ret = chmod(exePath, 0744) == 0;
(*env).ReleaseStringUTFChars(jExePath, exePath);
env->ReleaseStringUTFChars(jExePath, exePath);
return ret;
}

View File

@ -27,11 +27,11 @@ JNICALL Java_org_petero_droidfish_tb_RtbProbe_init(
JNIEnv* env, jclass cls, jstring jTbPath)
{
initOk = false;
const char* tbPath = (*env).GetStringUTFChars(jTbPath, NULL);
const char* tbPath = env->GetStringUTFChars(jTbPath, NULL);
if (!tbPath)
return false;
std::string rtbPath(tbPath);
(*env).ReleaseStringUTFChars(jTbPath, tbPath);
env->ReleaseStringUTFChars(jTbPath, tbPath);
TBProbe::initialize(rtbPath);
initOk = true;
@ -45,26 +45,26 @@ JNICALL Java_org_petero_droidfish_tb_RtbProbe_probe(
jint halfMoveClock, jint fullMoveCounter,
jintArray result)
{
if ((*env).GetArrayLength(result) < 2)
if (env->GetArrayLength(result) < 2)
return;
jint res[2];
res[0] = 1000;
res[1] = 1000;
(*env).SetIntArrayRegion(result, 0, 2, res);
env->SetIntArrayRegion(result, 0, 2, res);
if (!initOk)
return;
const int len = (*env).GetArrayLength(jSquares);
const int len = env->GetArrayLength(jSquares);
if (len != 64)
return;
Position pos;
jbyte* jbPtr = (*env).GetByteArrayElements(jSquares, NULL);
jbyte* jbPtr = env->GetByteArrayElements(jSquares, NULL);
for (int i = 0; i < 64; i++)
pos.setPiece(i, jbPtr[i]);
(*env).ReleaseByteArrayElements(jSquares, jbPtr, 0);
env->ReleaseByteArrayElements(jSquares, jbPtr, 0);
pos.setWhiteMove(wtm);
pos.setEpSquare(epSq);
@ -78,5 +78,5 @@ JNICALL Java_org_petero_droidfish_tb_RtbProbe_probe(
if (TBProbe::rtbProbeDTZ(pos, score))
res[1] = score;
(*env).SetIntArrayRegion(result, 0, 2, res);
env->SetIntArrayRegion(result, 0, 2, res);
}