Skip to content

Commit 731ba33

Browse files
committed
Python: Fix async functions that return external types (#2659)
The issue was that we were using the same name for both the local and external types, which lead to the one of them being lost when they were de-duped.
1 parent 159006b commit 731ba33

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

uniffi_bindgen/src/bindings/python/pipeline/external_types.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ pub fn pass(namespace: &mut Namespace) -> Result<()> {
5959
_ => (),
6060
};
6161
});
62+
// Transform RustBuffer namespaces to concrete Python module names
63+
namespace.visit_mut(|ffi_type: &mut FfiType| {
64+
if let FfiType::RustBuffer(Some(ref mut namespace)) = ffi_type {
65+
match namespace_config.external_packages.get(namespace) {
66+
Some(package_name) if !package_name.is_empty() => {
67+
*namespace = package_name.clone();
68+
}
69+
_ => (),
70+
}
71+
}
72+
});
73+
6274
namespace.imports.extend(module_imports);
6375
Ok(())
6476
}

uniffi_bindgen/src/pipeline/general/ffi_async_data.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ fn generate_async_data(crate_name: &str, ffi_return_type: Option<&FfiTypeNode>)
4242
None => "void",
4343
ty => panic!("Invalid future return type: {ty:?}"),
4444
};
45+
let struct_crate_name = match &ffi_return_type.map(|ffi_type| &ffi_type.ty) {
46+
Some(FfiType::RustBuffer(Some(rust_buffer_crate))) => rust_buffer_crate,
47+
_ => "",
48+
};
49+
4550
AsyncData {
4651
ffi_rust_future_poll: RustFfiFunctionName(format!(
4752
"ffi_{crate_name}_rust_future_poll_{return_type_name}"
@@ -56,11 +61,11 @@ fn generate_async_data(crate_name: &str, ffi_return_type: Option<&FfiTypeNode>)
5661
"ffi_{crate_name}_rust_future_free_{return_type_name}"
5762
)),
5863
ffi_foreign_future_result: FfiStructName(format!(
59-
"ForeignFutureResult{}",
64+
"ForeignFutureResult{struct_crate_name}{}",
6065
return_type_name.to_upper_camel_case()
6166
)),
6267
ffi_foreign_future_complete: FfiFunctionTypeName(format!(
63-
"ForeignFutureComplete{return_type_name}"
68+
"ForeignFutureComplete{struct_crate_name}{return_type_name}"
6469
)),
6570
}
6671
}

0 commit comments

Comments
 (0)