Commit a0040e3d authored by Eric Stevenson's avatar Eric Stevenson Committed by Commit Bot

jni_generator: Fix proxy native handling of arrays.

While the JNIProcessor was already handling arrays correctly, the
jni_generator was generating incorrect native method signatures for
return types and parameters that used 2D arrays.

The script now handles multi-dimensional arrays.

Bug: 1000820
Change-Id: I6b6110e2bb07328a0618ae605b055d81c4d5a2aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1788481
Commit-Queue: Eric Stevenson <estevenson@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#694124}
parent 21062e40
...@@ -197,19 +197,16 @@ def JavaDataTypeToC(java_type): ...@@ -197,19 +197,16 @@ def JavaDataTypeToC(java_type):
return 'jobject' return 'jobject'
def JavaTypeToProxyCast(type): def JavaTypeToProxyCast(java_type):
"""Maps from a java type to the type used by the native proxy GEN_JNI class""" """Maps from a java type to the type used by the native proxy GEN_JNI class"""
if type in JAVA_POD_TYPE_MAP or type in JAVA_TYPE_MAP: # All the types and array types of JAVA_TYPE_MAP become jobjectArray across
return type # jni but they still need to be passed as the original type on the java side.
# All the array types of JAVA_TYPE_MAP become jobjectArray across jni but raw_type = java_type.rstrip('[]')
# they still need to be passed as the original type on the java side. if raw_type in JAVA_POD_TYPE_MAP or raw_type in JAVA_TYPE_MAP:
if type[:-2] in JAVA_POD_TYPE_MAP or type[:-2] in JAVA_TYPE_MAP: return java_type
return type
# All other types should just be passed as Objects or Object arrays.
# Otherwise we have a jobject type that should be an object. return 'Object' + java_type[len(raw_type):]
if type[-2:] == '[]':
return 'Object[]'
return 'Object'
def WrapCTypeForDeclaration(c_type): def WrapCTypeForDeclaration(c_type):
......
...@@ -25,6 +25,7 @@ from jni_generator import CalledByNative ...@@ -25,6 +25,7 @@ from jni_generator import CalledByNative
from jni_generator import IsMainDexJavaClass from jni_generator import IsMainDexJavaClass
from jni_generator import NativeMethod from jni_generator import NativeMethod
from jni_generator import Param from jni_generator import Param
from jni_generator import ProxyHelpers
_SCRIPT_NAME = 'base/android/jni_generator/jni_generator.py' _SCRIPT_NAME = 'base/android/jni_generator/jni_generator.py'
_INCLUDES = ('base/android/jni_generator/jni_generator_helper.h') _INCLUDES = ('base/android/jni_generator/jni_generator_helper.h')
...@@ -1556,6 +1557,70 @@ class ProxyTestGenerator(BaseTest): ...@@ -1556,6 +1557,70 @@ class ProxyTestGenerator(BaseTest):
reg_dict, proxy_options) reg_dict, proxy_options)
self.AssertGoldenTextEquals(content, 'MocksRequired') self.AssertGoldenTextEquals(content, 'MocksRequired')
def testProxyTypeInfoPreserved(self):
test_data = """
package org.chromium.foo;
class Foo {
@NativeMethods
interface Natives {
char[][] fooProxy(byte[][] b);
SomeJavaType[][] barProxy(String[][] s, short z);
String[] foobarProxy(String[] a, int[][] b);
byte[][] bazProxy(long nativePtr, BazClass caller,
SomeJavaType[][] someObjects);
}
"""
natives = ProxyHelpers.ExtractStaticProxyNatives('org/chromium/foo/FooJni',
test_data, 'long')
golden_natives = [
NativeMethod(
static=True,
java_class_name=None,
return_type='char[][]',
name='fooProxy',
params=[Param(datatype='byte[][]', name='b')],
is_proxy=True,
proxy_name='org_chromium_foo_FooJni_fooProxy'),
NativeMethod(
static=True,
java_class_name=None,
return_type='Object[][]',
name='barProxy',
params=[
Param(datatype='String[][]', name='s'),
Param(datatype='short', name='z')
],
is_proxy=True,
proxy_name='org_chromium_foo_FooJni_barProxy'),
NativeMethod(
static=True,
java_class_name=None,
return_type='String[]',
name='foobarProxy',
params=[
Param(datatype='String[]', name='a'),
Param(datatype='int[][]', name='b')
],
is_proxy=True,
proxy_name='org_chromium_foo_FooJni_foobarProxy'),
NativeMethod(
static=True,
java_class_name=None,
return_type='byte[][]',
name='bazProxy',
params=[
Param(datatype='long', name='nativePtr'),
Param(datatype='Object', name='caller'),
Param(datatype='Object[][]', name='someObjects')
],
is_proxy=True,
proxy_name='org_chromium_foo_FooJni_bazProxy',
ptr_type='long')
]
self.AssertListEquals(golden_natives, natives)
def TouchStamp(stamp_path): def TouchStamp(stamp_path):
dir_name = os.path.dirname(stamp_path) dir_name = os.path.dirname(stamp_path)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment