Skip to content

Commit

Permalink
Fixing the Kotlin async function signatures
Browse files Browse the repository at this point in the history
PollResult is an `i8` in Rust, but was incorrectly specified as a
`Short` in Kotlin.  Things seem to be working accidentally, but this
should be fixed.
  • Loading branch information
bendk committed Dec 12, 2023
1 parent 473689f commit 4f4c989
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions uniffi_bindgen/src/bindings/kotlin/templates/Async.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Async return type handlers

internal const val UNIFFI_RUST_FUTURE_POLL_READY = 0.toShort()
internal const val UNIFFI_RUST_FUTURE_POLL_MAYBE_READY = 1.toShort()
internal const val UNIFFI_RUST_FUTURE_POLL_READY = 0.toByte()
internal const val UNIFFI_RUST_FUTURE_POLL_MAYBE_READY = 1.toByte()

internal val uniffiContinuationHandleMap = UniFfiHandleMap<CancellableContinuation<Short>>()
internal val uniffiContinuationHandleMap = UniFfiHandleMap<CancellableContinuation<Byte>>()

// FFI type for Rust future continuations
internal object uniffiRustFutureContinuationCallback: UniFffiRustFutureContinuationCallbackType {
override fun callback(continuationHandle: USize, pollResult: Short) {
override fun callback(continuationHandle: USize, pollResult: Byte) {
uniffiContinuationHandleMap.remove(continuationHandle)?.resume(pollResult)
}
}
Expand All @@ -22,7 +22,7 @@ internal suspend fun<T, F, E: Exception> uniffiRustCallAsync(
): T {
try {
do {
val pollResult = suspendCancellableCoroutine<Short> { continuation ->
val pollResult = suspendCancellableCoroutine<Byte> { continuation ->
pollFunc(
rustFuture,
uniffiRustFutureContinuationCallback,
Expand Down
2 changes: 1 addition & 1 deletion uniffi_bindgen/src/bindings/kotlin/templates/Helpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,5 @@ internal class UniFfiHandleMap<T: Any> {

// FFI type for Rust future continuations
internal interface UniFffiRustFutureContinuationCallbackType : com.sun.jna.Callback {
fun callback(continuationHandle: USize, pollResult: Short);
fun callback(continuationHandle: USize, pollResult: Byte);
}

0 comments on commit 4f4c989

Please sign in to comment.