0
0
mirror of https://github.com/signalapp/libsignal.git synced 2024-09-20 03:52:17 +02:00

bridge: Distinguish Throwing and non-throwing JNI bridge_fns

This commit does not actually do anything with that information; that
will come next commit.
This commit is contained in:
Jordan Rose 2024-02-06 16:54:46 -08:00
parent e115f69cd0
commit 071adfc689
3 changed files with 24 additions and 12 deletions

View File

@ -43,7 +43,8 @@ ignore_this_warning = re.compile(
r"WARN: Missing `\[defines\]` entry for `ios_device_as_detected_in_build_rs` in cbindgen config\.|"
r"WARN: Skip libsignal-bridge::.+ - \(not `(?:pub|no_mangle)`\)\.|"
r"WARN: Couldn't find path for Array\(Path\(GenericPath \{ .+ \}\), Name\(\"LEN\"\)\), skipping associated constants|"
r"WARN: Cannot find a mangling for generic path GenericPath { path: Path { name: \"JavaCompletableFuture\" }.+"
r"WARN: Cannot find a mangling for generic path GenericPath { path: Path { name: \"JavaCompletableFuture\" }.+|"
r"WARN: Cannot find a mangling for generic path GenericPath { path: Path { name: \"Throwing\" }.+"
")")
unknown_warning = False
@ -103,16 +104,23 @@ def translate_to_java(typ):
}
if typ in type_map:
return type_map[typ]
return (type_map[typ], False)
if typ == 'Throwing':
return ('void', True)
if (stripped := typ.removeprefix('Throwing<')) != typ:
assert stripped.endswith('>')
return (translate_to_java(stripped.removesuffix('>'))[0], True)
if (stripped := typ.removeprefix('JavaCompletableFuture<')) != typ:
assert stripped.endswith('>')
inner = translate_to_java(stripped.removesuffix('>'))
return f'CompletableFuture<{box_primitive_if_needed(inner)}>'
inner = translate_to_java(stripped.removesuffix('>'))[0]
return (f'CompletableFuture<{box_primitive_if_needed(inner)}>', False)
# Assume anything else prefixed with "Java" refers to an object
if typ.startswith('Java'):
return typ[4:]
return (typ[4:], False)
raise Exception("Don't know what to do with a", typ)
@ -136,13 +144,13 @@ for line in stdout.split('\n'):
cur_type = this_type
java_fn_name = method_name.replace('_1', '_')
java_ret_type = translate_to_java(ret_type)
(java_ret_type, is_throwing) = translate_to_java(ret_type)
java_args = []
if args is not None:
for arg in args.split(', ')[1:]:
(arg_type, arg_name) = arg.split(' ')
java_arg_type = translate_to_java(arg_type)
(java_arg_type, _is_throwing) = translate_to_java(arg_type)
java_args.append('%s %s' % (java_arg_type, arg_name))
decls.append(" public static native %s %s(%s);" % (java_ret_type, java_fn_name, ", ".join(java_args)))

View File

@ -1164,19 +1164,19 @@ macro_rules! jni_result_type {
// Therefore, if you need to return a more complicated Result or Option
// type, you'll have to add another rule for its form.
(Result<$typ:tt $(, $_:ty)?>) => {
jni_result_type!($typ)
jni::Throwing<jni_result_type!($typ)>
};
(Result<&$typ:tt $(, $_:ty)?>) => {
jni_result_type!(&$typ)
jni::Throwing<jni_result_type!(&$typ)>
};
(Result<Option<&$typ:tt> $(, $_:ty)?>) => {
jni_result_type!(&$typ)
jni::Throwing<jni_result_type!(&$typ)>
};
(Result<Option<$typ:tt<$($args:tt),+> > $(, $_:ty)?>) => {
jni_result_type!($typ<$($args),+>)
jni::Throwing<jni_result_type!($typ<$($args),+>)>
};
(Result<$typ:tt<$($args:tt),+> $(, $_:ty)?>) => {
jni_result_type!($typ<$($args),+>)
jni::Throwing<jni_result_type!($typ<$($args),+>)>
};
(Option<$typ:tt>) => {
jni_result_type!($typ)

View File

@ -54,6 +54,10 @@ pub type JavaUUID<'a> = JObject<'a>;
pub type JavaCiphertextMessage<'a> = JObject<'a>;
pub type JavaMap<'a> = JObject<'a>;
/// Return type marker for `bridge_fn`s that return Result, which gen_java_decl.py will pick out
/// when generating Native.java.
pub type Throwing<T> = T;
/// A Java wrapper for a `CompletableFuture` type.
#[derive(Default)]
#[repr(transparent)] // Ensures that the representation is the same as JObject.