Skip to content

Commit 8919ed8

Browse files
committed
callback fix
1 parent f061ce1 commit 8919ed8

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

prebindgen-ext/src/jni/jni_ext.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,13 +1048,6 @@ fn callback_input(
10481048
registry: &Registry,
10491049
) -> Option<(syn::Type, syn::Expr)> {
10501050
let stem = derive_callback_stem(args);
1051-
let kotlin_class = format!("JNI{}Callback", stem);
1052-
let kotlin_fqn = if ext.kotlin_callback_package.is_empty() {
1053-
kotlin_class.clone()
1054-
} else {
1055-
format!("{}.{}", ext.kotlin_callback_package, kotlin_class)
1056-
};
1057-
let internal_class = kotlin_fqn.replace('.', "/");
10581051

10591052
// Per-arg: encode call + JNI signature chunk.
10601053
let mut arg_idents: Vec<syn::Ident> = Vec::new();
@@ -1091,7 +1084,17 @@ fn callback_input(
10911084
jvalue_exprs.push(quote!(jni::objects::JValue::Object(&#obj_ident)));
10921085
}
10931086
None if is_jobject_wire(&arg_wire) => {
1094-
sig.push_str(&format!("L{};", internal_class));
1087+
// The callback's `run` method takes the Kotlin equivalent
1088+
// of this Rust arg type, not the callback interface itself.
1089+
// Look up the registered FQN and slash-encode it for the
1090+
// JVM method descriptor.
1091+
let arg_key = TypeKey::from_type(arg_ty).as_str().to_string();
1092+
let arg_fqn = ext.kotlin_type_fqns
1093+
.iter()
1094+
.find(|(k, _)| k == &arg_key)
1095+
.map(|(_, v)| v.replace('.', "/"))
1096+
.unwrap_or_else(|| "java/lang/Object".to_string());
1097+
sig.push_str(&format!("L{};", arg_fqn));
10951098
arg_preludes.push(quote! {
10961099
let #enc_ident = #conv(&mut env, &__cb_args.#i)?;
10971100
let #obj_ident: jni::objects::JObject = #enc_ident;

0 commit comments

Comments
 (0)