Chromium Code Reviews| 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 de865d527be81e9afda60a5d866e9b3aa81f4f8e..b2d8013b12bc5fe242fa577bf4d71fabba4097e5 100755 |
| --- a/base/android/jni_generator/jni_generator.py |
| +++ b/base/android/jni_generator/jni_generator.py |
| @@ -599,10 +599,12 @@ $CLASS_PATH_DEFINITIONS |
| } // namespace |
| $OPEN_NAMESPACE |
| +extern "C"{ |
| $FORWARD_DECLARATIONS |
| // Step 2: method stubs. |
| $METHOD_STUBS |
| +}; |
| // Step 3: RegisterNatives. |
| @@ -660,6 +662,8 @@ $CLOSE_NAMESPACE |
| def GetRegisterNativesImplString(self): |
| """Returns the implementation for RegisterNatives.""" |
| + if not self.called_by_natives: |
| + return '' |
| template = Template("""\ |
| static const JNINativeMethod kMethods${JAVA_CLASS}[] = { |
| ${KMETHODS} |
| @@ -681,7 +685,7 @@ ${KMETHODS} |
| if kmethods: |
| values = {'JAVA_CLASS': clazz, |
| 'KMETHODS': kmethods} |
| - ret += [template.substitute(values)] |
| + # ret += [template.substitute(values)] |
| if not ret: return '' |
| return '\n' + '\n'.join(ret) |
| @@ -733,9 +737,17 @@ ${KMETHODS} |
| def GetForwardDeclaration(self, native): |
| template = Template(""" |
| static ${RETURN} ${NAME}(JNIEnv* env, ${PARAMS}); |
| +__attribute__((visibility("default"))) ${RETURN} |
| + Java_${JAVA_NAME}_native${NAME}(JNIEnv* env, ${PARAMS}) |
| + __attribute__((alias("${NAME}"))); |
|
bulach
2013/06/28 00:45:54
I think you can combine the attributes:
__attribut
|
| """) |
| + java_name = JniParams.RemapClassName(self.fully_qualified_class).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)} |
| return template.substitute(values) |
| @@ -747,6 +759,8 @@ static ${RETURN} ${NAME}(JNIEnv* env, ${PARAMS_IN_DECLARATION}) { |
| ${P0_TYPE}* native = reinterpret_cast<${P0_TYPE}*>(${PARAM0_NAME}); |
| return native->${NAME}(env, obj${PARAMS_IN_CALL})${POST_CALL}; |
| } |
| +__attribute__((visibility("default"))) ${RETURN} Java_${JAVA_NAME}_native${NAME}(JNIEnv* env, |
| + ${PARAMS_IN_DECLARATION}) __attribute__((alias("${NAME}"))); |
| """) |
| params_for_call = ', '.join(p.name for p in native.params[1:]) |
| if params_for_call: |
| @@ -759,9 +773,14 @@ static ${RETURN} ${NAME}(JNIEnv* env, ${PARAMS_IN_DECLARATION}) { |
| else: |
| scoped_return_type = return_type |
| post_call = '' |
| + java_name = JniParams.RemapClassName(self.fully_qualified_class).replace('_', '_1').replace('/', '_') |
| + if native.java_class_name: |
| + java_name += "_00024" + native.java_class_name |
| + |
| values = { |
| 'RETURN': return_type, |
| 'SCOPED_RETURN': scoped_return_type, |
| + 'JAVA_NAME': java_name, |
| 'NAME': native.name, |
| 'PARAMS_IN_DECLARATION': self.GetParamsInDeclaration(native), |
| 'PARAM0_NAME': native.params[0].name, |
| @@ -879,12 +898,11 @@ ${FUNCTION_HEADER} |
| def GetClassPathDefinitions(self): |
| """Returns the ClassPath constants.""" |
| ret = [] |
| + if not self.called_by_natives: |
| + return '' |
| template = Template("""\ |
| const char k${JAVA_CLASS}ClassPath[] = "${JNI_CLASS_PATH}";""") |
| - native_classes = self.GetUniqueClasses(self.natives) |
| - called_by_native_classes = self.GetUniqueClasses(self.called_by_natives) |
| - all_classes = native_classes |
| - all_classes.update(called_by_native_classes) |
| + all_classes = self.GetUniqueClasses(self.called_by_natives) |
| for clazz in all_classes: |
| values = { |
| 'JAVA_CLASS': clazz, |
| @@ -892,7 +910,7 @@ const char k${JAVA_CLASS}ClassPath[] = "${JNI_CLASS_PATH}";""") |
| } |
| ret += [template.substitute(values)] |
| ret += '' |
| - for clazz in called_by_native_classes: |
| + for clazz in all_classes: |
| template = Template("""\ |
| // Leaking this jclass as we cannot use LazyInstance from some threads. |
| jclass g_${JAVA_CLASS}_clazz = NULL;""") |