Skip to content

Commit

Permalink
Fix Class#isInstance, include NPE checks, non-integer literal fix
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLogicMaster committed May 24, 2022
1 parent 1f24e7d commit 4b9d879
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ LibGDX backend but doesn't depend on it. An example project is provided in the `
- Fix try-catch/synchronized block nesting (See SwitchGDX ThreadTest)
- Dynamic cast checks
- Reformat runtime and transpiler sources
- Reflection type conversions (See SwitchGDX ReflectionTest)

## Notes
- Requires retrolambda for lambda, default method, and method reference support (RetroLambda Gradle plugin doesn't support Gradle 7)
Expand All @@ -47,3 +48,4 @@ LibGDX backend but doesn't depend on it. An example project is provided in the `
- JAVA_ARRAY_BYTE must be explicitly `unsigned char`, since it's compiler specific behavior otherwise
- Array components in multidimensional arrays should refer to array classes of decreasing size
- Added dedicated primitive types
- Literals for non-integer types must be explicitly specified
5 changes: 3 additions & 2 deletions runtime/res/nativeMethods.c
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ JAVA_BOOLEAN java_lang_Class_isAssignableFrom___java_lang_Class_R_boolean(CODENA
JAVA_BOOLEAN java_lang_Class_isInstance___java_lang_Object_R_boolean(CODENAME_ONE_THREAD_STATE, JAVA_OBJECT cls, JAVA_OBJECT obj) {
struct clazz* clz1 = (struct clazz*)cls;
struct clazz* clz2 = (struct clazz*)obj->__codenameOneParentClsReference;
return instanceofFunction(clz2->classId, clz1->classId);
return instanceofFunction(clz1->classId, clz2->classId);
}

JAVA_BOOLEAN java_lang_Class_isInterface___R_boolean(CODENAME_ONE_THREAD_STATE, JAVA_OBJECT cls) {
Expand Down Expand Up @@ -1388,7 +1388,8 @@ JAVA_OBJECT java_lang_Object_getClassImpl___R_java_lang_Class(CODENAME_ONE_THREA
if(!obj->__codenameOneParentClsReference) {
return (JAVA_OBJECT)(&ClazzClazz);
}
obj->__codenameOneParentClsReference->__codenameOneParentClsReference = &ClazzClazz;
if (obj->__codenameOneParentClsReference != &ClazzClazz && !obj->__codenameOneParentClsReference->__codenameOneParentClsReference)
obj->__codenameOneParentClsReference->__codenameOneParentClsReference = &ClazzClazz; // Todo: Is this even needed?
return (JAVA_OBJECT)obj->__codenameOneParentClsReference;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ private void copyDir(File source, File destDir) throws IOException {
*/
public static void main(String[] args) throws Exception {
// System.setProperty("optimizer", "off");
System.setProperty("INCLUDE_NPE_CHECKS", "true");

if(args.length != 3 && args.length != 4) {
System.out.println("Usage: <input directory> <output directory> <config> <main class>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -711,37 +711,37 @@ public boolean assignTo(String varName, StringBuilder sb) {
break;

case Opcodes.LCONST_0:
b.append("0 /* LCONST_0 */");
b.append("((JAVA_LONG)0) /* LCONST_0 */");
//b2.append("CN1_TYPE_LONG");
break;

case Opcodes.LCONST_1:
b.append("1 /* LCONST_1 */");
b.append("((JAVA_LONG)1) /* LCONST_1 */");
//b2.append("CN1_TYPE_LONG");
break;

case Opcodes.FCONST_0:
b.append("0 /* FCONST_0 */");
b.append("((JAVA_FLOAT)0) /* FCONST_0 */");
//b2.append("CN1_TYPE_FLOAT");
break;

case Opcodes.FCONST_1:
b.append("1 /* FCONST_1 */");
b.append("((JAVA_FLOAT)1) /* FCONST_1 */");
//b2.append("CN1_TYPE_FLOAT");
break;

case Opcodes.FCONST_2:
b.append("2 /* FCONST_2 */");
b.append("((JAVA_FLOAT)2) /* FCONST_2 */");
//b2.append("CN1_TYPE_FLOAT");
break;

case Opcodes.DCONST_0:
b.append("0 /* DCONST_0 */");
b.append("((JAVA_DOUBLE)0) /* DCONST_0 */");
//b2.append("CN1_TYPE_DOUBLE");
break;

case Opcodes.DCONST_1:
b.append("1 /* DCONST_1 */");
b.append("((JAVA_DOUBLE)1) /* DCONST_1 */");
//b2.append("CN1_TYPE_DOUBLE");
break;

Expand Down

0 comments on commit 4b9d879

Please sign in to comment.