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 74d0117495dd9362a280c7a8d706454fca02fa59..f7c13936f9d9c83e93ab11b96cdc39e50df30223 100755 |
--- a/base/android/jni_generator/jni_generator.py |
+++ b/base/android/jni_generator/jni_generator.py |
@@ -764,7 +764,6 @@ $METHOD_ID_DEFINITIONS |
} // namespace |
$OPEN_NAMESPACE |
-$FORWARD_DECLARATIONS |
$CONSTANT_FIELDS |
@@ -783,7 +782,6 @@ $JNI_REGISTER_NATIVES |
'FULLY_QUALIFIED_CLASS': self.fully_qualified_class, |
'CLASS_PATH_DEFINITIONS': self.GetClassPathDefinitionsString(), |
'METHOD_ID_DEFINITIONS': self.GetMethodIDDefinitionsString(), |
- 'FORWARD_DECLARATIONS': self.GetForwardDeclarationsString(), |
'CONSTANT_FIELDS': self.GetConstantFieldsString(), |
'METHOD_STUBS': self.GetMethodStubsString(), |
'OPEN_NAMESPACE': self.GetOpenNamespaceString(), |
@@ -816,15 +814,6 @@ jmethodID g_${JAVA_CLASS}_${METHOD_ID_VAR_NAME} = NULL;""") |
ret += [template.substitute(values)] |
return '\n'.join(ret) |
- def GetForwardDeclarationsString(self): |
- ret = [] |
- for native in self.natives: |
- if native.type != 'method': |
- ret += [self.GetForwardDeclaration(native)] |
- if self.options.native_exports and ret: |
- return '\nextern "C" {\n' + "\n".join(ret) + '\n}; // extern "C"' |
- return '\n'.join(ret) |
- |
def GetConstantFieldsString(self): |
if not self.constant_fields: |
return '' |
@@ -838,15 +827,11 @@ jmethodID g_${JAVA_CLASS}_${METHOD_ID_VAR_NAME} = NULL;""") |
"""Returns the code corresponding to method stubs.""" |
ret = [] |
for native in self.natives: |
- if native.type == 'method': |
- ret += [self.GetNativeMethodStubString(native)] |
+ ret += [self.GetNativeStub(native)] |
if self.options.eager_called_by_natives: |
ret += self.GetEagerCalledByNativeMethodStubs() |
else: |
ret += self.GetLazyCalledByNativeMethodStubs() |
- |
- if self.options.native_exports and ret: |
- return '\nextern "C" {\n' + "\n".join(ret) + '\n}; // extern "C"' |
return '\n'.join(ret) |
def GetLazyCalledByNativeMethodStubs(self): |
@@ -1053,90 +1038,75 @@ Java_${FULLY_QUALIFIED_CLASS}_${INIT_NATIVE_NAME}(JNIEnv* env, jclass clazz) { |
native: the native dictionary describing the method. |
Returns: |
- A string with the stub function name. For native exports mode this is the |
- Java_* symbol name required by the JVM; otherwise it is just the name of |
- the native method itself. |
+ A string with the stub function name (used by the JVM). |
""" |
- if self.options.native_exports: |
- template = Template("Java_${JAVA_NAME}_native${NAME}") |
+ 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 |
+ 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 |
+ values = {'NAME': native.name, |
+ 'JAVA_NAME': java_name} |
+ return template.substitute(values) |
- def GetForwardDeclaration(self, native): |
- template_str = """ |
-static ${RETURN} ${NAME}(JNIEnv* env, ${PARAMS}); |
-""" |
- if self.options.native_exports: |
- template_str += """ |
-__attribute__((visibility("default"))) |
-${RETURN} ${STUB_NAME}(JNIEnv* env, ${PARAMS}) { |
- return ${NAME}(${PARAMS_IN_CALL}); |
-} |
-""" |
- template = Template(template_str) |
+ def GetNativeStub(self, native): |
+ is_method = native.type == 'method' |
+ |
+ if is_method: |
+ params = native.params[1:] |
+ else: |
+ params = native.params |
params_in_call = [] |
if not self.options.pure_native_methods: |
params_in_call = ['env', 'jcaller'] |
- params_in_call = ', '.join(params_in_call + [p.name for p in native.params]) |
+ params_in_call = ', '.join(params_in_call + [p.name for p in params]) |
- values = {'RETURN': JavaDataTypeToC(native.return_type), |
- 'NAME': native.name, |
- 'PARAMS': self.GetParamsInDeclaration(native), |
- 'PARAMS_IN_CALL': params_in_call, |
- 'STUB_NAME': self.GetStubName(native)} |
- return template.substitute(values) |
- |
- def GetNativeMethodStubString(self, native): |
- """Returns stubs for native methods.""" |
if self.options.native_exports: |
- template_str = """\ |
-__attribute__((visibility("default"))) |
-${RETURN} ${STUB_NAME}(JNIEnv* env, |
- ${PARAMS_IN_DECLARATION}) {""" |
+ stub_visibility = 'extern "C" __attribute__((visibility("default")))\n' |
else: |
- template_str = """\ |
-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}); |
- return native->${NAME}(${PARAMS_IN_CALL})${POST_CALL}; |
-} |
-""" |
- |
- template = Template(template_str) |
- params = [] |
- if not self.options.pure_native_methods: |
- params = ['env', 'jcaller'] |
- params_in_call = ', '.join(params + [p.name for p in native.params[1:]]) |
- |
+ stub_visibility = 'static ' |
return_type = JavaDataTypeToC(native.return_type) |
- 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 = { |
'RETURN': return_type, |
- 'OPTIONAL_ERROR_RETURN': optional_error_return, |
'NAME': native.name, |
- 'PARAMS_IN_DECLARATION': self.GetParamsInDeclaration(native), |
- 'PARAM0_NAME': native.params[0].name, |
- 'P0_TYPE': native.p0_type, |
+ 'PARAMS': self.GetParamsInDeclaration(native), |
'PARAMS_IN_CALL': params_in_call, |
- 'POST_CALL': post_call, |
'STUB_NAME': self.GetStubName(native), |
+ 'STUB_VISIBILITY': stub_visibility, |
} |
+ |
+ if is_method: |
+ 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, |
+ ${PARAMS}) { |
+ ${P0_TYPE}* native = reinterpret_cast<${P0_TYPE}*>(${PARAM0_NAME}); |
+ CHECK_NATIVE_PTR(env, jcaller, native, "${NAME}"${OPTIONAL_ERROR_RETURN}); |
+ return native->${NAME}(${PARAMS_IN_CALL})${POST_CALL}; |
+} |
+""") |
+ else: |
+ template = Template(""" |
+static ${RETURN} ${NAME}(JNIEnv* env, ${PARAMS}); |
+ |
+${STUB_VISIBILITY}${RETURN} ${STUB_NAME}(JNIEnv* env, ${PARAMS}) { |
+ return ${NAME}(${PARAMS_IN_CALL}); |
+} |
+""") |
+ |
return template.substitute(values) |
def GetArgument(self, param): |