| Index: base/android/jni_generator/jni_generator.py
|
| diff --git a/base/android/jni_generator/jni_generator.py b/base/android/jni_generator/jni_generator.py
|
| index 6e39c13d4b0631b90cc300fa26f8a324d8085283..e23660c0c8ee05e7fade70cf20c6cd4e5a3d3a6a 100755
|
| --- a/base/android/jni_generator/jni_generator.py
|
| +++ b/base/android/jni_generator/jni_generator.py
|
| @@ -889,7 +889,7 @@ jmethodID g_${JAVA_CLASS}_${METHOD_ID_VAR_NAME} = NULL;""")
|
|
|
| def GetJNINativeMethodsString(self):
|
| """Returns the implementation of the array of native methods."""
|
| - if self.options.native_exports:
|
| + if self.options.native_exports and not self.options.native_exports_optional:
|
| return ''
|
| template = Template("""\
|
| static const JNINativeMethod kMethods${JAVA_CLASS}[] = {
|
| @@ -945,7 +945,7 @@ ${CALLED_BY_NATIVES}
|
|
|
| def GetRegisterNativesImplString(self):
|
| """Returns the shared implementation for RegisterNatives."""
|
| - if self.options.native_exports:
|
| + if self.options.native_exports and not self.options.native_exports_optional:
|
| return ''
|
|
|
| template = Template("""\
|
| @@ -1035,6 +1035,21 @@ Java_${FULLY_QUALIFIED_CLASS}_${INIT_NATIVE_NAME}(JNIEnv* env, jclass clazz) {
|
| param.name
|
| for param in called_by_native.params])
|
|
|
| + def GetStubName(self, native):
|
| + if self.options.native_exports:
|
| + template = Template("Java_${JAVA_NAME}_native${NAME}")
|
| +
|
| + java_name = JniParams.RemapClassName(self.fully_qualified_class)
|
| + java_name = java_name.replace('_', '_1').replace('/', '_')
|
| + if native.java_class_name:
|
| + java_name += '_00024' + native.java_class_name
|
| +
|
| + values = {'NAME': native.name,
|
| + 'JAVA_NAME': java_name}
|
| + return template.substitute(values)
|
| + else:
|
| + return native.name
|
| +
|
| def GetForwardDeclaration(self, native):
|
| template_str = """
|
| static ${RETURN} ${NAME}(JNIEnv* env, ${PARAMS});
|
| @@ -1042,7 +1057,7 @@ static ${RETURN} ${NAME}(JNIEnv* env, ${PARAMS});
|
| if self.options.native_exports:
|
| template_str += """
|
| __attribute__((visibility("default"), alias("${NAME}")))
|
| -${RETURN} Java_${JAVA_NAME}_native${NAME}(JNIEnv* env, ${PARAMS});
|
| +${RETURN} ${STUB_NAME}(JNIEnv* env, ${PARAMS});
|
| """
|
| template = Template(template_str)
|
| params_in_call = []
|
| @@ -1050,16 +1065,11 @@ ${RETURN} Java_${JAVA_NAME}_native${NAME}(JNIEnv* env, ${PARAMS});
|
| params_in_call = ['env', 'jcaller']
|
| params_in_call = ', '.join(params_in_call + [p.name for p in native.params])
|
|
|
| - java_name = JniParams.RemapClassName(self.fully_qualified_class)
|
| - java_name = java_name.replace('_', '_1').replace('/', '_')
|
| - if native.java_class_name:
|
| - java_name += '_00024' + native.java_class_name
|
| -
|
| values = {'RETURN': JavaDataTypeToC(native.return_type),
|
| 'NAME': native.name,
|
| - 'JAVA_NAME': java_name,
|
| 'PARAMS': self.GetParamsInDeclaration(native),
|
| - 'PARAMS_IN_CALL': params_in_call}
|
| + 'PARAMS_IN_CALL': params_in_call,
|
| + 'STUB_NAME': self.GetStubName(native)}
|
| return template.substitute(values)
|
|
|
| def GetNativeMethodStubString(self, native):
|
| @@ -1067,11 +1077,11 @@ ${RETURN} Java_${JAVA_NAME}_native${NAME}(JNIEnv* env, ${PARAMS});
|
| if self.options.native_exports:
|
| template_str = """\
|
| __attribute__((visibility("default")))
|
| -${RETURN} Java_${JAVA_NAME}_native${NAME}(JNIEnv* env,
|
| +${RETURN} ${STUB_NAME}(JNIEnv* env,
|
| ${PARAMS_IN_DECLARATION}) {"""
|
| else:
|
| template_str = """\
|
| -static ${RETURN} ${NAME}(JNIEnv* env, ${PARAMS_IN_DECLARATION}) {"""
|
| +static ${RETURN} ${STUB_NAME}(JNIEnv* env, ${PARAMS_IN_DECLARATION}) {"""
|
| template_str += """
|
| ${P0_TYPE}* native = reinterpret_cast<${P0_TYPE}*>(${PARAM0_NAME});
|
| CHECK_NATIVE_PTR(env, jcaller, native, "${NAME}"${OPTIONAL_ERROR_RETURN});
|
| @@ -1093,24 +1103,16 @@ static ${RETURN} ${NAME}(JNIEnv* env, ${PARAMS_IN_DECLARATION}) {"""
|
| if re.match(RE_SCOPED_JNI_RETURN_TYPES, return_type):
|
| post_call = '.Release()'
|
|
|
| - if self.options.native_exports:
|
| - java_name = JniParams.RemapClassName(self.fully_qualified_class)
|
| - java_name = java_name.replace('_', '_1').replace('/', '_')
|
| - if native.java_class_name:
|
| - java_name += '_00024' + native.java_class_name
|
| - else:
|
| - java_name = ''
|
| -
|
| values = {
|
| 'RETURN': return_type,
|
| 'OPTIONAL_ERROR_RETURN': optional_error_return,
|
| - 'JAVA_NAME': java_name,
|
| 'NAME': native.name,
|
| 'PARAMS_IN_DECLARATION': self.GetParamsInDeclaration(native),
|
| 'PARAM0_NAME': native.params[0].name,
|
| 'P0_TYPE': native.p0_type,
|
| 'PARAMS_IN_CALL': params_in_call,
|
| - 'POST_CALL': post_call
|
| + 'POST_CALL': post_call,
|
| + 'STUB_NAME': self.GetStubName(native),
|
| }
|
| return template.substitute(values)
|
|
|
| @@ -1226,11 +1228,12 @@ ${FUNCTION_HEADER}
|
|
|
| def GetKMethodArrayEntry(self, native):
|
| template = Template("""\
|
| - { "native${NAME}", ${JNI_SIGNATURE}, reinterpret_cast<void*>(${NAME}) },""")
|
| + { "native${NAME}", ${JNI_SIGNATURE}, reinterpret_cast<void*>(${STUB_NAME}) },""")
|
| values = {'NAME': native.name,
|
| 'JNI_SIGNATURE': JniParams.Signature(native.params,
|
| native.return_type,
|
| - True)}
|
| + True),
|
| + 'STUB_NAME': self.GetStubName(native)}
|
| return template.substitute(values)
|
|
|
| def GetUniqueClasses(self, origin):
|
| @@ -1500,7 +1503,12 @@ See SampleForTests.java for more details.
|
| option_parser.add_option('--native_exports', action='store_true',
|
| help='Native method registration through .so '
|
| 'exports.')
|
| + option_parser.add_option('--native_exports_optional', action='store_true',
|
| + help='Support both explicit and native method'
|
| + 'registration.')
|
| options, args = option_parser.parse_args(argv)
|
| + if options.native_exports_optional:
|
| + options.native_exports = True
|
| if options.jar_file:
|
| input_file = ExtractJarInputFile(options.jar_file, options.input_file,
|
| options.output_dir)
|
|
|