uniffi-rs
uniffi-rs copied to clipboard
Handles
This PR contains the parts of #1808 that I think are most beneficial and least controversial:
- Consolidate the handle code. Use one
FfiTypevariant for all handles. Implement one system in Rust and one system in each foreign language rather than multiple systems. This makes it easier to add new object/handle types. - Handles should be clonable. This is needed to fix #1797.
- Rust and foreign handles should be distinguishable. This will make the trait interface implementation more efficient.
This PR sets things up to fix #1797, but doesn't actually fix it. That's going to take some more code and I want to do that in a separate PR.
It also doesn't implement the trait interface changes, because when I did that I hit #1797. In the traits example, we pass a trait interface into Rust, then Rust immediately returns it. This is what happens Rust returns it:
- It copies the handle in
lower() - It drops the struct, invoking the
IDX_CALLBACK_FREEmethod. - It then returns the handle back to the foreign language, which is use-after-free.