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

Side by Side Diff: base/android/jni_generator/jni_generator.py

Issue 2154293002: jni_generator: handle inner class natives properly. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Extracts native methods from a Java file and generates the JNI bindings. 6 """Extracts native methods from a Java file and generates the JNI bindings.
7 If you change this, please run and update the tests.""" 7 If you change this, please run and update the tests."""
8 8
9 import collections 9 import collections
10 import errno 10 import errno
(...skipping 1137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 ret[class_name] = jni_class_path 1148 ret[class_name] = jni_class_path
1149 return ret 1149 return ret
1150 1150
1151 def GetClassPathDefinitions(self): 1151 def GetClassPathDefinitions(self):
1152 """Returns the ClassPath constants.""" 1152 """Returns the ClassPath constants."""
1153 ret = [] 1153 ret = []
1154 template = Template("""\ 1154 template = Template("""\
1155 const char k${JAVA_CLASS}ClassPath[] = "${JNI_CLASS_PATH}";""") 1155 const char k${JAVA_CLASS}ClassPath[] = "${JNI_CLASS_PATH}";""")
1156 native_classes = self.GetUniqueClasses(self.natives) 1156 native_classes = self.GetUniqueClasses(self.natives)
1157 called_by_native_classes = self.GetUniqueClasses(self.called_by_natives) 1157 called_by_native_classes = self.GetUniqueClasses(self.called_by_natives)
1158 if self.options.native_exports: 1158 if self.options.native_exports and not self.options.native_exports_optional:
1159 all_classes = called_by_native_classes 1159 all_classes = called_by_native_classes
1160 else: 1160 else:
1161 all_classes = native_classes 1161 all_classes = native_classes
1162 all_classes.update(called_by_native_classes) 1162 all_classes.update(called_by_native_classes)
1163 1163
1164 for clazz in all_classes: 1164 for clazz in all_classes:
1165 values = { 1165 values = {
1166 'JAVA_CLASS': clazz, 1166 'JAVA_CLASS': clazz,
1167 'JNI_CLASS_PATH': all_classes[clazz], 1167 'JNI_CLASS_PATH': all_classes[clazz],
1168 } 1168 }
1169 ret += [template.substitute(values)] 1169 ret += [template.substitute(values)]
1170 ret += '' 1170 ret += ''
1171 1171
1172 class_getter_methods = []
1173 if self.options.native_exports: 1172 if self.options.native_exports:
1174 template = Template("""\ 1173 template = Template("""\
1175 // Leaking this jclass as we cannot use LazyInstance from some threads. 1174 // Leaking this jclass as we cannot use LazyInstance from some threads.
1176 base::subtle::AtomicWord g_${JAVA_CLASS}_clazz __attribute__((unused)) = 0; 1175 base::subtle::AtomicWord g_${JAVA_CLASS}_clazz __attribute__((unused)) = 0;
1177 #define ${JAVA_CLASS}_clazz(env) \ 1176 #define ${JAVA_CLASS}_clazz(env) \
1178 base::android::LazyGetClass(env, k${JAVA_CLASS}ClassPath, \ 1177 base::android::LazyGetClass(env, k${JAVA_CLASS}ClassPath, \
1179 &g_${JAVA_CLASS}_clazz)""") 1178 &g_${JAVA_CLASS}_clazz)""")
1180 else: 1179 else:
1181 template = Template("""\ 1180 template = Template("""\
1182 // Leaking this jclass as we cannot use LazyInstance from some threads. 1181 // Leaking this jclass as we cannot use LazyInstance from some threads.
1183 jclass g_${JAVA_CLASS}_clazz = NULL; 1182 jclass g_${JAVA_CLASS}_clazz = NULL;
1184 #define ${JAVA_CLASS}_clazz(env) g_${JAVA_CLASS}_clazz""") 1183 #define ${JAVA_CLASS}_clazz(env) g_${JAVA_CLASS}_clazz""")
1185 1184
1186 for clazz in called_by_native_classes: 1185 for clazz in all_classes:
1187 values = { 1186 values = {
1188 'JAVA_CLASS': clazz, 1187 'JAVA_CLASS': clazz,
1189 } 1188 }
1190 ret += [template.substitute(values)] 1189 ret += [template.substitute(values)]
1191 1190
1192 return '\n'.join(ret) 1191 return '\n'.join(ret)
1193 1192
1194 def GetFindClasses(self): 1193 def GetFindClasses(self):
1195 """Returns the imlementation of FindClass for all known classes.""" 1194 """Returns the imlementation of FindClass for all known classes."""
1196 if self.options.native_exports: 1195 if self.options.native_exports:
1197 return '\n' 1196 return '\n'
1198 template = Template("""\ 1197 template = Template("""\
1199 g_${JAVA_CLASS}_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( 1198 g_${JAVA_CLASS}_clazz = reinterpret_cast<jclass>(env->NewGlobalRef(
1200 base::android::GetClass(env, k${JAVA_CLASS}ClassPath).obj()));""") 1199 base::android::GetClass(env, k${JAVA_CLASS}ClassPath).obj()));""")
1201 ret = [] 1200 ret = []
1202 for clazz in self.GetUniqueClasses(self.called_by_natives): 1201 all_classes = self.GetUniqueClasses(self.natives)
1202 all_classes.update(self.GetUniqueClasses(self.called_by_natives))
1203 for clazz in all_classes:
1203 values = {'JAVA_CLASS': clazz} 1204 values = {'JAVA_CLASS': clazz}
1204 ret += [template.substitute(values)] 1205 ret += [template.substitute(values)]
1205 return '\n'.join(ret) 1206 return '\n'.join(ret)
1206 1207
1207 def GetMethodIDImpl(self, called_by_native): 1208 def GetMethodIDImpl(self, called_by_native):
1208 """Returns the implementation of GetMethodID.""" 1209 """Returns the implementation of GetMethodID."""
1209 template = Template("""\ 1210 template = Template("""\
1210 base::android::MethodID::LazyGet< 1211 base::android::MethodID::LazyGet<
1211 base::android::MethodID::TYPE_${STATIC}>( 1212 base::android::MethodID::TYPE_${STATIC}>(
1212 env, ${JAVA_CLASS}_clazz(env), 1213 env, ${JAVA_CLASS}_clazz(env),
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 GenerateJNIHeader(input_file, output_file, options) 1392 GenerateJNIHeader(input_file, output_file, options)
1392 1393
1393 if options.depfile: 1394 if options.depfile:
1394 build_utils.WriteDepfile( 1395 build_utils.WriteDepfile(
1395 options.depfile, 1396 options.depfile,
1396 build_utils.GetPythonDependencies()) 1397 build_utils.GetPythonDependencies())
1397 1398
1398 1399
1399 if __name__ == '__main__': 1400 if __name__ == '__main__':
1400 sys.exit(main(sys.argv)) 1401 sys.exit(main(sys.argv))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698