Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(719)

Unified Diff: base/android/jni_generator/jni_generator.py

Issue 1279163006: jni_generator: Wrap all native methods in stubs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..463cad21563b6598f796b50091f3ff7f7f4aefa5 100755
--- a/base/android/jni_generator/jni_generator.py
+++ b/base/android/jni_generator/jni_generator.py
@@ -821,8 +821,6 @@ jmethodID g_${JAVA_CLASS}_${METHOD_ID_VAR_NAME} = NULL;""")
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):
@@ -844,9 +842,6 @@ jmethodID g_${JAVA_CLASS}_${METHOD_ID_VAR_NAME} = NULL;""")
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,32 +1048,24 @@ 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}) {
+
+${STUB_VISIBILITY}${RETURN} ${STUB_NAME}(JNIEnv* env, ${PARAMS}) {
return ${NAME}(${PARAMS_IN_CALL});
}
"""
@@ -1087,31 +1074,29 @@ ${RETURN} ${STUB_NAME}(JNIEnv* env, ${PARAMS}) {
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])
+ if self.options.native_exports:
+ stub_visibility = 'extern "C" __attribute__((visibility("default")))\n'
+ else:
+ stub_visibility = 'static '
values = {'RETURN': JavaDataTypeToC(native.return_type),
'NAME': native.name,
'PARAMS': self.GetParamsInDeclaration(native),
'PARAMS_IN_CALL': params_in_call,
- 'STUB_NAME': self.GetStubName(native)}
+ 'STUB_NAME': self.GetStubName(native),
+ 'STUB_VISIBILITY': stub_visibility}
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}) {"""
- else:
- template_str = """\
-static ${RETURN} ${STUB_NAME}(JNIEnv* env, ${PARAMS_IN_DECLARATION}) {"""
- template_str += """
+ template_str = """\
+${STUB_VISIBILITY}${RETURN} ${STUB_NAME}(JNIEnv* env,
+ ${PARAMS_IN_DECLARATION}) {
${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:
@@ -1125,6 +1110,10 @@ static ${RETURN} ${STUB_NAME}(JNIEnv* env, ${PARAMS_IN_DECLARATION}) {"""
post_call = ''
if re.match(RE_SCOPED_JNI_RETURN_TYPES, return_type):
post_call = '.Release()'
+ if self.options.native_exports:
+ stub_visibility = 'extern "C" __attribute__((visibility("default")))\n'
+ else:
+ stub_visibility = 'static '
rmcilroy 2015/08/12 10:35:35 nit - pull this out to a helper function to avoid
Torne 2015/08/12 10:37:56 Actually, I could probably just merge these two fu
values = {
'RETURN': return_type,
@@ -1136,6 +1125,7 @@ static ${RETURN} ${STUB_NAME}(JNIEnv* env, ${PARAMS_IN_DECLARATION}) {"""
'PARAMS_IN_CALL': params_in_call,
'POST_CALL': post_call,
'STUB_NAME': self.GetStubName(native),
+ 'STUB_VISIBILITY': stub_visibility,
}
return template.substitute(values)

Powered by Google App Engine
This is Rietveld 408576698