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

View File

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

View File

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