Index: android/jni_generator/jni_generator.py |
diff --git a/android/jni_generator/jni_generator.py b/android/jni_generator/jni_generator.py |
index f7c13936f9d9c83e93ab11b96cdc39e50df30223..33f83ecc6f4fc9161cb7b16bb81358ffae54a275 100755 |
--- a/android/jni_generator/jni_generator.py |
+++ b/android/jni_generator/jni_generator.py |
@@ -113,8 +113,10 @@ def JavaDataTypeToC(java_type): |
java_type_map = { |
'void': 'void', |
'String': 'jstring', |
+ 'Throwable': 'jthrowable', |
'java/lang/String': 'jstring', |
'java/lang/Class': 'jclass', |
+ 'java/lang/Throwable': 'jthrowable', |
} |
if java_type in java_pod_type_map: |
@@ -430,6 +432,8 @@ def ExtractNatives(contents, ptr_type): |
def GetStaticCastForReturnType(return_type): |
type_map = { 'String' : 'jstring', |
'java/lang/String' : 'jstring', |
+ 'Throwable': 'jthrowable', |
+ 'java/lang/Throwable': 'jthrowable', |
'boolean[]': 'jbooleanArray', |
'byte[]': 'jbyteArray', |
'char[]': 'jcharArray', |
@@ -525,7 +529,8 @@ def MangleCalledByNatives(called_by_natives): |
# Regex to match the JNI return types that should be included in a |
# ScopedJavaLocalRef. |
-RE_SCOPED_JNI_RETURN_TYPES = re.compile('jobject|jclass|jstring|.*Array') |
+RE_SCOPED_JNI_RETURN_TYPES = re.compile( |
+ 'jobject|jclass|jstring|jthrowable|.*Array') |
# Regex to match a string like "@CalledByNative public void foo(int bar)". |
RE_CALLED_BY_NATIVE = re.compile( |
@@ -1067,12 +1072,18 @@ Java_${FULLY_QUALIFIED_CLASS}_${INIT_NATIVE_NAME}(JNIEnv* env, jclass clazz) { |
stub_visibility = 'extern "C" __attribute__((visibility("default")))\n' |
else: |
stub_visibility = 'static ' |
- return_type = JavaDataTypeToC(native.return_type) |
+ return_type = return_declaration = JavaDataTypeToC(native.return_type) |
+ post_call = '' |
+ if re.match(RE_SCOPED_JNI_RETURN_TYPES, return_type): |
+ post_call = '.Release()' |
+ return_declaration = 'ScopedJavaLocalRef<' + return_type + '>' |
values = { |
'RETURN': return_type, |
+ 'RETURN_DECLARATION': return_declaration, |
'NAME': native.name, |
'PARAMS': self.GetParamsInDeclaration(native), |
'PARAMS_IN_CALL': params_in_call, |
+ 'POST_CALL': post_call, |
'STUB_NAME': self.GetStubName(native), |
'STUB_VISIBILITY': stub_visibility, |
} |
@@ -1081,14 +1092,10 @@ Java_${FULLY_QUALIFIED_CLASS}_${INIT_NATIVE_NAME}(JNIEnv* env, jclass clazz) { |
optional_error_return = JavaReturnValueToC(native.return_type) |
if optional_error_return: |
optional_error_return = ', ' + optional_error_return |
- post_call = '' |
- if re.match(RE_SCOPED_JNI_RETURN_TYPES, return_type): |
- post_call = '.Release()' |
values.update({ |
'OPTIONAL_ERROR_RETURN': optional_error_return, |
'PARAM0_NAME': native.params[0].name, |
'P0_TYPE': native.p0_type, |
- 'POST_CALL': post_call, |
}) |
template = Template("""\ |
${STUB_VISIBILITY}${RETURN} ${STUB_NAME}(JNIEnv* env, |
@@ -1100,10 +1107,10 @@ ${STUB_VISIBILITY}${RETURN} ${STUB_NAME}(JNIEnv* env, |
""") |
else: |
template = Template(""" |
-static ${RETURN} ${NAME}(JNIEnv* env, ${PARAMS}); |
+static ${RETURN_DECLARATION} ${NAME}(JNIEnv* env, ${PARAMS}); |
${STUB_VISIBILITY}${RETURN} ${STUB_NAME}(JNIEnv* env, ${PARAMS}) { |
- return ${NAME}(${PARAMS_IN_CALL}); |
+ return ${NAME}(${PARAMS_IN_CALL})${POST_CALL}; |
} |
""") |
@@ -1151,7 +1158,7 @@ ${STUB_VISIBILITY}${RETURN} ${STUB_NAME}(JNIEnv* env, ${PARAMS}) { |
pre_call = ' ' + pre_call |
return_declaration = return_type + ' ret =' |
if re.match(RE_SCOPED_JNI_RETURN_TYPES, return_type): |
- return_type = 'base::android::ScopedJavaLocalRef<' + return_type + '>' |
+ return_type = 'ScopedJavaLocalRef<' + return_type + '>' |
return_clause = 'return ' + return_type + '(env, ret);' |
else: |
return_clause = 'return ret;' |