Skip to content

Commit

Permalink
Merge pull request #125 from rlcevg/fix_javaai_customparams
Browse files Browse the repository at this point in the history
Fix java AI's getCustomParams
  • Loading branch information
abma committed Aug 30, 2014
2 parents e4b9326 + 72aa8c1 commit 28fadd8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
17 changes: 5 additions & 12 deletions AI/Interfaces/Java/bin/jni_wrappCallback.awk
Expand Up @@ -201,13 +201,7 @@ function printNativeJNI() {
print("\t\t" c_paramNames[p] " = (" c_paramTypes[p] ") (*__env)->Get" capArrType "ArrayElements(__env, " jni_paramNames[p] ", NULL);") >> outFile_nc;
} else if (_isString) {
print("\t\t" "const int " c_paramNames[p] "_size = (int) (*__env)->GetArrayLength(__env, " jni_paramNames[p] ");") >> outFile_nc;
print("\t\t" c_paramNames[p] " = (" c_paramTypes[p] ") calloc(sizeof(char*), " c_paramNames[p] "_size);") >> outFile_nc;
print("\t\t" "int " c_paramNames[p] "_i;") >> outFile_nc;
print("\t\t" "jstring " c_paramNames[p] "_jStr;") >> outFile_nc;
print("\t\t" "for (" c_paramNames[p] "_i=0; " c_paramNames[p] "_i < " c_paramNames[p] "_size; ++" c_paramNames[p] "_i) {") >> outFile_nc;
print("\t\t\t" c_paramNames[p] "_jStr = (jstring) (*__env)->GetObjectArrayElement(__env, " jni_paramNames[p] ", " c_paramNames[p] "_i);") >> outFile_nc;
print("\t\t\t" c_paramNames[p] "[" c_paramNames[p] "_i] = (const char*) (*__env)->GetStringUTFChars(__env, " c_paramNames[p] "_jStr, NULL);") >> outFile_nc;
print("\t\t" "}") >> outFile_nc;
print("\t\t" c_paramNames[p] " = (" c_paramTypes[p] ") malloc(sizeof(char*) * " c_paramNames[p] "_size);") >> outFile_nc;
} else {
print("ERROR: do not know how to convert parameter type: " pType_jni);
exit(1);
Expand Down Expand Up @@ -247,7 +241,7 @@ function printNativeJNI() {
capArrType = capitalize(capArrType);

_isPrimitive = (capArrType != "Object");
_isString = !_isPrimitive && (c_paramTypes[p] == "char**");
_isString = !_isPrimitive && match(c_paramTypes[p], /(const )?char\*\*/);

print("\t" "if (" jni_paramNames[p] " != NULL) {") >> outFile_nc;
if (_isPrimitive) {
Expand All @@ -256,15 +250,14 @@ function printNativeJNI() {
print("\t\t" "(*__env)->Release" capArrType "ArrayElements(__env, " jni_paramNames[p] ", (" _elementJNativeType "*) " c_paramNames[p] ", 0 /* copy back changes and release */);") >> outFile_nc;
} else if (_isString) {
print("\t\t" "const int " c_paramNames[p] "_size = (int) (*__env)->GetArrayLength(__env, " jni_paramNames[p] ");") >> outFile_nc;
print("\t\t" c_paramNames[p] " = (" c_paramTypes[p] ") calloc(sizeof(char*), " c_paramNames[p] "_size);") >> outFile_nc;
print("\t\t" "int " c_paramNames[p] "_i;") >> outFile_nc;
print("\t\t" "jstring " c_paramNames[p] "_jStr;") >> outFile_nc;
print("\t\t" "for (" c_paramNames[p] "_i=0; " c_paramNames[p] "_i < " c_paramNames[p] "_size; ++" c_paramNames[p] "_i) {") >> outFile_nc;
print("\t\t\t" c_paramNames[p] "_jStr = (jstring) (*__env)->GetObjectArrayElement(__env, " jni_paramNames[p] ", " c_paramNames[p] "_i);") >> outFile_nc;
print("\t\t\t" "(*__env)->ReleaseStringUTFChars(__env, " c_paramNames[p] "_jStr, " c_paramNames[p] "[" c_paramNames[p] "_i]);") >> outFile_nc;
print("\t\t\t" c_paramNames[p] "_jStr = (jstring) (*__env)->NewStringUTF(__env, " c_paramNames[p] "[" c_paramNames[p] "_i]);") >> outFile_nc;
print("\t\t\t" "(*__env)->SetObjectArrayElement(__env, " jni_paramNames[p] ", " c_paramNames[p] "_i, " c_paramNames[p] "_jStr);") >> outFile_nc;
print("\t\t\t" "(*__env)->DeleteLocalRef(__env, " c_paramNames[p] "_jStr);") >> outFile_nc;
print("\t\t" "}") >> outFile_nc;
print("\t\t" "free(" c_paramNames[p] ");") >> outFile_nc;
print("\t\t" c_paramNames[p] " = NULL;") >> outFile_nc;
}
print("\t" "}") >> outFile_nc;
}
Expand Down
12 changes: 6 additions & 6 deletions AI/Wrappers/JavaOO/bin/wrappCallback.awk
Expand Up @@ -887,15 +887,15 @@ function printMember(fullName_m, memName_m, additionalIndices_m) {
# convert to a HashMap
conversionCode_post = conversionCode_post "\t\t" _mapVar_oo " = new " _mapType_impl "();" "\n";
conversionCode_post = conversionCode_post "\t\t" "for (int i=0; i < " _mapVar_size "; i++) {" "\n";
if (_isObj) {
if (_isRetSize) {
# if (_isObj) {
# if (_isRetSize) {
conversionCode_post = conversionCode_post "\t\t\t" _mapVar_oo ".put(" _mapVar_keys "[i], " _mapVar_values "[i]);" "\n";
} else {
# } else {
#conversionCode_post = conversionCode_post "\t\t\t" _mapVar_oo ".put(" myPkgA ".Wrapp" _refObj ".getInstance(" myWrapVar _addWrappVars ", " _arrayPaNa "[i]));" "\n";
}
} else if (_isNative) {
# }
# } else if (_isNative) {
#conversionCode_post = conversionCode_post "\t\t\t" _arrayListVar ".add(" _arrayPaNa "[i]);" "\n";
}
# }
conversionCode_post = conversionCode_post "\t\t" "}" "\n";

retParamType = _mapType_int;
Expand Down

0 comments on commit 28fadd8

Please sign in to comment.