uniffi-rs icon indicating copy to clipboard operation
uniffi-rs copied to clipboard

Use `u64` for interface handles

Open bendk opened this issue 5 months ago • 0 comments
trafficstars

Right now, interface and trait interface handles use raw pointers as their FFI type (*mut ::std::ffi::c_void). This makes sense since they're implemented using Arc::into_raw. This doesn't work great for trait interfaces that have with_foreign support. For those interfaces, we also allow them to be implemented on the foreign side, in which case they are passed across the FFI like a callback interface.

This presents an issue, since callback interfaces normally use u64 for their FFI type. We can make things work by casting the u64 to a pointer, but this isn't ideal:

  • It's often awkward to use 2 different FFI types
  • It's one of the reasons we have #2567
  • There's some possibility of overflow on 32-bit systems.

We should use a single FFI type for this and it seems better to use u64 in all cases than a pointer.

bendk avatar Jun 09 '25 20:06 bendk