diff options
author | Elliott Hughes <enh@google.com> | 2011-04-08 20:01:01 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2011-04-11 15:31:20 -0700 |
commit | 9875750593aae7c2a62f33c620809d49162393eb (patch) | |
tree | 05696154ec1056b08a758f5741cdd7cd31a54587 /opengl/tools/glgen/src | |
parent | 626d865d418cf3fcea985429ef85cf83f8cd978e (diff) | |
download | frameworks_native-9875750593aae7c2a62f33c620809d49162393eb.zip frameworks_native-9875750593aae7c2a62f33c620809d49162393eb.tar.gz frameworks_native-9875750593aae7c2a62f33c620809d49162393eb.tar.bz2 |
Kill the global references in the OpenGL wrappers.
Just use jniThrowException instead. Note that it would be trivial to throw
seemingly more appropriate exceptions (NullPointerException and
OutOfMemoryException in particular), but I'm only attempting to preserve
existing behavior here.
I also found shadowing bugs in some of the special-case functions, which
would previously always have leaked memory.
This also moves an accidental change to a generated file (ActivityThread ->
AppGlobals) into the generator, so it won't be overwritten in future.
Change-Id: Iab570310b568cb406c60dd0e2b8211f8a36ae590
Diffstat (limited to 'opengl/tools/glgen/src')
-rw-r--r-- | opengl/tools/glgen/src/JniCodeEmitter.java | 206 |
1 files changed, 89 insertions, 117 deletions
diff --git a/opengl/tools/glgen/src/JniCodeEmitter.java b/opengl/tools/glgen/src/JniCodeEmitter.java index 9d8c5a0..9fa2b74 100644 --- a/opengl/tools/glgen/src/JniCodeEmitter.java +++ b/opengl/tools/glgen/src/JniCodeEmitter.java @@ -58,7 +58,7 @@ public class JniCodeEmitter { } else if (baseType.equals("void")) { // nothing. } else { - throw new RuntimeException("Uknown primitive basetype " + baseType); + throw new RuntimeException("Unknown primitive basetype " + baseType); } return jniName; } @@ -200,15 +200,9 @@ public class JniCodeEmitter { if (emitExceptionCheck) { out.println(iii + indent + "_exception = 1;"); } - out.println(iii + indent + - (mUseCPlusPlus ? "_env" : "(*_env)") + - "->ThrowNew(" + - (mUseCPlusPlus ? "" : "_env, ") + - "IAEClass, " + - "\"" + - (isBuffer ? - "remaining()" : "length - " + offset) + - " < needed\");"); + out.println(iii + indent + "jniThrowException(_env, " + + "\"java/lang/IllegalArgumentException\", " + + "\"" + (isBuffer ? "remaining()" : "length - " + offset) + " < needed\");"); out.println(iii + indent + "goto exit;"); needsExit = true; out.println(iii + "}"); @@ -302,7 +296,7 @@ public class JniCodeEmitter { } return false; } - + String isRequiresFunc(CFunc cfunc) { String[] checks = mChecker.getChecks(cfunc.getName()); int index = 1; @@ -329,109 +323,94 @@ public class JniCodeEmitter { } return null; } - + void emitNativeBoundsChecks(CFunc cfunc, String cname, PrintStream out, boolean isBuffer, boolean emitExceptionCheck, String offset, String remaining, String iii) { - String[] checks = mChecker.getChecks(cfunc.getName()); - - boolean lastWasIfcheck = false; - - int index = 1; - if (checks != null) { - while (index < checks.length) { - if (checks[index].startsWith("check")) { - if (lastWasIfcheck) { - printIfcheckPostamble(out, isBuffer, emitExceptionCheck, - offset, remaining, iii); - } - lastWasIfcheck = false; - if (cname != null && !cname.equals(checks[index + 1])) { - index += 3; - continue; - } - out.println(iii + "if (" + remaining + " < " + - checks[index + 2] + - ") {"); - if (emitExceptionCheck) { - out.println(iii + indent + "_exception = 1;"); - } - String exceptionClassName = "IAEClass"; + String[] checks = mChecker.getChecks(cfunc.getName()); + + boolean lastWasIfcheck = false; + + int index = 1; + if (checks != null) { + while (index < checks.length) { + if (checks[index].startsWith("check")) { + if (lastWasIfcheck) { + printIfcheckPostamble(out, isBuffer, emitExceptionCheck, + offset, remaining, iii); + } + lastWasIfcheck = false; + if (cname != null && !cname.equals(checks[index + 1])) { + index += 3; + continue; + } + out.println(iii + "if (" + remaining + " < " + checks[index + 2] + ") {"); + if (emitExceptionCheck) { + out.println(iii + indent + "_exception = 1;"); + } + String exceptionClassName = "java/lang/IllegalArgumentException"; // If the "check" keyword was of the form // "check_<class name>", use the class name in the // exception to be thrown int underscore = checks[index].indexOf('_'); if (underscore >= 0) { - exceptionClassName = checks[index].substring(underscore + 1) + "Class"; - } - out.println(iii + indent + - (mUseCPlusPlus ? "_env" : "(*_env)") + - "->ThrowNew(" + - (mUseCPlusPlus ? "" : "_env, ") + - exceptionClassName + ", " + - "\"" + - (isBuffer ? - "remaining()" : "length - " + offset) + - " < " + checks[index + 2] + - "\");"); - - out.println(iii + indent + "goto exit;"); - needsExit = true; - out.println(iii + "}"); - - index += 3; - } else if (checks[index].equals("ifcheck")) { - String[] matches = checks[index + 4].split(","); - - if (!lastWasIfcheck) { - out.println(iii + "int _needed;"); - out.println(iii + - "switch (" + - checks[index + 3] + - ") {"); - } - - for (int i = 0; i < matches.length; i++) { - out.println("#if defined(" + matches[i] + ")"); - out.println(iii + - " case " + - matches[i] + - ":"); - out.println("#endif // defined(" + matches[i] + ")"); - } - out.println(iii + - " _needed = " + - checks[index + 2] + - ";"); - out.println(iii + - " break;"); - - lastWasIfcheck = true; - index += 5; - } else if (checks[index].equals("return")) { - // ignore - index += 2; - } else if (checks[index].equals("unsupported")) { - // ignore - index += 1; - } else if (checks[index].equals("requires")) { - // ignore - index += 2; - } else if (checks[index].equals("nullAllowed")) { - // ignore - index += 1; + String abbr = checks[index].substring(underscore + 1); + if (abbr.equals("AIOOBE")) { + exceptionClassName = "java/lang/ArrayIndexOutOfBoundsException"; } else { - System.out.println("Error: unknown keyword \"" + - checks[index] + "\""); - System.exit(0); + throw new RuntimeException("unknown exception abbreviation: " + abbr); } } - } + out.println(iii + indent + "jniThrowException(_env, " + + "\"" + exceptionClassName + "\", " + + "\"" + (isBuffer ? "remaining()" : "length - " + offset) + " < " + checks[index + 2] + "\");"); + + out.println(iii + indent + "goto exit;"); + needsExit = true; + out.println(iii + "}"); + + index += 3; + } else if (checks[index].equals("ifcheck")) { + String[] matches = checks[index + 4].split(","); + + if (!lastWasIfcheck) { + out.println(iii + "int _needed;"); + out.println(iii + "switch (" + checks[index + 3] + ") {"); + } + + for (int i = 0; i < matches.length; i++) { + out.println("#if defined(" + matches[i] + ")"); + out.println(iii + " case " + matches[i] + ":"); + out.println("#endif // defined(" + matches[i] + ")"); + } + out.println(iii + " _needed = " + checks[index + 2] + ";"); + out.println(iii + " break;"); - if (lastWasIfcheck) { - printIfcheckPostamble(out, isBuffer, emitExceptionCheck, iii); + lastWasIfcheck = true; + index += 5; + } else if (checks[index].equals("return")) { + // ignore + index += 2; + } else if (checks[index].equals("unsupported")) { + // ignore + index += 1; + } else if (checks[index].equals("requires")) { + // ignore + index += 2; + } else if (checks[index].equals("nullAllowed")) { + // ignore + index += 1; + } else { + System.out.println("Error: unknown keyword \"" + checks[index] + "\""); + System.exit(0); } } + } + + if (lastWasIfcheck) { + printIfcheckPostamble(out, isBuffer, emitExceptionCheck, iii); + } + } boolean hasNonConstArg(JFunc jfunc, CFunc cfunc, List<Integer> nonPrimitiveArgs) { if (nonPrimitiveArgs.size() > 0) { @@ -817,7 +796,7 @@ public class JniCodeEmitter { boolean isUnsupported = isUnsupportedFunc(cfunc); if (isUnsupported) { out.println(indent + - "_env->ThrowNew(UOEClass,"); + "jniThrowException(_env, \"java/lang/UnsupportedOperationException\","); out.println(indent + " \"" + cfunc.getName() + "\");"); if (!isVoid) { @@ -828,13 +807,13 @@ public class JniCodeEmitter { out.println(); return; } - + String requiresExtension = isRequiresFunc(cfunc); if (requiresExtension != null) { out.println(indent + "if (! supportsExtension(_env, _this, have_" + requiresExtension + "ID)) {"); out.println(indent + indent + - "_env->ThrowNew(UOEClass,"); + "jniThrowException(_env, \"java/lang/UnsupportedOperationException\","); out.println(indent + indent + " \"" + cfunc.getName() + "\");"); if (isVoid) { @@ -945,7 +924,8 @@ public class JniCodeEmitter { CType type = cfunc.getArgType(jfunc.getArgCIndex(idx)); String decl = type.getDeclaration(); out.println(indent + "if (!" + cname + ") {"); - out.println(indent + " _env->ThrowNew(IAEClass, \"" + cname + " == null\");"); + out.println(indent + " jniThrowException(_env, " + + "\"java/lang/IllegalArgumentException\", \"" + cname + " == null\");"); out.println(indent + " goto exit;"); needsExit = true; out.println(indent + "}"); @@ -978,13 +958,9 @@ public class JniCodeEmitter { if (emitExceptionCheck) { out.println(indent + indent + "_exception = 1;"); } - out.println(indent + " " + - (mUseCPlusPlus ? "_env" : "(*_env)") + - "->ThrowNew(" + - (mUseCPlusPlus ? "" : "_env, ") + - "IAEClass, " + - "\"" + cname + - " == null\");"); + out.println(indent + " jniThrowException(_env, " + + "\"java/lang/IllegalArgumentException\", " + + "\"" + cname + " == null\");"); out.println(indent + " goto exit;"); needsExit = true; out.println(indent + "}"); @@ -993,12 +969,8 @@ public class JniCodeEmitter { if (emitExceptionCheck) { out.println(indent + indent + "_exception = 1;"); } - out.println(indent + " " + - (mUseCPlusPlus ? "_env" : "(*_env)") + - "->ThrowNew(" + - (mUseCPlusPlus ? "" : "_env, ") + - "IAEClass, " + - "\"" + offset + " < 0\");"); + out.println(indent + " jniThrowException(_env, " + + "\"java/lang/IllegalArgumentException\", \"" + offset + " < 0\");"); out.println(indent + " goto exit;"); needsExit = true; out.println(indent + "}"); |